linux-stable/drivers/crypto
Giovanni Cabiddu 2b1501f058 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:29:41 +01:00
..
allwinner hwrng: core - treat default_quality as a maximum and default to 1024 2022-11-18 16:59:34 +08:00
amcc crypto: crypto4xx - Call dma_unmap_page when done 2023-03-10 09:28:21 +01:00
amlogic crypto: amlogic - Remove kcalloc without check 2022-12-02 18:12:40 +08:00
aspeed crypto: aspeed - Remove redundant dev_err call 2022-09-30 13:59:13 +08:00
axis crypto: artpec6 - Fix printk warning on size_t/%d 2022-09-24 16:14:43 +08:00
bcm crypto: bcm - Simplify obtain the name for cipher 2022-09-30 13:59:13 +08:00
caam crypto: caam - fix CAAM io mem access in blob_gen 2022-12-30 17:57:42 +08:00
cavium crypto: cavium - Set DMA alignment explicitly 2022-12-09 18:45:00 +08:00
ccp crypto: ccp - Flush the SEV-ES TMR memory before giving it to firmware 2023-03-10 09:28:12 +01:00
ccree crypto: ccree - Set DMA alignment explicitly 2022-12-09 18:45:00 +08:00
chelsio crypto: chelsio - Set DMA alignment explicitly 2022-12-09 18:45:00 +08:00
gemini Revert "crypto: gemini - Fix error check for dma_map_sg" 2022-09-02 18:15:53 +08:00
hisilicon crypto: hisilicon: Wipe entire pool on error 2023-03-10 09:29:10 +01:00
inside-secure crypto: safexcel - Set DMA alignment explicitly 2022-12-09 18:45:00 +08:00
keembay crypto: keembay - Set DMA alignment explicitly 2022-12-09 18:45:00 +08:00
marvell crypto: octeontx2 - Fix objects shared between several modules 2023-03-10 09:28:20 +01:00
nx crypto: Prepare to move crypto_tfm_ctx 2022-12-02 18:12:40 +08:00
qat crypto: qat - fix out-of-bounds read 2023-03-10 09:29:41 +01:00
qce crypto: qce - Set DMA alignment explicitly 2022-12-09 18:45:00 +08:00
rockchip crypto: rockchip - Remove surplus dev_err() when using platform_get_irq() 2022-11-11 18:14:59 +08:00
stm32 crypto: stm32/cryp - enable for use with Ux500 2022-12-09 18:45:00 +08:00
ux500 crypto: ux500 - update debug config after ux500 cryp driver removal 2023-03-10 09:28:04 +01:00
virtio virtio-crypto: fix memory leak in virtio_crypto_alg_skcipher_close_session() 2022-12-28 05:28:10 -05:00
vmx Merge branch 'topic/objtool' into next 2022-12-08 23:57:47 +11:00
xilinx crypto: xilinx: prevent probing on non-xilinx hardware 2022-03-09 15:12:31 +12:00
atmel-aes-regs.h
atmel-aes.c crypto: atmel-aes - Drop if with an always false condition 2022-07-15 16:43:20 +08:00
atmel-authenc.h
atmel-ecc.c MAINTAINERS: Update email of Tudor Ambarus 2023-01-07 15:18:44 +01:00
atmel-i2c.c MAINTAINERS: Update email of Tudor Ambarus 2023-01-07 15:18:44 +01:00
atmel-i2c.h MAINTAINERS: Update email of Tudor Ambarus 2023-01-07 15:18:44 +01:00
atmel-sha-regs.h
atmel-sha.c crypto: atmel-sha - initialize sha_dd while declaring 2022-07-15 16:43:22 +08:00
atmel-sha204a.c crypto: atmel-sha204a - Convert to i2c's .probe_new() 2022-11-25 17:39:19 +08:00
atmel-tdes-regs.h
atmel-tdes.c crypto: atmel-tdes - initialize tdes_dd while declaring 2022-07-15 16:43:22 +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-09 18:45:00 +08:00
ixp4xx_crypto.c crypto: ixp4xx - Fix sparse warnings 2022-10-21 19:15:35 +08:00
Kconfig crypto: ccree,hisilicon - Fix dependencies to correct algorithm 2022-12-02 18:12:41 +08:00
Makefile crypto: stm32 - enable drivers to be used on Ux500 2022-12-09 18:45:00 +08:00
mxs-dcp.c crypto: mxs-dcp - Fix scatterlist processing 2022-01-31 11:21:46 +11:00
n2_asm.S
n2_core.c crypto: n2 - add missing hash statesize 2022-10-21 19:15:35 +08:00
n2_core.h
omap-aes-gcm.c
omap-aes.c crypto: omap-aes - Drop if with an always false condition 2022-07-15 16:43:21 +08: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-des - Drop if with an always false condition 2022-07-15 16:43:21 +08:00
omap-sham.c crypto: omap-sham - Use pm_runtime_resume_and_get() in omap_sham_probe() 2022-12-02 18:12:40 +08:00
padlock-aes.c
padlock-sha.c
qcom-rng.c crypto: qcom-rng - Fix qcom_rng_of_match unused warning 2022-08-19 18:39:35 +08:00
s5p-sss.c crypto: s5p-sss - Drop if with an always false condition 2022-07-15 16:43:21 +08:00
sa2ul.c crypto: sa2ul - Check engine status before enabling 2022-07-15 16:43:22 +08:00
sa2ul.h crypto: sa2ul - Check engine status before enabling 2022-07-15 16:43:22 +08:00
sahara.c crypto: sahara - Fix error check for dma_map_sg 2022-08-26 18:50:39 +08:00
talitos.c crypto: talitos - Use the defined variable to clean code 2022-10-21 19:15:35 +08:00
talitos.h crypto: talitos - Replace zero-length arrays with DECLARE_FLEX_ARRAY() helper 2022-10-21 19:05:24 +08:00