• Eric Biggers's avatar
    crypto: chacha20poly1305 - fix atomic sleep when using async algorithm · baade060
    Eric Biggers authored
    commit 7545b6c2 upstream.
    
    Clear the CRYPTO_TFM_REQ_MAY_SLEEP flag when the chacha20poly1305
    operation is being continued from an async completion callback, since
    sleeping may not be allowed in that context.
    
    This is basically the same bug that was recently fixed in the xts and
    lrw templates.  But, it's always been broken in chacha20poly1305 too.
    This was found using syzkaller in combination with the updated crypto
    self-tests which actually test the MAY_SLEEP flag now.
    
    Reproducer:
    
        python -c 'import socket; socket.socket(socket.AF_ALG, 5, 0).bind(
        	       ("aead", "rfc7539(cryptd(chacha20-generic),poly1305-generic)"))'
    
    Kernel output:
    
        BUG: sleeping function called from invalid context at include/crypto/algapi.h:426
        in_atomic(): 1, irqs_disabled(): 0, pid: 1001, name: kworker/2:2
        [...]
        CPU: 2 PID: 1001 Comm: kworker/2:2 Not tainted 5.2.0-rc2 #5
        Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-20181126_142135-anatol 04/01/2014
        Workqueue: crypto cryptd_queue_worker
        Call Trace:
         __dump_stack lib/dump_stack.c:77 [inline]
         dump_stack+0x4d/0x6a lib/dump_stack.c:113
         ___might_sleep kernel/sched/core.c:6138 [inline]
         ___might_sleep.cold.19+0x8e/0x9f kernel/sched/core.c:6095
         crypto_yield include/crypto/algapi.h:426 [inline]
         crypto_hash_walk_done+0xd6/0x100 crypto/ahash.c:113
         shash_ahash_update+0x41/0x60 crypto/shash.c:251
         shash_async_update+0xd/0x10 crypto/shash.c:260
         crypto_ahash_update include/crypto/hash.h:539 [inline]
         poly_setkey+0xf6/0x130 crypto/chacha20poly1305.c:337
         poly_init+0x51/0x60 crypto/chacha20poly1305.c:364
         async_done_continue crypto/chacha20poly1305.c:78 [inline]
         poly_genkey_done+0x15/0x30 crypto/chacha20poly1305.c:369
         cryptd_skcipher_complete+0x29/0x70 crypto/cryptd.c:279
         cryptd_skcipher_decrypt+0xcd/0x110 crypto/cryptd.c:339
         cryptd_queue_worker+0x70/0xa0 crypto/cryptd.c:184
         process_one_work+0x1ed/0x420 kernel/workqueue.c:2269
         worker_thread+0x3e/0x3a0 kernel/workqueue.c:2415
         kthread+0x11f/0x140 kernel/kthread.c:255
         ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:352
    
    Fixes: 71ebc4d1 ("crypto: chacha20poly1305 - Add a ChaCha20-Poly1305 AEAD construction, RFC7539")
    Cc: <stable@vger.kernel.org> # v4.2+
    Cc: Martin Willi <martin@strongswan.org>
    Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
    Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    baade060
