From nobody Tue Aug 29 01:37:01 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RZVQj2h4Hz4s9gZ; Tue, 29 Aug 2023 01:37:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RZVQj28rXz3Kfs; Tue, 29 Aug 2023 01:37:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1693273021; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lr0WzqRtklYFAx7BMImNytrmupzjzCfUQozaXViqn50=; b=LOilol/VxkfHYwKcp2i6ZJX6y1Uo9WPgnRaLQ2Ty3VNohGc3H+4qiHVLvKncI2rpF1ymmD 20E1e2jJnX7+TYg0og4rFf0MQ8Iqop90Qt7RhzpnxbBvpCRt5Uo5NfPQZ8PD85QoBK7wi+ pU9mRV0tNCxfLDrOGB2eDIWr7MVBL+IxovbYp9GAmKo0gDbAVCViix/f1Yf5sioeOTyIJb 984eaX5S88YCvY1Nc60sRBkD6vUtTVHyl1z0ko72fLbQxl7M6echkvIurGcnB0POZ/jdZT lQrWHpDZShlKB41w5NU5Jax+VSi8xNS7m3UCzFttGhUVbrN0rQ4oa+/qT/ZPgg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1693273021; a=rsa-sha256; cv=none; b=AxfcV6pI17l4JItYsAYDTUUxQ1jWiR2R4WTjCn2SKGobC6t1JHE2WNIn4mqzdTab21ncMN 9/hSQno49mgRUr33kCJQXVjfWlucJl1ujmzRdiSjwIGJi74dEkx8rRzU1knX/mdkPFrSjP LUnjx4XqKBgtVhqFMeO7h0VxX8vc/M3U9ij56xN0akc5XAxBsq+kMApiizAzaE5t4ofCQc p9np7NM3KzNSt0uggmXjhatU5dteft9uyzQIO2cmBOK3/hg+ZI70L/MrJE2xyGhDlKV2Eu jLurFmAAGZE86p8uC1Xgr3+FC5v6JbpO91zJhknQ04u43M6o4RuaqmVJjwZvhg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1693273021; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lr0WzqRtklYFAx7BMImNytrmupzjzCfUQozaXViqn50=; b=YNPgoKLKnmroOqDNUaDWReVWyCfqk5qeq0AdhbDrwjUFNsUs7YyXNEjwlw/xi6rMfpBxTD XxGWWSwpHWzSEc9eRTdJ3fJytaiW/jD0u+1YLfHof3cFHVklhN8f72x6rkiiLPA2U9xGiK WAPQJN40/T1t5goNclh+rLmV0uy3Sy3Z1TKoPl1V/hnNII109z7w5sreqXiSuPhnzPfiJ5 HTRuPmSf+KW3p0dDuY7TG6Xvovg6NKVVHCey4N5TQQXcuwc6KVrD+3fihcJsONyKLIblyk 6cf9Ax3lXGWpFyKtbmv16cOW2oHMLCsbeQ3T5keGl8guo4mxHlR40qOoyMRDsQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RZVQj0wk7zXYx; Tue, 29 Aug 2023 01:37:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37T1b1mJ075294; Tue, 29 Aug 2023 01:37:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37T1b17W075291; Tue, 29 Aug 2023 01:37:01 GMT (envelope-from git) Date: Tue, 29 Aug 2023 01:37:01 GMT Message-Id: <202308290137.37T1b17W075291@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 6b635c74fd41 - main - aesni: Push FPU sections down further List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6b635c74fd4135eaae68970bfc5aad9ae905fec7 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=6b635c74fd4135eaae68970bfc5aad9ae905fec7 commit 6b635c74fd4135eaae68970bfc5aad9ae905fec7 Author: Mark Johnston AuthorDate: 2023-08-29 01:26:53 +0000 Commit: Mark Johnston CommitDate: 2023-08-29 01:26:53 +0000 aesni: Push FPU sections down further After commit 937b4473be21 aesni_cipher_crypt() and aesni_cipher_mac() execute in a FPU_KERN_NOCTX section, which means that they must run with preemption disabled. These functions handle discontiguous I/O buffers by allocating a contiguous buffer and copying as necessary, but this allocation cannot happen with preemption disabled. Fix the problem by pushing the FPU section down into aesni_cipher_crypt() and aesni_cipher_mac(). In particular, encrypt-then-auth transforms need not be handled with a single FPU section. Reported by: syzbot+78258dbb02eb92157357@syzkaller.appspotmail.com Discussed with: jhb Fixes: 937b4473be21 ("aesni: Switch to using FPU_KERN_NOCTX.") --- sys/crypto/aesni/aesni.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sys/crypto/aesni/aesni.c b/sys/crypto/aesni/aesni.c index 6d83743dece9..5d5afd8aee41 100644 --- a/sys/crypto/aesni/aesni.c +++ b/sys/crypto/aesni/aesni.c @@ -594,8 +594,6 @@ aesni_cipher_process(struct aesni_session *ses, struct cryptop *crp) break; } - fpu_kern_enter(curthread, NULL, FPU_KERN_NORMAL | FPU_KERN_NOCTX); - /* Do work */ if (csp->csp_mode == CSP_MODE_ETA) { if (CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) { @@ -612,7 +610,6 @@ aesni_cipher_process(struct aesni_session *ses, struct cryptop *crp) else error = aesni_cipher_crypt(ses, crp, csp); - fpu_kern_leave(curthread, NULL); return (error); } @@ -677,6 +674,8 @@ aesni_cipher_crypt(struct aesni_session *ses, struct cryptop *crp, outcopy = allocated; } + fpu_kern_enter(curthread, NULL, FPU_KERN_NORMAL | FPU_KERN_NOCTX); + error = 0; encflag = CRYPTO_OP_IS_ENCRYPT(crp->crp_op); if (crp->crp_cipher_key != NULL) @@ -749,6 +748,9 @@ aesni_cipher_crypt(struct aesni_session *ses, struct cryptop *crp, } break; } + + fpu_kern_leave(curthread, NULL); + if (outcopy && error == 0) crypto_copyback(crp, CRYPTO_HAS_OUTPUT_BUFFER(crp) ? crp->crp_payload_output_start : crp->crp_payload_start, @@ -784,6 +786,8 @@ aesni_cipher_mac(struct aesni_session *ses, struct cryptop *crp, key = csp->csp_auth_key; keylen = csp->csp_auth_klen; + fpu_kern_enter(curthread, NULL, FPU_KERN_NORMAL | FPU_KERN_NOCTX); + if (ses->hmac) { uint8_t hmac_key[SHA1_BLOCK_LEN] __aligned(16); @@ -849,6 +853,8 @@ aesni_cipher_mac(struct aesni_session *ses, struct cryptop *crp, ses->hash_finalize(res, &sctx); } + fpu_kern_leave(curthread, NULL); + if (crp->crp_op & CRYPTO_OP_VERIFY_DIGEST) { uint32_t res2[SHA2_256_HASH_LEN / sizeof(uint32_t)];