Skip to content

Commit 561141d

Browse files
committed
SUNRPC: Use a static buffer for the checksum initialization vector
Allocating and zeroing a buffer during every call to krb5_etm_checksum() is inefficient. Instead, set aside a static buffer that is the maximum crypto block size, and use a portion (or all) of that. Reported-by: Markus Elfring <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 3cfcfc1 commit 561141d

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

net/sunrpc/auth_gss/gss_krb5_crypto.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,8 @@ gss_krb5_aes_decrypt(struct krb5_ctx *kctx, u32 offset, u32 len,
921921
* Caller provides the truncation length of the output token (h) in
922922
* cksumout.len.
923923
*
924+
* Note that for RPCSEC, the "initial cipher state" is always all zeroes.
925+
*
924926
* Return values:
925927
* %GSS_S_COMPLETE: Digest computed, @cksumout filled in
926928
* %GSS_S_FAILURE: Call failed
@@ -931,22 +933,19 @@ u32 krb5_etm_checksum(struct crypto_sync_skcipher *cipher,
931933
int body_offset, struct xdr_netobj *cksumout)
932934
{
933935
unsigned int ivsize = crypto_sync_skcipher_ivsize(cipher);
936+
static const u8 iv[GSS_KRB5_MAX_BLOCKSIZE];
934937
struct ahash_request *req;
935938
struct scatterlist sg[1];
936-
u8 *iv, *checksumdata;
937939
int err = -ENOMEM;
940+
u8 *checksumdata;
938941

939942
checksumdata = kmalloc(crypto_ahash_digestsize(tfm), GFP_KERNEL);
940943
if (!checksumdata)
941944
return GSS_S_FAILURE;
942-
/* For RPCSEC, the "initial cipher state" is always all zeroes. */
943-
iv = kzalloc(ivsize, GFP_KERNEL);
944-
if (!iv)
945-
goto out_free_mem;
946945

947946
req = ahash_request_alloc(tfm, GFP_KERNEL);
948947
if (!req)
949-
goto out_free_mem;
948+
goto out_free_cksumdata;
950949
ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP, NULL, NULL);
951950
err = crypto_ahash_init(req);
952951
if (err)
@@ -970,8 +969,7 @@ u32 krb5_etm_checksum(struct crypto_sync_skcipher *cipher,
970969

971970
out_free_ahash:
972971
ahash_request_free(req);
973-
out_free_mem:
974-
kfree(iv);
972+
out_free_cksumdata:
975973
kfree_sensitive(checksumdata);
976974
return err ? GSS_S_FAILURE : GSS_S_COMPLETE;
977975
}

0 commit comments

Comments
 (0)