Skip to content

Commit

Permalink
aesni: Push FPU sections down further
Browse files Browse the repository at this point in the history
After commit 937b447 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:		937b447 ("aesni: Switch to using FPU_KERN_NOCTX.")
  • Loading branch information
markjdb committed Aug 29, 2023
1 parent aca3bd1 commit 6b635c7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions sys/crypto/aesni/aesni.c
Expand Up @@ -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)) {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)];

Expand Down

0 comments on commit 6b635c7

Please sign in to comment.