linux-brain/drivers/crypto
Iuliana Prodan 35a9399714 crypto: caam - fix the address of the last entry of S/G
commit 55b3209acbb01cb02b1ee6b1afe80d83b1aab36d upstream.

For skcipher algorithms, the input, output HW S/G tables
look like this: [IV, src][dst, IV]
Now, we can have 2 conditions here:
- there is no IV;
- src and dst are equal (in-place encryption) and scattered
and the error is an "off-by-one" in the HW S/G table.

This issue was seen with KASAN:
BUG: KASAN: slab-out-of-bounds in skcipher_edesc_alloc+0x95c/0x1018

Read of size 4 at addr ffff000022a02958 by task cryptomgr_test/321

CPU: 2 PID: 321 Comm: cryptomgr_test Not tainted
5.6.0-rc1-00165-ge4ef8383-dirty #4
Hardware name: LS1046A RDB Board (DT)
Call trace:
 dump_backtrace+0x0/0x260
 show_stack+0x14/0x20
 dump_stack+0xe8/0x144
 print_address_description.isra.11+0x64/0x348
 __kasan_report+0x11c/0x230
 kasan_report+0xc/0x18
 __asan_load4+0x90/0xb0
 skcipher_edesc_alloc+0x95c/0x1018
 skcipher_encrypt+0x84/0x150
 crypto_skcipher_encrypt+0x50/0x68
 test_skcipher_vec_cfg+0x4d4/0xc10
 test_skcipher_vec+0x178/0x1d8
 alg_test_skcipher+0xec/0x230
 alg_test.part.44+0x114/0x4a0
 alg_test+0x1c/0x60
 cryptomgr_test+0x34/0x58
 kthread+0x1b8/0x1c0
 ret_from_fork+0x10/0x18

Allocated by task 321:
 save_stack+0x24/0xb0
 __kasan_kmalloc.isra.10+0xc4/0xe0
 kasan_kmalloc+0xc/0x18
 __kmalloc+0x178/0x2b8
 skcipher_edesc_alloc+0x21c/0x1018
 skcipher_encrypt+0x84/0x150
 crypto_skcipher_encrypt+0x50/0x68
 test_skcipher_vec_cfg+0x4d4/0xc10
 test_skcipher_vec+0x178/0x1d8
 alg_test_skcipher+0xec/0x230
 alg_test.part.44+0x114/0x4a0
 alg_test+0x1c/0x60
 cryptomgr_test+0x34/0x58
 kthread+0x1b8/0x1c0
 ret_from_fork+0x10/0x18

Freed by task 0:
(stack is not available)

The buggy address belongs to the object at ffff000022a02800
 which belongs to the cache dma-kmalloc-512 of size 512
The buggy address is located 344 bytes inside of
 512-byte region [ffff000022a02800, ffff000022a02a00)
The buggy address belongs to the page:
page:fffffe00006a8000 refcount:1 mapcount:0 mapping:ffff00093200c400
index:0x0 compound_mapcount: 0
flags: 0xffff00000010200(slab|head)
raw: 0ffff00000010200 dead000000000100 dead000000000122 ffff00093200c400
raw: 0000000000000000 0000000080100010 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff000022a02800: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 ffff000022a02880: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff000022a02900: 00 00 00 00 00 00 00 00 00 00 fc fc fc fc fc fc
                                                    ^
 ffff000022a02980: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff000022a02a00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc

