linux-stable/crypto
Daniel Jordan 8c1f8ee594 crypto: pcrypt - Delay write to padata->info
[ Upstream commit 68b6dea802 ]

These three events can race when pcrypt is used multiple times in a
template ("pcrypt(pcrypt(...))"):

  1.  [taskA] The caller makes the crypto request via crypto_aead_encrypt()
  2.  [kworkerB] padata serializes the inner pcrypt request
  3.  [kworkerC] padata serializes the outer pcrypt request

3 might finish before the call to crypto_aead_encrypt() returns in 1,
resulting in two possible issues.

First, a use-after-free of the crypto request's memory when, for
example, taskA writes to the outer pcrypt request's padata->info in
pcrypt_aead_enc() after kworkerC completes the request.

Second, the outer pcrypt request overwrites the inner pcrypt request's
return code with -EINPROGRESS, making a successful request appear to
fail.  For instance, kworkerB writes the outer pcrypt request's
padata->info in pcrypt_aead_done() and then taskA overwrites it
in pcrypt_aead_enc().

Avoid both situations by delaying the write of padata->info until after
the inner crypto request's return code is checked.  This prevents the
use-after-free by not touching the crypto request's memory after the
next-inner crypto request is made, and stops padata->info from being
overwritten.

Fixes: 5068c7a883 ("crypto: pcrypt - Add pcrypt crypto parallelization wrapper")
Reported-by: syzbot+b187b77c8474f9648fae@syzkaller.appspotmail.com
Signed-off-by: Daniel Jordan <daniel.m.jordan@oracle.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-11-26 11:48:36 +01:00
..
asymmetric_keys crypto: asymmetric_keys - select CRYPTO_HASH where needed 2019-08-04 09:33:23 +02:00
async_tx async_tx: Fix DMA_PREP_FENCE usage in do_async_gen_syndrome() 2018-04-13 19:47:58 +02:00
.gitignore
842.c
ablk_helper.c
ablkcipher.c crypto: skcipher - Fix -Wstringop-truncation warnings 2018-10-03 17:01:41 -07:00
aead.c
aes_generic.c
af_alg.c crypto: af_alg - fix use-after-free in af_alg_accept() due to bh_lock_sock() 2020-07-09 09:35:55 +02:00
ahash.c crypto: hash - set CRYPTO_TFM_NEED_KEY if ->setkey() fails 2019-03-23 13:19:45 +01:00
akcipher.c
algapi.c crypto: api - Fix race condition in crypto_spawn_alg 2020-02-14 16:31:02 -05:00
algboss.c crypto: algboss - don't wait during notifier callback 2020-06-30 15:38:32 -04:00
algif_aead.c crypto: algif_aead - Do not set MAY_BACKLOG on the async path 2020-10-29 09:05:32 +01:00
algif_hash.c crypto: af_alg - fix use-after-free in af_alg_accept() due to bh_lock_sock() 2020-07-09 09:35:55 +02:00
algif_rng.c
algif_skcipher.c crypto: af_alg - fix use-after-free in af_alg_accept() due to bh_lock_sock() 2020-07-09 09:35:55 +02:00
ansi_cprng.c
anubis.c
api.c crypto: api - Fix race condition in crypto_spawn_alg 2020-02-14 16:31:02 -05:00
arc4.c
authenc.c crypto: authenc - fix parsing key with misaligned rta_len 2019-01-23 08:10:54 +01:00
authencesn.c crypto: authencesn - Avoid twice completion call in decrypt path 2019-01-23 08:10:54 +01:00
blkcipher.c crypto: skcipher - Fix -Wstringop-truncation warnings 2018-10-03 17:01:41 -07:00
blowfish_common.c
blowfish_generic.c
camellia_generic.c
cast5_generic.c
cast6_generic.c
cast_common.c
cbc.c
ccm.c crypto: ccm - preserve the IV buffer 2017-11-15 15:53:18 +01:00
chacha20_generic.c
chacha20poly1305.c crypto: chacha20poly1305 - fix atomic sleep when using async algorithm 2019-08-04 09:33:26 +02:00
cipher.c
cmac.c
compress.c
crc32_generic.c crypto: hash - annotate algorithms taking optional key 2018-02-25 11:05:43 +01:00
crc32c_generic.c crypto: hash - annotate algorithms taking optional key 2018-02-25 11:05:43 +01:00
crct10dif_common.c
crct10dif_generic.c crypto: crct10dif-generic - fix use via crypto_shash_digest() 2019-05-21 18:48:57 +02:00
cryptd.c crypto: hash - annotate algorithms taking optional key 2018-02-25 11:05:43 +01:00
crypto_engine.c kthread: kthread worker API cleanup 2016-10-11 15:06:33 -07:00
crypto_null.c
crypto_user.c crypto: user - fix memory leak in crypto_report 2019-12-21 10:41:41 +01:00
crypto_wq.c
ctr.c
cts.c
deflate.c
des_generic.c
dh.c crypto: dh - Fix double free of ctx->p 2017-11-24 08:33:41 +01:00
dh_helper.c crypto: dh - Don't permit 'key' or 'g' size longer than 'p' 2017-11-21 09:23:29 +01:00
drbg.c crypto: drbg - set freed buffers to NULL 2018-05-01 15:13:08 -07:00
ecb.c
ecc.c crypto: ecdh - fix big endian bug in ECC library 2019-12-21 10:41:40 +01:00
ecc.h
ecc_curve_defs.h
ecdh.c
ecdh_helper.c crypto: ecdh_helper - Ensure 'len >= secret.len' in decode_key() 2021-03-03 17:44:36 +01:00
echainiv.c crypto: echainiv - Replace chaining with multiplication 2016-09-13 18:44:57 +08:00
fcrypt.c
fips.c
gcm.c crypto: gcm - fix incompatibility between "gcm" and "gcm_base" 2019-05-21 18:49:00 +02:00
gf128mul.c
ghash-generic.c crypto: ghash - fix unaligned memory access in ghash_setkey() 2019-08-04 09:33:25 +02:00
hash_info.c
hmac.c crypto: hmac - require that the underlying hash algorithm is unkeyed 2017-12-20 10:07:15 +01:00
internal.h crypto: api - Fix race condition in crypto_spawn_alg 2020-02-14 16:31:02 -05:00
jitterentropy-kcapi.c
jitterentropy.c
Kconfig crypto: ecdh - fix typo in KPP dependency of CRYPTO_ECDH 2018-02-03 17:05:34 +01:00
keywrap.c
khazad.c
kpp.c
lrw.c gcc-10: avoid shadowing standard library 'free()' in crypto 2020-05-20 08:15:37 +02:00
lz4.c
lz4hc.c
lzo.c
Makefile crypto: improve gcc optimization flags for serpent and wp512 2017-03-18 19:14:26 +08:00
mcryptd.c crypto: hash - annotate algorithms taking optional key 2018-02-25 11:05:43 +01:00
md4.c
md5.c
memneq.c
michael_mic.c
pcbc.c crypto: pcbc - remove bogus memcpy()s with src == dest 2019-03-23 13:19:47 +01:00
pcrypt.c crypto: pcrypt - Delay write to padata->info 2021-11-26 11:48:36 +01:00
poly1305_generic.c crypto: poly1305 - remove ->setkey() method 2018-02-17 13:21:15 +01:00
proc.c
ripemd.h
rmd128.c
rmd160.c
rmd256.c
rmd320.c
rng.c
rsa-pkcs1pad.c crypto: fix a memory leak in rsa-kcs1pad's encryption mode 2019-11-25 09:53:02 +01:00
rsa.c
rsa_helper.c crypto: rsa - fix buffer overread when stripping leading zeroes 2017-12-20 10:07:15 +01:00
rsaprivkey.asn1
rsapubkey.asn1
salsa20_generic.c crypto: salsa20 - don't access already-freed walk.iv 2019-05-21 18:49:00 +02:00
scatterwalk.c crypto: scatterwalk - Remove unnecessary aliasing check in map_and_copy 2016-11-22 15:02:25 +08:00
seed.c
seqiv.c
serpent_generic.c
sha1_generic.c
sha3_generic.c crypto: sha3-generic - fixes for alignment and big endian operation 2018-02-03 17:05:34 +01:00
sha256_generic.c
sha512_generic.c
shash.c crypto: shash - avoid comparing pointers to exported functions under CFI 2021-07-20 16:20:59 +02:00
skcipher.c crypto: skcipher - Add missing API setkey checks 2017-06-07 12:07:46 +02:00
tcrypt.c crypto: tcrypt - fix ghash-generic speed test 2018-11-13 11:16:57 -08:00
tcrypt.h
tea.c
testmgr.c crypto: testmgr - add guard to dst buffer for ahash_export 2016-10-02 22:33:43 +08:00
testmgr.h crypto: x86/poly1305 - fix overflow during partial reduction 2019-04-27 09:34:43 +02:00
tgr192.c crypto: tgr192 - fix unaligned memory access 2020-01-29 10:24:12 +01:00
twofish_common.c
twofish_generic.c
vmac.c crypto: vmac - separate tfm and request context 2018-08-17 20:59:29 +02:00
wp512.c
xcbc.c
xor.c crypto: xor - Fix warning when XOR_SELECT_TEMPLATE is unset 2016-08-31 23:00:48 +08:00
xts.c gcc-10: avoid shadowing standard library 'free()' in crypto 2020-05-20 08:15:37 +02:00