WSL2-Linux-Kernel/drivers/crypto
Giovanni Cabiddu 7697139d5d crypto: qat - fix out-of-bounds read
commit f6044cc303 upstream.

When preparing an AER-CTR request, the driver copies the key provided by
the user into a data structure that is accessible by the firmware.
If the target device is QAT GEN4, the key size is rounded up by 16 since
a rounded up size is expected by the device.
If the key size is rounded up before the copy, the size used for copying
the key might be bigger than the size of the region containing the key,
causing an out-of-bounds read.

Fix by doing the copy first and then update the keylen.

This is to fix the following warning reported by KASAN:

	[  138.150574] BUG: KASAN: global-out-of-bounds in qat_alg_skcipher_init_com.isra.0+0x197/0x250 [intel_qat]
	[  138.150641] Read of size 32 at addr ffffffff88c402c0 by task cryptomgr_test/2340

	[  138.150651] CPU: 15 PID: 2340 Comm: cryptomgr_test Not tainted 6.2.0-rc1+ #45
	[  138.150659] Hardware name: Intel Corporation ArcherCity/ArcherCity, BIOS EGSDCRB1.86B.0087.D13.2208261706 08/26/2022
	[  138.150663] Call Trace:
	[  138.150668]  <TASK>
	[  138.150922]  kasan_check_range+0x13a/0x1c0
	[  138.150931]  memcpy+0x1f/0x60
	[  138.150940]  qat_alg_skcipher_init_com.isra.0+0x197/0x250 [intel_qat]
	[  138.151006]  qat_alg_skcipher_init_sessions+0xc1/0x240 [intel_qat]
	[  138.151073]  crypto_skcipher_setkey+0x82/0x160
	[  138.151085]  ? prepare_keybuf+0xa2/0xd0
	[  138.151095]  test_skcipher_vec_cfg+0x2b8/0x800

Fixes: 67916c9516 ("crypto: qat - add AES-CTR support for QAT GEN4 devices")
Cc: <stable@vger.kernel.org>
Reported-by: Vladis Dronov <vdronov@redhat.com>
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Fiona Trahe <fiona.trahe@intel.com>
Reviewed-by: Vladis Dronov <vdronov@redhat.com>
Tested-by: Vladis Dronov <vdronov@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-03-10 09:40:03 +01:00
..
allwinner crypto: sun8i-ss - use dma_addr instead u32 2022-12-31 13:14:21 +01:00
amcc crypto: crypto4xx - Call dma_unmap_page when done 2023-03-10 09:39:17 +01:00
amlogic crypto: amlogic - Remove kcalloc without check 2022-12-31 13:14:25 +01:00
axis
bcm
caam crypto: caam - fix i.MX6SX entropy delay value 2022-06-06 08:43:39 +02:00
cavium crypto: nitrox - avoid double free on error path in nitrox_sriov_init() 2022-12-31 13:14:21 +01:00
ccp crypto: ccp - Flush the SEV-ES TMR memory before giving it to firmware 2023-03-10 09:39:13 +01:00
ccree crypto: ccree - Make cc_debugfs_global_fini() available for module init function 2022-12-31 13:14:24 +01:00
chelsio
gemini crypto: gemini - call finalize with bh disabled 2022-04-08 14:23:08 +02:00
hisilicon crypto: hisilicon: Wipe entire pool on error 2023-03-10 09:39:49 +01:00
inside-secure crypto: inside-secure - Change swab to swab32 2022-10-26 12:35:26 +02:00
keembay
marvell crypto: marvell/octeontx - prevent integer overflows 2022-10-26 12:35:27 +02:00
nx powerpc/powernv/vas: Assign real address to rx_fifo in vas_rx_win_attr 2022-06-09 10:22:43 +02:00
qat crypto: qat - fix out-of-bounds read 2023-03-10 09:40:03 +01:00
qce crypto: qce - fix uaf on qce_skcipher_register_one 2022-01-27 11:03:14 +01:00
rockchip crypto: rockchip - rework by using crypto_engine 2022-12-31 13:14:22 +01:00
stm32 crypto: stm32 - fix reference leak in stm32_crc_remove 2022-05-25 09:57:24 +02:00
ux500
virtio crypto: virtio - Replace deprecated CPU-hotplug functions. 2021-08-12 19:16:58 +08:00
vmx crypto: vmx - add missing dependencies 2022-04-08 14:23:08 +02:00
xilinx
Kconfig crypto: rockchip - rework by using crypto_engine 2022-12-31 13:14:22 +01:00
Makefile
atmel-aes-regs.h
atmel-aes.c crypto: atmel-aes - Reestablish the correct tfm context at dequeue 2022-01-27 11:03:14 +01:00
atmel-authenc.h
atmel-ecc.c
atmel-i2c.c
atmel-i2c.h
atmel-sha-regs.h
atmel-sha.c
atmel-sha204a.c
atmel-tdes-regs.h
atmel-tdes.c crypto: atmel - Set OFB's blocksize to 1 2021-07-30 10:58:34 +08:00
exynos-rng.c
geode-aes.c
geode-aes.h
hifn_795x.c
img-hash.c crypto: img-hash - Fix variable dereferenced before check 'hdev->req' 2022-12-31 13:14:26 +01:00
ixp4xx_crypto.c ARM: SoC changes for 5.14 2021-07-10 09:22:44 -07:00
mxs-dcp.c crypto: mxs-dcp - Fix scatterlist processing 2022-04-08 14:23:05 +02:00
n2_asm.S
n2_core.c crypto: n2 - add missing hash statesize 2023-01-12 11:58:58 +01:00
n2_core.h
omap-aes-gcm.c
omap-aes.c crypto: omap-aes - Fix broken pm_runtime_and_get() usage 2022-01-27 11:05:06 +01:00
omap-aes.h
omap-crypto.c crypto: omap - Avoid redundant copy when using truncated sg list 2021-08-21 15:44:53 +08:00
omap-crypto.h
omap-des.c crypto: omap - Fix inconsistent locking of device lists 2021-08-21 15:44:53 +08:00
omap-sham.c crypto: omap-sham - Use pm_runtime_resume_and_get() in omap_sham_probe() 2022-12-31 13:14:26 +01:00
padlock-aes.c
padlock-sha.c
qcom-rng.c crypto: qcom-rng - fix infinite loop on requests not multiple of WORD_SZ 2022-05-25 09:57:28 +02:00
s5p-sss.c crypto: s5p-sss - Add error handling in s5p_aes_probe() 2021-11-18 19:15:53 +01:00
sa2ul.c
sa2ul.h
sahara.c crypto: sahara - don't sleep when in softirq 2022-10-26 12:35:23 +02:00
talitos.c
talitos.h