Skip to content

Commit 04de758

Browse files
iokilljarkkojs
authored andcommitted
KEYS: trusted: dcp: fix NULL dereference in AEAD crypto operation
When sealing or unsealing a key blob we currently do not wait for the AEAD cipher operation to finish and simply return after submitting the request. If there is some load on the system we can exit before the cipher operation is done and the buffer we read from/write to is already removed from the stack. This will e.g. result in NULL pointer dereference errors in the DCP driver during blob creation. Fix this by waiting for the AEAD cipher operation to finish before resuming the seal and unseal calls. Cc: stable@vger.kernel.org # v6.10+ Fixes: 0e28bf6 ("KEYS: trusted: dcp: fix leak of blob encryption key") Reported-by: Parthiban N <parthiban@linumiz.com> Closes: https://lore.kernel.org/keyrings/254d3bb1-6dbc-48b4-9c08-77df04baee2f@linumiz.com/ Signed-off-by: David Gstir <david@sigma-star.at> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent 4a74da0 commit 04de758

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

security/keys/trusted-keys/trusted_dcp.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ static int do_aead_crypto(u8 *in, u8 *out, size_t len, u8 *key, u8 *nonce,
133133
struct scatterlist src_sg, dst_sg;
134134
struct crypto_aead *aead;
135135
int ret;
136+
DECLARE_CRYPTO_WAIT(wait);
136137

137138
aead = crypto_alloc_aead("gcm(aes)", 0, CRYPTO_ALG_ASYNC);
138139
if (IS_ERR(aead)) {
@@ -163,8 +164,8 @@ static int do_aead_crypto(u8 *in, u8 *out, size_t len, u8 *key, u8 *nonce,
163164
}
164165

165166
aead_request_set_crypt(aead_req, &src_sg, &dst_sg, len, nonce);
166-
aead_request_set_callback(aead_req, CRYPTO_TFM_REQ_MAY_SLEEP, NULL,
167-
NULL);
167+
aead_request_set_callback(aead_req, CRYPTO_TFM_REQ_MAY_SLEEP,
168+
crypto_req_done, &wait);
168169
aead_request_set_ad(aead_req, 0);
169170

170171
if (crypto_aead_setkey(aead, key, AES_KEYSIZE_128)) {
@@ -174,9 +175,9 @@ static int do_aead_crypto(u8 *in, u8 *out, size_t len, u8 *key, u8 *nonce,
174175
}
175176

176177
if (do_encrypt)
177-
ret = crypto_aead_encrypt(aead_req);
178+
ret = crypto_wait_req(crypto_aead_encrypt(aead_req), &wait);
178179
else
179-
ret = crypto_aead_decrypt(aead_req);
180+
ret = crypto_wait_req(crypto_aead_decrypt(aead_req), &wait);
180181

181182
free_req:
182183
aead_request_free(aead_req);

0 commit comments

Comments
 (0)