* Re: BUG: sleeping function called from invalid context at mm/slab.h:LINE (4) [not found] <00000000000085c1ce05708f6724@google.com> @ 2018-12-15 18:43 ` syzbot 2018-12-15 20:40 ` [PATCH] crypto: x86/chacha - avoid sleeping under kernel_fpu_begin() Eric Biggers 0 siblings, 1 reply; 3+ messages in thread From: syzbot @ 2018-12-15 18:43 UTC (permalink / raw) To: davem, gregkh, herbert, linux-crypto, linux-kernel, rafael, syzkaller-bugs syzbot has found a reproducer for the following crash on: HEAD commit: d14b746c6c1c Add linux-next specific files for 20181214 git tree: linux-next console output: https://syzkaller.appspot.com/x/log.txt?x=129bc943400000 kernel config: https://syzkaller.appspot.com/x/.config?x=1da6d2d18f803140 dashboard link: https://syzkaller.appspot.com/bug?extid=9bf843c33f782d73ae7d compiler: gcc (GCC) 8.0.1 20180413 (experimental) syz repro: https://syzkaller.appspot.com/x/repro.syz?x=136154cd400000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1687bfa3400000 IMPORTANT: if you fix the bug, please add the following tag to the commit: Reported-by: syzbot+9bf843c33f782d73ae7d@syzkaller.appspotmail.com sshd (6035) used greatest stack depth: 15600 bytes left BUG: sleeping function called from invalid context at mm/slab.h:421 in_atomic(): 1, irqs_disabled(): 0, pid: 6051, name: syz-executor515 1 lock held by syz-executor515/6051: #0: 000000002f6552ef (sk_lock-AF_ALG){+.+.}, at: lock_sock include/net/sock.h:1502 [inline] #0: 000000002f6552ef (sk_lock-AF_ALG){+.+.}, at: skcipher_recvmsg+0xbb/0x1420 crypto/algif_skcipher.c:163 Preemption disabled at: [<ffffffff812e4ae6>] kernel_fpu_begin+0x16/0x260 arch/x86/kernel/fpu/core.c:127 CPU: 0 PID: 6051 Comm: syz-executor515 Not tainted 4.20.0-rc6-next-20181214+ #171 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x244/0x39d lib/dump_stack.c:113 ___might_sleep.cold.86+0x221/0x254 kernel/sched/core.c:6148 __might_sleep+0x95/0x190 kernel/sched/core.c:6101 slab_pre_alloc_hook mm/slab.h:421 [inline] slab_alloc mm/slab.c:3365 [inline] __do_kmalloc mm/slab.c:3707 [inline] __kmalloc+0x2da/0x760 mm/slab.c:3718 kmalloc include/linux/slab.h:550 [inline] kzalloc include/linux/slab.h:740 [inline] skcipher_next_slow crypto/skcipher.c:254 [inline] skcipher_walk_next+0x7f9/0x17f0 crypto/skcipher.c:358 skcipher_walk_first+0xff/0x3a0 crypto/skcipher.c:441 skcipher_walk_skcipher+0x541/0x700 crypto/skcipher.c:469 skcipher_walk_virt+0x58/0xd0 crypto/skcipher.c:479 chacha_simd_stream_xor+0xb3/0xa40 arch/x86/crypto/chacha_glue.c:141 chacha_simd+0xd8/0x110 arch/x86/crypto/chacha_glue.c:179 crypto_skcipher_decrypt include/crypto/skcipher.h:538 [inline] _skcipher_recvmsg crypto/algif_skcipher.c:146 [inline] skcipher_recvmsg+0xcc9/0x1420 crypto/algif_skcipher.c:165 sock_recvmsg_nosec net/socket.c:795 [inline] sock_recvmsg+0xd0/0x110 net/socket.c:802 ___sys_recvmsg+0x2b6/0x680 net/socket.c:2279 do_recvmmsg+0x303/0xb90 net/socket.c:2392 __sys_recvmmsg+0x265/0x2a0 net/socket.c:2471 __do_sys_recvmmsg net/socket.c:2494 [inline] __se_sys_recvmmsg net/socket.c:2487 [inline] __x64_sys_recvmmsg+0xe6/0x140 net/socket.c:2487 do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290 entry_SYSCALL_64_after_hwframe+0x49/0xbe RIP: 0033:0x440349 Code: 18 89 d0 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 fb 13 fc ff c3 66 2e 0f 1f 84 00 00 00 00 RSP: 002b:00007fff9312c608 EFLAGS: 00000203 ORIG_RAX: 000000000000012b RAX: ffffffffffffffda RBX: 00000000004002c8 RCX: 0000000000440349 RDX: 0000000000000001 RSI: 000000002000a280 RDI: 0000000000000004 RBP: 00000000006ca018 R08: 0000000000000000 R09: 00000000004002c8 R10: 0000000000000000 R11: 0000000000000203 R12: 00000000 ^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] crypto: x86/chacha - avoid sleeping under kernel_fpu_begin() 2018-12-15 18:43 ` BUG: sleeping function called from invalid context at mm/slab.h:LINE (4) syzbot @ 2018-12-15 20:40 ` Eric Biggers 2018-12-23 4:03 ` Herbert Xu 0 siblings, 1 reply; 3+ messages in thread From: Eric Biggers @ 2018-12-15 20:40 UTC (permalink / raw) To: linux-crypto, Herbert Xu; +Cc: syzkaller-bugs, davem, linux-kernel From: Eric Biggers <ebiggers@google.com> Passing atomic=true to skcipher_walk_virt() only makes the later skcipher_walk_done() calls use atomic memory allocations, not skcipher_walk_virt() itself. Thus, we have to move it outside of the preemption-disabled region (kernel_fpu_begin()/kernel_fpu_end()). (skcipher_walk_virt() only allocates memory for certain layouts of the input scatterlist, hence why I didn't notice this earlier...) Reported-by: syzbot+9bf843c33f782d73ae7d@syzkaller.appspotmail.com Fixes: 4af78261870a ("crypto: x86/chacha20 - add XChaCha20 support") Signed-off-by: Eric Biggers <ebiggers@google.com> --- arch/x86/crypto/chacha_glue.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/arch/x86/crypto/chacha_glue.c b/arch/x86/crypto/chacha_glue.c index 9b1d3fac49433..45c1c41431766 100644 --- a/arch/x86/crypto/chacha_glue.c +++ b/arch/x86/crypto/chacha_glue.c @@ -127,30 +127,27 @@ static void chacha_dosimd(u32 *state, u8 *dst, const u8 *src, } } -static int chacha_simd_stream_xor(struct skcipher_request *req, +static int chacha_simd_stream_xor(struct skcipher_walk *walk, struct chacha_ctx *ctx, u8 *iv) { u32 *state, state_buf[16 + 2] __aligned(8); - struct skcipher_walk walk; int next_yield = 4096; /* bytes until next FPU yield */ - int err; + int err = 0; BUILD_BUG_ON(CHACHA_STATE_ALIGN != 16); state = PTR_ALIGN(state_buf + 0, CHACHA_STATE_ALIGN); - err = skcipher_walk_virt(&walk, req, true); - crypto_chacha_init(state, ctx, iv); - while (walk.nbytes > 0) { - unsigned int nbytes = walk.nbytes; + while (walk->nbytes > 0) { + unsigned int nbytes = walk->nbytes; - if (nbytes < walk.total) { - nbytes = round_down(nbytes, walk.stride); + if (nbytes < walk->total) { + nbytes = round_down(nbytes, walk->stride); next_yield -= nbytes; } - chacha_dosimd(state, walk.dst.virt.addr, walk.src.virt.addr, + chacha_dosimd(state, walk->dst.virt.addr, walk->src.virt.addr, nbytes, ctx->nrounds); if (next_yield <= 0) { @@ -160,7 +157,7 @@ static int chacha_simd_stream_xor(struct skcipher_request *req, next_yield = 4096; } - err = skcipher_walk_done(&walk, walk.nbytes - nbytes); + err = skcipher_walk_done(walk, walk->nbytes - nbytes); } return err; @@ -170,13 +167,18 @@ static int chacha_simd(struct skcipher_request *req) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm); + struct skcipher_walk walk; int err; if (req->cryptlen <= CHACHA_BLOCK_SIZE || !irq_fpu_usable()) return crypto_chacha_crypt(req); + err = skcipher_walk_virt(&walk, req, true); + if (err) + return err; + kernel_fpu_begin(); - err = chacha_simd_stream_xor(req, ctx, req->iv); + err = chacha_simd_stream_xor(&walk, ctx, req->iv); kernel_fpu_end(); return err; } @@ -185,6 +187,7 @@ static int xchacha_simd(struct skcipher_request *req) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm); + struct skcipher_walk walk; struct chacha_ctx subctx; u32 *state, state_buf[16 + 2] __aligned(8); u8 real_iv[16]; @@ -193,6 +196,10 @@ static int xchacha_simd(struct skcipher_request *req) if (req->cryptlen <= CHACHA_BLOCK_SIZE || !irq_fpu_usable()) return crypto_xchacha_crypt(req); + err = skcipher_walk_virt(&walk, req, true); + if (err) + return err; + BUILD_BUG_ON(CHACHA_STATE_ALIGN != 16); state = PTR_ALIGN(state_buf + 0, CHACHA_STATE_ALIGN); crypto_chacha_init(state, ctx, req->iv); @@ -204,7 +211,7 @@ static int xchacha_simd(struct skcipher_request *req) memcpy(&real_iv[0], req->iv + 24, 8); memcpy(&real_iv[8], req->iv + 16, 8); - err = chacha_simd_stream_xor(req, &subctx, real_iv); + err = chacha_simd_stream_xor(&walk, &subctx, real_iv); kernel_fpu_end(); -- 2.19.2 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] crypto: x86/chacha - avoid sleeping under kernel_fpu_begin() 2018-12-15 20:40 ` [PATCH] crypto: x86/chacha - avoid sleeping under kernel_fpu_begin() Eric Biggers @ 2018-12-23 4:03 ` Herbert Xu 0 siblings, 0 replies; 3+ messages in thread From: Herbert Xu @ 2018-12-23 4:03 UTC (permalink / raw) To: Eric Biggers; +Cc: linux-crypto, syzkaller-bugs, davem, linux-kernel On Sat, Dec 15, 2018 at 12:40:17PM -0800, Eric Biggers wrote: > From: Eric Biggers <ebiggers@google.com> > > Passing atomic=true to skcipher_walk_virt() only makes the later > skcipher_walk_done() calls use atomic memory allocations, not > skcipher_walk_virt() itself. Thus, we have to move it outside of the > preemption-disabled region (kernel_fpu_begin()/kernel_fpu_end()). > > (skcipher_walk_virt() only allocates memory for certain layouts of the > input scatterlist, hence why I didn't notice this earlier...) > > Reported-by: syzbot+9bf843c33f782d73ae7d@syzkaller.appspotmail.com > Fixes: 4af78261870a ("crypto: x86/chacha20 - add XChaCha20 support") > Signed-off-by: Eric Biggers <ebiggers@google.com> > --- > arch/x86/crypto/chacha_glue.c | 33 ++++++++++++++++++++------------- > 1 file changed, 20 insertions(+), 13 deletions(-) Patch applied. Thanks. -- Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-12-23 4:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <00000000000085c1ce05708f6724@google.com>
2018-12-15 18:43 ` BUG: sleeping function called from invalid context at mm/slab.h:LINE (4) syzbot
2018-12-15 20:40 ` [PATCH] crypto: x86/chacha - avoid sleeping under kernel_fpu_begin() Eric Biggers
2018-12-23 4:03 ` Herbert Xu
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).