Skip to content

Commit ef609c2

Browse files
committed
sunrpc: Fix skcipher/shash conversion
The skcpiher/shash conversion introduced a number of bugs in the sunrpc code: 1) Missing calls to skcipher_request_set_tfm lead to crashes. 2) The allocation size of shash_desc is too small which leads to memory corruption. Fixes: 3b5cf20 ("sunrpc: Use skcipher and ahash/shash") Reported-by: J. Bruce Fields <bfields@fieldses.org> Tested-by: J. Bruce Fields <bfields@fieldses.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 9735a22 commit ef609c2

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

net/sunrpc/auth_gss/gss_krb5_crypto.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ krb5_encrypt(
7878
memcpy(out, in, length);
7979
sg_init_one(sg, out, length);
8080

81+
skcipher_request_set_tfm(req, tfm);
8182
skcipher_request_set_callback(req, 0, NULL, NULL);
8283
skcipher_request_set_crypt(req, sg, sg, length, local_iv);
8384

@@ -115,6 +116,7 @@ krb5_decrypt(
115116
memcpy(out, in, length);
116117
sg_init_one(sg, out, length);
117118

119+
skcipher_request_set_tfm(req, tfm);
118120
skcipher_request_set_callback(req, 0, NULL, NULL);
119121
skcipher_request_set_crypt(req, sg, sg, length, local_iv);
120122

@@ -946,7 +948,8 @@ krb5_rc4_setup_seq_key(struct krb5_ctx *kctx, struct crypto_skcipher *cipher,
946948
return PTR_ERR(hmac);
947949
}
948950

949-
desc = kmalloc(sizeof(*desc), GFP_KERNEL);
951+
desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(hmac),
952+
GFP_KERNEL);
950953
if (!desc) {
951954
dprintk("%s: failed to allocate shash descriptor for '%s'\n",
952955
__func__, kctx->gk5e->cksum_name);
@@ -1012,7 +1015,8 @@ krb5_rc4_setup_enc_key(struct krb5_ctx *kctx, struct crypto_skcipher *cipher,
10121015
return PTR_ERR(hmac);
10131016
}
10141017

1015-
desc = kmalloc(sizeof(*desc), GFP_KERNEL);
1018+
desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(hmac),
1019+
GFP_KERNEL);
10161020
if (!desc) {
10171021
dprintk("%s: failed to allocate shash descriptor for '%s'\n",
10181022
__func__, kctx->gk5e->cksum_name);

net/sunrpc/auth_gss/gss_krb5_mech.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,8 @@ context_derive_keys_rc4(struct krb5_ctx *ctx)
451451
goto out_err_free_hmac;
452452

453453

454-
desc = kmalloc(sizeof(*desc), GFP_KERNEL);
454+
desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(hmac),
455+
GFP_KERNEL);
455456
if (!desc) {
456457
dprintk("%s: failed to allocate hash descriptor for '%s'\n",
457458
__func__, ctx->gk5e->cksum_name);

0 commit comments

Comments
 (0)