Skip to content

Commit 3bfbf5f

Browse files
phx0ferherbertx
authored andcommitted
crypto: krb5enc - fix async decrypt skipping hash verification
krb5enc_dispatch_decrypt() sets req->base.complete as the skcipher callback, which is the caller's own completion handler. When the skcipher completes asynchronously, this signals "done" to the caller without executing krb5enc_dispatch_decrypt_hash(), completely bypassing the integrity verification (hash check). Compare with the encrypt path which correctly uses krb5enc_encrypt_done as an intermediate callback to chain into the hash computation on async completion. Fix by adding krb5enc_decrypt_done as an intermediate callback that chains into krb5enc_dispatch_decrypt_hash() upon async skcipher completion, matching the encrypt path's callback pattern. Also fix EBUSY/EINPROGRESS handling throughout: remove krb5enc_request_complete() which incorrectly swallowed EINPROGRESS notifications that must be passed up to callers waiting on backlogged requests, and add missing EBUSY checks in krb5enc_encrypt_ahash_done for the dispatch_encrypt return value. Fixes: d1775a1 ("crypto: Add 'krb5enc' hash and cipher AEAD algorithm") Signed-off-by: Dudu Lu <phx0fer@gmail.com> Unset MAY_BACKLOG on the async completion path so the user won't see back-to-back EINPROGRESS notifications. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 5aa58c3 commit 3bfbf5f

1 file changed

Lines changed: 31 additions & 21 deletions

File tree

crypto/krb5enc.c

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ struct krb5enc_request_ctx {
3939
char tail[];
4040
};
4141

42-
static void krb5enc_request_complete(struct aead_request *req, int err)
43-
{
44-
if (err != -EINPROGRESS)
45-
aead_request_complete(req, err);
46-
}
47-
4842
/**
4943
* crypto_krb5enc_extractkeys - Extract Ke and Ki keys from the key blob.
5044
* @keys: Where to put the key sizes and pointers
@@ -127,7 +121,7 @@ static void krb5enc_encrypt_done(void *data, int err)
127121
{
128122
struct aead_request *req = data;
129123

130-
krb5enc_request_complete(req, err);
124+
aead_request_complete(req, err);
131125
}
132126

133127
/*
@@ -188,14 +182,16 @@ static void krb5enc_encrypt_ahash_done(void *data, int err)
188182
struct ahash_request *ahreq = (void *)(areq_ctx->tail + ictx->reqoff);
189183

190184
if (err)
191-
return krb5enc_request_complete(req, err);
185+
goto out;
192186

193187
krb5enc_insert_checksum(req, ahreq->result);
194188

195-
err = krb5enc_dispatch_encrypt(req,
196-
aead_request_flags(req) & ~CRYPTO_TFM_REQ_MAY_SLEEP);
197-
if (err != -EINPROGRESS)
198-
aead_request_complete(req, err);
189+
err = krb5enc_dispatch_encrypt(req, 0);
190+
if (err == -EINPROGRESS)
191+
return;
192+
193+
out:
194+
aead_request_complete(req, err);
199195
}
200196

201197
/*
@@ -265,17 +261,16 @@ static void krb5enc_decrypt_hash_done(void *data, int err)
265261
{
266262
struct aead_request *req = data;
267263

268-
if (err)
269-
return krb5enc_request_complete(req, err);
270-
271-
err = krb5enc_verify_hash(req);
272-
krb5enc_request_complete(req, err);
264+
if (!err)
265+
err = krb5enc_verify_hash(req);
266+
aead_request_complete(req, err);
273267
}
274268

275269
/*
276270
* Dispatch the hashing of the plaintext after we've done the decryption.
277271
*/
278-
static int krb5enc_dispatch_decrypt_hash(struct aead_request *req)
272+
static int krb5enc_dispatch_decrypt_hash(struct aead_request *req,
273+
unsigned int flags)
279274
{
280275
struct crypto_aead *krb5enc = crypto_aead_reqtfm(req);
281276
struct aead_instance *inst = aead_alg_instance(krb5enc);
@@ -291,7 +286,7 @@ static int krb5enc_dispatch_decrypt_hash(struct aead_request *req)
291286
ahash_request_set_tfm(ahreq, auth);
292287
ahash_request_set_crypt(ahreq, req->dst, hash,
293288
req->assoclen + req->cryptlen - authsize);
294-
ahash_request_set_callback(ahreq, aead_request_flags(req),
289+
ahash_request_set_callback(ahreq, flags,
295290
krb5enc_decrypt_hash_done, req);
296291

297292
err = crypto_ahash_digest(ahreq);
@@ -301,6 +296,21 @@ static int krb5enc_dispatch_decrypt_hash(struct aead_request *req)
301296
return krb5enc_verify_hash(req);
302297
}
303298

299+
static void krb5enc_decrypt_done(void *data, int err)
300+
{
301+
struct aead_request *req = data;
302+
303+
if (err)
304+
goto out;
305+
306+
err = krb5enc_dispatch_decrypt_hash(req, 0);
307+
if (err == -EINPROGRESS)
308+
return;
309+
310+
out:
311+
aead_request_complete(req, err);
312+
}
313+
304314
/*
305315
* Dispatch the decryption of the ciphertext.
306316
*/
@@ -324,7 +334,7 @@ static int krb5enc_dispatch_decrypt(struct aead_request *req)
324334

325335
skcipher_request_set_tfm(skreq, ctx->enc);
326336
skcipher_request_set_callback(skreq, aead_request_flags(req),
327-
req->base.complete, req->base.data);
337+
krb5enc_decrypt_done, req);
328338
skcipher_request_set_crypt(skreq, src, dst,
329339
req->cryptlen - authsize, req->iv);
330340

@@ -339,7 +349,7 @@ static int krb5enc_decrypt(struct aead_request *req)
339349
if (err < 0)
340350
return err;
341351

342-
return krb5enc_dispatch_decrypt_hash(req);
352+
return krb5enc_dispatch_decrypt_hash(req, aead_request_flags(req));
343353
}
344354

345355
static int krb5enc_init_tfm(struct crypto_aead *tfm)

0 commit comments

Comments
 (0)