drivers/crypto/atmel-aes.c:944 atmel_aes_ctr_transfer() warn: right shifting more than type allows 16 vs 16
PATCH 37/96 drivers/crypto/atmel-aes.c:944 atmel_aes_ctr_transfer() warn: right shifting more than type allows 16 vs 16
tree: https://git.kernel.org/pub/scm/linux/kernel/git/sashal/linux-stable.git queue-4.9 head: 89d815750d288127abb27eedf62fb7606c59cd69 commit: 5f5295e65a5cd95f1c9c208547be07a5bb0ec6c5 [37/96] crypto: atmel-aes - Fix counter overflow in CTR mode
If you fix the issue, kindly add following tag
smatch warnings:drivers/crypto/atmel-aes.c:944 atmel_aes_ctr_transfer() warn: right shifting more than type allows 16 vs 16
# https://git.kernel.org/pub/scm/linux/kernel/git/sashal/linux-stable.git/commit/?id=5f5295e65a5cd95f1c9c208547be07a5bb0ec6c5
git remote add sashal-linux-stable https://git.kernel.org/pub/scm/linux/kernel/git/sashal/linux-stable.git
git remote update sashal-linux-stable
git checkout 5f5295e65a5cd95f1c9c208547be07a5bb0ec6c5
vim +944 drivers/crypto/atmel-aes.c
fcac83656a3e3b Cyrille Pitchen 2015-12-17 920 static int atmel_aes_ctr_transfer(struct atmel_aes_dev *dd)
fcac83656a3e3b Cyrille Pitchen 2015-12-17 921 {
fcac83656a3e3b Cyrille Pitchen 2015-12-17 922 struct atmel_aes_ctr_ctx *ctx = atmel_aes_ctr_ctx_cast(dd->ctx);
fcac83656a3e3b Cyrille Pitchen 2015-12-17 923 struct ablkcipher_request *req = ablkcipher_request_cast(dd->areq);
fcac83656a3e3b Cyrille Pitchen 2015-12-17 924 struct scatterlist *src, *dst;
fcac83656a3e3b Cyrille Pitchen 2015-12-17 925 size_t datalen;
5f5295e65a5cd9 Tudor Ambarus 2019-12-05 926 u32 ctr;
5f5295e65a5cd9 Tudor Ambarus 2019-12-05 927 u16 blocks, start, end;
^^^^^^^^^^fcac83656a3e3b Cyrille Pitchen 2015-12-17 928 bool use_dma, fragmented = false;
fcac83656a3e3b Cyrille Pitchen 2015-12-17 929
fcac83656a3e3b Cyrille Pitchen 2015-12-17 930 /* Check for transfer completion. */
fcac83656a3e3b Cyrille Pitchen 2015-12-17 931 ctx->offset += dd->total;
fcac83656a3e3b Cyrille Pitchen 2015-12-17 932 if (ctx->offset >= req->nbytes)
fcac83656a3e3b Cyrille Pitchen 2015-12-17 933 return atmel_aes_transfer_complete(dd);
fcac83656a3e3b Cyrille Pitchen 2015-12-17 934
fcac83656a3e3b Cyrille Pitchen 2015-12-17 935 /* Compute data length. */
fcac83656a3e3b Cyrille Pitchen 2015-12-17 936 datalen = req->nbytes - ctx->offset;
fcac83656a3e3b Cyrille Pitchen 2015-12-17 937 blocks = DIV_ROUND_UP(datalen, AES_BLOCK_SIZE);
fcac83656a3e3b Cyrille Pitchen 2015-12-17 938 ctr = be32_to_cpu(ctx->iv[3]);
5f5295e65a5cd9 Tudor Ambarus 2019-12-05 939
fcac83656a3e3b Cyrille Pitchen 2015-12-17 940 /* Check 16bit counter overflow. */
5f5295e65a5cd9 Tudor Ambarus 2019-12-05 941 start = ctr & 0xffff;
5f5295e65a5cd9 Tudor Ambarus 2019-12-05 942 end = start + blocks - 1;
fcac83656a3e3b Cyrille Pitchen 2015-12-17 943
fcac83656a3e3b Cyrille Pitchen 2015-12-17 @944 if (blocks >> 16 || end < start) {
^^^^^^^^^^^^This is always non-zero.
fcac83656a3e3b Cyrille Pitchen 2015-12-17 945 ctr |= 0xffff;
fcac83656a3e3b Cyrille Pitchen 2015-12-17 946 datalen = AES_BLOCK_SIZE * (0x10000 - start);
fcac83656a3e3b Cyrille Pitchen 2015-12-17 947 fragmented = true;
fcac83656a3e3b Cyrille Pitchen 2015-12-17 948 }
5f5295e65a5cd9 Tudor Ambarus 2019-12-05 949
fcac83656a3e3b Cyrille Pitchen 2015-12-17 950 use_dma = (datalen >= ATMEL_AES_DMA_THRESHOLD);
fcac83656a3e3b Cyrille Pitchen 2015-12-17 951
fcac83656a3e3b Cyrille Pitchen 2015-12-17 952 /* Jump to offset. */
fcac83656a3e3b Cyrille Pitchen 2015-12-17 953 src = scatterwalk_ffwd(ctx->src, req->src, ctx->offset);
fcac83656a3e3b Cyrille Pitchen 2015-12-17 954 dst = ((req->src == req->dst) ? src :
fcac83656a3e3b Cyrille Pitchen 2015-12-17 955 scatterwalk_ffwd(ctx->dst, req->dst, ctx->offset));
fcac83656a3e3b Cyrille Pitchen 2015-12-17 956
fcac83656a3e3b Cyrille Pitchen 2015-12-17 957 /* Configure hardware. */
fcac83656a3e3b Cyrille Pitchen 2015-12-17 958 atmel_aes_write_ctrl(dd, use_dma, ctx->iv);
fcac83656a3e3b Cyrille Pitchen 2015-12-17 959 if (unlikely(fragmented)) {
fcac83656a3e3b Cyrille Pitchen 2015-12-17 960 /*
fcac83656a3e3b Cyrille Pitchen 2015-12-17 961 * Increment the counter manually to cope with the hardware
fcac83656a3e3b Cyrille Pitchen 2015-12-17 962 * counter overflow.
fcac83656a3e3b Cyrille Pitchen 2015-12-17 963 */
fcac83656a3e3b Cyrille Pitchen 2015-12-17 964 ctx->iv[3] = cpu_to_be32(ctr);
fcac83656a3e3b Cyrille Pitchen 2015-12-17 965 crypto_inc((u8 *)ctx->iv, AES_BLOCK_SIZE);
fcac83656a3e3b Cyrille Pitchen 2015-12-17 966 }
fcac83656a3e3b Cyrille Pitchen 2015-12-17 967
fcac83656a3e3b Cyrille Pitchen 2015-12-17 968 if (use_dma)
fcac83656a3e3b Cyrille Pitchen 2015-12-17 969 return atmel_aes_dma_start(dd, src, dst, datalen,
fcac83656a3e3b Cyrille Pitchen 2015-12-17 970 atmel_aes_ctr_transfer);
fcac83656a3e3b Cyrille Pitchen 2015-12-17 971
fcac83656a3e3b Cyrille Pitchen 2015-12-17 972 return atmel_aes_cpu_start(dd, src, dst, datalen,
fcac83656a3e3b Cyrille Pitchen 2015-12-17 973 atmel_aes_ctr_transfer);
fcac83656a3e3b Cyrille Pitchen 2015-12-17 974 }---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org