Skip to content

Commit 9063157

Browse files
committed
crypto: qat - fix out-of-bounds read
jira LE-1907 Rebuild_History Non-Buildable kernel-rt-5.14.0-284.30.1.rt14.315.el9_2 commit-author Giovanni Cabiddu <[email protected]> commit f6044cc 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+ ctrliq#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: 67916c9 ("crypto: qat - add AES-CTR support for QAT GEN4 devices") Cc: <[email protected]> Reported-by: Vladis Dronov <[email protected]> Signed-off-by: Giovanni Cabiddu <[email protected]> Reviewed-by: Fiona Trahe <[email protected]> Reviewed-by: Vladis Dronov <[email protected]> Tested-by: Vladis Dronov <[email protected]> Signed-off-by: Herbert Xu <[email protected]> (cherry picked from commit f6044cc) Signed-off-by: Jonathan Maple <[email protected]>
1 parent 6872b13 commit 9063157

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/crypto/qat/qat_common/qat_algs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ static void qat_alg_skcipher_init_com(struct qat_alg_skcipher_ctx *ctx,
435435
} else if (aes_v2_capable && mode == ICP_QAT_HW_CIPHER_CTR_MODE) {
436436
ICP_QAT_FW_LA_SLICE_TYPE_SET(header->serv_specif_flags,
437437
ICP_QAT_FW_LA_USE_UCS_SLICE_TYPE);
438-
keylen = round_up(keylen, 16);
439438
memcpy(cd->ucs_aes.key, key, keylen);
439+
keylen = round_up(keylen, 16);
440440
} else {
441441
memcpy(cd->aes.key, key, keylen);
442442
}

0 commit comments

Comments
 (0)