An error occurred while fetching folder content.
crypto: pcrypt - Delay write to padata->info
Daniel Jordan authored
[ Upstream commit 68b6dea8 ]

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: 5068c7a8

 ("crypto: pcrypt - Add pcrypt crypto parallelization wrapper")
Reported-by: syzbot+b187b77c8474f9648fae@syzkaller.appspotmail.com
Signed-off-by: default avatarDaniel Jordan <daniel.m.jordan@oracle.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
8c1f8ee5
Name Last commit Last update
..
asymmetric_keys crypto: asymmetric_keys - select CRYPTO_HASH where needed
async_tx async_tx: Fix DMA_PREP_FENCE usage in do_async_gen_syndrome()
.gitignore crypto: rsa - add .gitignore for crypto/*.-asn1.[ch] files
842.c crypto: 842 - change 842 alg to use software
Kconfig crypto: ecdh - fix typo in KPP dependency of CRYPTO_ECDH
Makefile crypto: improve gcc optimization flags for serpent and wp512
ablk_helper.c crypto: ablk_helper - Fix cryptd reordering
ablkcipher.c crypto: skcipher - Fix -Wstringop-truncation warnings
aead.c crypto: aead - Remove blkcipher null for IV generators
aes_generic.c crypto: add missing crypto module aliases
af_alg.c crypto: af_alg - fix use-after-free in af_alg_accept() due to bh_lock_sock()
ahash.c crypto: hash - set CRYPTO_TFM_NEED_KEY if ->setkey() fails
akcipher.c crypto: akcipher - add akcipher declarations needed by templates.
algapi.c crypto: api - Fix race condition in crypto_spawn_alg
algboss.c crypto: algboss - don't wait during notifier callback
algif_aead.c crypto: algif_aead - Do not set MAY_BACKLOG on the async path
algif_hash.c crypto: af_alg - fix use-after-free in af_alg_accept() due to bh_lock_sock()
algif_rng.c crypto: algif_rng - Remove obsolete const-removal cast
algif_skcipher.c crypto: af_alg - fix use-after-free in af_alg_accept() due to bh_lock_sock()
ansi_cprng.c crypto: ansi_cprng - Convert to new rng interface
anubis.c crypto: prefix module autoloading with "crypto-"
api.c crypto: api - Fix race condition in crypto_spawn_alg
arc4.c crypto: prefix module autoloading with "crypto-"
authenc.c crypto: authenc - fix parsing key with misaligned rta_len
authencesn.c crypto: authencesn - Avoid twice completion call in decrypt path
blkcipher.c
blowfish_common.c
blowfish_generic.c
camellia_generic.c
cast5_generic.c
cast6_generic.c
cast_common.c
cbc.c
ccm.c
chacha20_generic.c
chacha20poly1305.c
cipher.c
cmac.c
compress.c
crc32_generic.c
crc32c_generic.c
crct10dif_common.c
crct10dif_generic.c
cryptd.c
crypto_engine.c
crypto_null.c
crypto_user.c
crypto_wq.c
ctr.c
cts.c
deflate.c
des_generic.c
dh.c
dh_helper.c
drbg.c
ecb.c
ecc.c
ecc.h
ecc_curve_defs.h
ecdh.c
ecdh_helper.c
echainiv.c
fcrypt.c
fips.c
gcm.c
gf128mul.c
ghash-generic.c
hash_info.c
hmac.c
internal.h
jitterentropy-kcapi.c
jitterentropy.c
keywrap.c
khazad.c
kpp.c
lrw.c
lz4.c
lz4hc.c
lzo.c
mcryptd.c
md4.c
md5.c
memneq.c
michael_mic.c
pcbc.c
pcrypt.c
poly1305_generic.c
proc.c
ripemd.h
rmd128.c
rmd160.c
rmd256.c
rmd320.c
rng.c
rsa-pkcs1pad.c
rsa.c
rsa_helper.c
rsaprivkey.asn1
rsapubkey.asn1
salsa20_generic.c