Name
Last commit
Last update
..
asymmetric_keys Loading commit data...
async_tx Loading commit data...
842.c Loading commit data...
Kconfig Loading commit data...
Makefile Loading commit data...
ablkcipher.c Loading commit data...
acompress.c Loading commit data...
adiantum.c Loading commit data...
aead.c Loading commit data...
aegis.h Loading commit data...
aegis128.c Loading commit data...
aegis128l.c Loading commit data...
aegis256.c Loading commit data...
aes_generic.c Loading commit data...
aes_ti.c Loading commit data...
af_alg.c Loading commit data...
ahash.c Loading commit data...
akcipher.c Loading commit data...
algapi.c Loading commit data...
algboss.c Loading commit data...
algif_aead.c Loading commit data...
algif_hash.c Loading commit data...
algif_rng.c Loading commit data...
algif_skcipher.c Loading commit data...
ansi_cprng.c Loading commit data...
anubis.c Loading commit data...
api.c Loading commit data...
arc4.c Loading commit data...
authenc.c Loading commit data...
authencesn.c Loading commit data...
blkcipher.c Loading commit data...
blowfish_common.c Loading commit data...
blowfish_generic.c Loading commit data...
camellia_generic.c Loading commit data...
cast5_generic.c Loading commit data...
cast6_generic.c Loading commit data...
cast_common.c Loading commit data...
cbc.c Loading commit data...
ccm.c Loading commit data...
cfb.c Loading commit data...
chacha20poly1305.c Loading commit data...
chacha_generic.c Loading commit data...
cipher.c Loading commit data...
cmac.c Loading commit data...
compress.c Loading commit data...
crc32_generic.c Loading commit data...
crc32c_generic.c Loading commit data...
crct10dif_common.c Loading commit data...
crct10dif_generic.c Loading commit data...
cryptd.c Loading commit data...
crypto_engine.c Loading commit data...
crypto_null.c Loading commit data...
crypto_user_base.c Loading commit data...
crypto_user_stat.c Loading commit data...
crypto_wq.c Loading commit data...
ctr.c Loading commit data...
cts.c Loading commit data...
deflate.c Loading commit data...
des_generic.c Loading commit data...
dh.c Loading commit data...
dh_helper.c Loading commit data...
drbg.c Loading commit data...
ecb.c Loading commit data...
ecc.c Loading commit data...
ecc.h Loading commit data...
ecc_curve_defs.h Loading commit data...
ecdh.c Loading commit data...
ecdh_helper.c Loading commit data...
echainiv.c Loading commit data...
ecrdsa.c Loading commit data...
ecrdsa_defs.h Loading commit data...
ecrdsa_params.asn1 Loading commit data...
ecrdsa_pub_key.asn1 Loading commit data...
fcrypt.c Loading commit data...
fips.c Loading commit data...
gcm.c Loading commit data...
gf128mul.c Loading commit data...
ghash-generic.c Loading commit data...
hash_info.c Loading commit data...
hmac.c Loading commit data...
internal.h Loading commit data...
jitterentropy-kcapi.c Loading commit data...
jitterentropy.c Loading commit data...
keywrap.c Loading commit data...
khazad.c Loading commit data...
kpp.c Loading commit data...
lrw.c Loading commit data...
lz4.c Loading commit data...
lz4hc.c Loading commit data...
lzo-rle.c Loading commit data...
lzo.c Loading commit data...
md4.c Loading commit data...
md5.c Loading commit data...
memneq.c Loading commit data...
michael_mic.c Loading commit data...
morus1280.c Loading commit data...
morus640.c Loading commit data...
nhpoly1305.c Loading commit data...
ofb.c Loading commit data...
pcbc.c Loading commit data...
pcrypt.c Loading commit data...
poly1305_generic.c Loading commit data...
proc.c Loading commit data...
ripemd.h Loading commit data...
rmd128.c Loading commit data...
rmd160.c Loading commit data...
rmd256.c Loading commit data...
rmd320.c Loading commit data...
rng.c Loading commit data...
rsa-pkcs1pad.c Loading commit data...
rsa.c Loading commit data...
rsa_helper.c Loading commit data...
rsaprivkey.asn1 Loading commit data...
rsapubkey.asn1 Loading commit data...
salsa20_generic.c Loading commit data...
scatterwalk.c Loading commit data...
scompress.c Loading commit data...
seed.c Loading commit data...
seqiv.c Loading commit data...
serpent_generic.c Loading commit data...
sha1_generic.c Loading commit data...
sha256_generic.c Loading commit data...
sha3_generic.c Loading commit data...
sha512_generic.c Loading commit data...
shash.c Loading commit data...
simd.c Loading commit data...
skcipher.c Loading commit data...
sm3_generic.c Loading commit data...
sm4_generic.c Loading commit data...
streebog_generic.c Loading commit data...
tcrypt.c Loading commit data...
tcrypt.h Loading commit data...
tea.c Loading commit data...
testmgr.c Loading commit data...
testmgr.h Loading commit data...
tgr192.c Loading commit data...
twofish_common.c Loading commit data...
twofish_generic.c Loading commit data...
vmac.c Loading commit data...
wp512.c Loading commit data...
xcbc.c Loading commit data...
xor.c Loading commit data...
xts.c Loading commit data...
zstd.c Loading commit data...