Skip to content

Commit f82e90b

Browse files
Ard Biesheuvelherbertx
authored andcommitted
crypto: arm/aes-ctr - fix NULL dereference in tail processing
The AES-CTR glue code avoids calling into the blkcipher API for the tail portion of the walk, by comparing the remainder of walk.nbytes modulo AES_BLOCK_SIZE with the residual nbytes, and jumping straight into the tail processing block if they are equal. This tail processing block checks whether nbytes != 0, and does nothing otherwise. However, in case of an allocation failure in the blkcipher layer, we may enter this code with walk.nbytes == 0, while nbytes > 0. In this case, we should not dereference the source and destination pointers, since they may be NULL. So instead of checking for nbytes != 0, check for (walk.nbytes % AES_BLOCK_SIZE) != 0, which implies the former in non-error conditions. Fixes: 8646485 ("crypto: arm - AES in ECB/CBC/CTR/XTS modes using ARMv8 Crypto Extensions") Cc: [email protected] Reported-by: xiakaixu <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent acdb04d commit f82e90b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/arm/crypto/aes-ce-glue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static int ctr_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
284284
err = blkcipher_walk_done(desc, &walk,
285285
walk.nbytes % AES_BLOCK_SIZE);
286286
}
287-
if (nbytes) {
287+
if (walk.nbytes % AES_BLOCK_SIZE) {
288288
u8 *tdst = walk.dst.virt.addr + blocks * AES_BLOCK_SIZE;
289289
u8 *tsrc = walk.src.virt.addr + blocks * AES_BLOCK_SIZE;
290290
u8 __aligned(8) tail[AES_BLOCK_SIZE];

0 commit comments

Comments
 (0)