Fixes: 334d37c9e2 ("crypto: caam - update IV using HW support")
Cc: <stable@vger.kernel.org> # v5.3+
Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-05-06 08:15:07 +02:00
..
amcc crypto: crypto4xx - fix double-free in crypto4xx_destroy_sdr 2019-12-13 08:43:04 +01:00
axis crypto: artpec6 - return correct error code for failed setkey() 2020-02-14 16:34:18 -05:00
bcm crypto: bcm/des - switch to new verification routines 2019-08-22 14:39:38 +10:00
caam crypto: caam - fix the address of the last entry of S/G 2020-05-06 08:15:07 +02:00
cavium crypto: cavium/nitrox - fix firmware assignment to AE cores 2020-01-17 19:48:45 +01:00
ccp crypto: ccp - set max RSA modulus size for v3 platform devices as well 2020-02-11 04:35:30 -08:00
ccree crypto: ccree - dec auth tag size from cryptlen map 2020-04-17 10:50:18 +02:00
chelsio Crypto: chelsio - Fixes a hang issue during driver registration 2020-05-02 08:49:00 +02:00
hisilicon crypto: hisilicon - Use the offset fields in sqe to avoid need to split scatterlists 2020-02-11 04:35:30 -08:00
inside-secure crypto: inside-secure - Fix a maybe-uninitialized warning 2019-12-31 16:43:56 +01:00
marvell crypto: marvell - Use kzfree rather than its implementation 2019-09-09 23:48:40 +10:00
mediatek crypto: mediatek - fix incorrect crypto key setting 2019-09-05 14:36:54 +10:00
nx crypto: nx - remove unused variables 'nx_driver_string' and 'nx_driver_version' 2019-08-30 18:05:31 +10:00
qat crypto: qat - Silence smp_processor_id() warning 2019-08-02 14:44:00 +10:00
qce crypto: qce/des - switch to new verification routines 2019-08-22 14:57:32 +10:00
rockchip crypto: rk3288/des - switch to new verification routines 2019-08-22 14:57:32 +10:00
stm32 crypto: des - split off DES library from generic DES cipher driver 2019-08-22 14:57:33 +10:00
sunxi-ss crypto: sun4i-ss - fix big endian issues 2020-01-26 10:01:01 +01:00
ux500 crypto: ux500 - Fix COMPILE_TEST warnings 2019-09-09 23:48:41 +10:00
virtio crypto: virtio - implement missing support for output IVs 2020-01-17 19:48:46 +01:00
vmx crypto: vmx - reject xts inputs that are too short 2020-02-01 09:34:52 +00:00
Kconfig crypto: inside-secure - add unspecified HAS_IOMEM dependency 2020-02-24 08:36:39 +01:00
Makefile crypto: atmel-i2c - add support for SHA204A random number generator 2019-05-30 15:35:45 +08:00
atmel-aes-regs.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
atmel-aes.c crypto: atmel-aes - Fix counter overflow in CTR mode 2020-02-11 04:35:31 -08:00
atmel-authenc.h crypto: atmel - Fix authenc support when it is set to m 2019-12-31 16:45:12 +01:00
atmel-ecc.c crypto: atmel-ecc - factor out code that can be shared 2019-05-30 15:35:45 +08:00
atmel-i2c.c crypto: atmel - Fix -Wunused-const-variable warning 2019-08-30 18:05:31 +10:00
atmel-i2c.h crypto: atmel - Fix -Wunused-const-variable warning 2019-08-30 18:05:31 +10:00
atmel-sha-regs.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
atmel-sha.c crypto: atmel-sha - fix error handling when setting hmac key 2020-02-14 16:34:18 -05:00
atmel-sha204a.c crypto: atmel-sha204a - Use device-managed registration API 2019-08-02 14:43:59 +10:00
atmel-tdes-regs.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
atmel-tdes.c crypto: atmel/des - switch to new verification routines 2019-08-22 14:39:38 +10:00
exynos-rng.c crypto: exynos - use devm_platform_ioremap_resource() to simplify code 2019-08-09 15:11:59 +10:00
geode-aes.c crypto: geode-aes - convert to skcipher API and make thread-safe 2020-01-17 19:48:46 +01:00
geode-aes.h crypto: geode-aes - convert to skcipher API and make thread-safe 2020-01-17 19:48:46 +01:00
hifn_795x.c crypto: hifn/des - switch to new verification routines 2019-08-22 14:39:40 +10:00
img-hash.c crypto: img-hash - use devm_platform_ioremap_resource() to simplify code 2019-08-09 15:11:59 +10:00
ixp4xx_crypto.c crypto: ixp4xx/des - switch to new verification routines 2019-08-22 14:57:31 +10:00
mxs-dcp.c crypto: mxs-dcp - fix scatterlist linearization for hash 2020-04-17 10:50:16 +02:00
n2_asm.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
n2_core.c crypto: n2 - Rename arrays to avoid conflict with crypto/sha256.h 2019-09-05 14:54:54 +10:00
n2_core.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
omap-aes-gcm.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
omap-aes.c crypto: drivers - Remove dev_err() usage after platform_get_irq() 2019-08-09 15:11:38 +10:00
omap-aes.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
omap-crypto.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
omap-crypto.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
omap-des.c crypto: omap/des - switch to new verification routines 2019-08-22 14:57:31 +10:00
omap-sham.c crypto: drivers - Remove dev_err() usage after platform_get_irq() 2019-08-09 15:11:38 +10:00
padlock-aes.c crypto: padlock/aes - switch to library version of key expansion routine 2019-07-26 14:56:02 +10:00
padlock-sha.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
picoxcell_crypto.c crypto: picoxcell - adjust the position of tasklet_init and fix missed tasklet_kill 2020-02-11 04:35:31 -08:00
picoxcell_crypto_regs.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
qcom-rng.c crypto: qcom-rng - use devm_platform_ioremap_resource() to simplify code 2019-08-09 15:12:03 +10:00
s5p-sss.c crypto: s5p - use correct block size of 1 for ctr(aes) 2019-08-30 18:05:28 +10:00
sahara.c crypto: drivers - Remove dev_err() usage after platform_get_irq() 2019-08-09 15:11:38 +10:00
talitos.c crypto: talitos - fix missing break in switch statement 2019-09-20 22:53:08 +10:00
talitos.h crypto: talitos - drop icv_ool 2019-07-03 22:13:11 +08:00