BUG: sleeping function called from invalid context at mm/slab.h:LINE (4)

102 views
Skip to first unread message

syzbot

unread,
Jul 9, 2018, 7:35:03 AM7/9/18
to gre...@linuxfoundation.org, linux-...@vger.kernel.org, raf...@kernel.org, syzkall...@googlegroups.com
Hello,

syzbot found the following crash on:

HEAD commit: d00d6d9a339d Add linux-next specific files for 20180709
git tree: linux-next
console output: https://syzkaller.appspot.com/x/log.txt?x=10ad4968400000
kernel config: https://syzkaller.appspot.com/x/.config?x=94fe2b586beccacd
dashboard link: https://syzkaller.appspot.com/bug?extid=9bf843c33f782d73ae7d
compiler: gcc (GCC) 8.0.1 20180413 (experimental)

Unfortunately, I don't have any reproducer for this crash yet.

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+9bf843...@syzkaller.appspotmail.com

RAX: ffffffffffffffda RBX: cccccccccccccccd RCX: 0000000000410081
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 00007fc453c22850
RBP: 000000000072bea0 R08: 000000000000000f R09: 0000000000000000
R10: 0000000020000100 R11: 0000000000000293 R12: 0000000000000015
R13: 00000000004c289a R14: 00000000004d41c8 R15: 0000000000000004
BUG: sleeping function called from invalid context at mm/slab.h:421
in_atomic(): 1, irqs_disabled(): 0, pid: 24283, name: syz-executor7
INFO: lockdep is turned off.
CPU: 1 PID: 24283 Comm: syz-executor7 Not tainted 4.18.0-rc3-next-20180709+
#2
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
Call Trace:
<IRQ>
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0x1c9/0x2b4 lib/dump_stack.c:113
___might_sleep.cold.86+0x11f/0x13a kernel/sched/core.c:6187
__might_sleep+0x95/0x190 kernel/sched/core.c:6140
slab_pre_alloc_hook mm/slab.h:421 [inline]
slab_alloc mm/slab.c:3378 [inline]
kmem_cache_alloc_trace+0x2bc/0x780 mm/slab.c:3618
kmalloc include/linux/slab.h:513 [inline]
kzalloc include/linux/slab.h:707 [inline]
kobject_uevent_env+0x20f/0x1110 lib/kobject_uevent.c:514
kobject_uevent+0x1f/0x30 lib/kobject_uevent.c:636
kobject_cleanup lib/kobject.c:630 [inline]
kobject_release lib/kobject.c:672 [inline]
kref_put include/linux/kref.h:70 [inline]
kobject_put+0x1fb/0x280 lib/kobject.c:689
put_device+0x20/0x30 drivers/base/core.c:2002
delete_partition_rcu_cb+0x147/0x1b0 block/partition-generic.c:254
__rcu_reclaim kernel/rcu/rcu.h:258 [inline]
rcu_do_batch kernel/rcu/tree.c:2576 [inline]
invoke_rcu_callbacks kernel/rcu/tree.c:2878 [inline]
__rcu_process_callbacks kernel/rcu/tree.c:2845 [inline]
rcu_process_callbacks+0xe01/0x2810 kernel/rcu/tree.c:2862
__do_softirq+0x2e8/0xb17 kernel/softirq.c:288
invoke_softirq kernel/softirq.c:368 [inline]
irq_exit+0x1d1/0x200 kernel/softirq.c:408
exiting_irq arch/x86/include/asm/apic.h:527 [inline]
smp_apic_timer_interrupt+0x186/0x730 arch/x86/kernel/apic/apic.c:1052
apic_timer_interrupt+0xf/0x20 arch/x86/entry/entry_64.S:867
</IRQ>
RIP: 0010:__read_once_size include/linux/compiler.h:188 [inline]
RIP: 0010:check_kcov_mode kernel/kcov.c:69 [inline]
RIP: 0010:__sanitizer_cov_trace_pc+0x26/0x50 kernel/kcov.c:101
Code: 5d c3 66 90 55 65 48 8b 04 25 40 ee 01 00 65 8b 15 5f 73 85 7e 48 89
e5 81 e2 00 01 1f 00 48 8b 75 08 75 2b 8b 90 98 12 00 00 <83> fa 02 75 20
48 8b 88 a0 12 00 00 8b 80 9c 12 00 00 48 8b 11 48
RSP: 0018:ffff8801ca396bb0 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff13
RAX: ffff8801c5c62240 RBX: ffff8801c9db6f10 RCX: ffffffff81ac0f6f
RDX: 0000000000000000 RSI: ffffffff81ac0f7d RDI: 0000000000000007
RBP: ffff8801ca396bb0 R08: ffff8801c5c62240 R09: fffff94000d02f5e
R10: fffff94000d02f5e R11: ffffea0006817af3 R12: ffffea0006817ac0
R13: 00007fc4545e3000 R14: dffffc0000000000 R15: 0000000000000000
constant_test_bit arch/x86/include/asm/bitops.h:328 [inline]
PageCompound include/linux/page-flags.h:156 [inline]
page_mapcount include/linux/mm.h:613 [inline]
zap_pte_range mm/memory.c:1340 [inline]
zap_pmd_range mm/memory.c:1443 [inline]
zap_pud_range mm/memory.c:1472 [inline]
zap_p4d_range mm/memory.c:1493 [inline]
unmap_page_range+0xf7d/0x2220 mm/memory.c:1514
unmap_single_vma+0x1a0/0x310 mm/memory.c:1559
unmap_vmas+0x120/0x1f0 mm/memory.c:1589
exit_mmap+0x2c2/0x5b0 mm/mmap.c:3106
__mmput kernel/fork.c:974 [inline]
mmput+0x265/0x620 kernel/fork.c:995
exit_mm kernel/exit.c:544 [inline]
do_exit+0xea9/0x2750 kernel/exit.c:856
do_group_exit+0x177/0x440 kernel/exit.c:972
get_signal+0x88e/0x1970 kernel/signal.c:2467
do_signal+0x9c/0x21c0 arch/x86/kernel/signal.c:816
exit_to_usermode_loop+0x2e0/0x370 arch/x86/entry/common.c:162
prepare_exit_to_usermode arch/x86/entry/common.c:197 [inline]
syscall_return_slowpath arch/x86/entry/common.c:268 [inline]
do_syscall_64+0x6be/0x820 arch/x86/entry/common.c:293
entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x455e29
Code: 38 4c 8b 95 30 fb ff ff 4c 8b 85 20 fb ff ff 49 39 c2 0f 85 b2 f4 ff
ff 44 8b 8d 28 fb ff ff b8 ff ff ff 7f 44 29 c8 48 98 49 <39> c2 0f 86 00
f9 ff ff 48 c7 c0 d0 ff ff ff 64 c7 00 4b 00 00 00
RSP: 002b:00007fc453c22ce8 EFLAGS: 00000246 ORIG_RAX: 00000000000000ca
RAX: fffffffffffffe00 RBX: 000000000072bec0 RCX: 0000000000455e29
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 000000000072bec0
RBP: 000000000072bec0 R08: 0000000000000035 R09: 000000000072bea0
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fff0111086f R14: 00007fc453c239c0 R15: 0000000000000000
netlink: 'syz-executor3': attribute type 10 has an invalid length.
netlink: 'syz-executor3': attribute type 10 has an invalid length.


---
This bug is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#bug-status-tracking for how to communicate with
syzbot.

syzbot

unread,
Dec 15, 2018, 1:43:04 PM12/15/18
to da...@davemloft.net, gre...@linuxfoundation.org, her...@gondor.apana.org.au, linux-...@vger.kernel.org, linux-...@vger.kernel.org, raf...@kernel.org, syzkall...@googlegroups.com
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+9bf843...@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

Eric Biggers

unread,
Dec 15, 2018, 3:41:41 PM12/15/18
to linux-...@vger.kernel.org, Herbert Xu, syzkall...@googlegroups.com, da...@davemloft.net, linux-...@vger.kernel.org
From: Eric Biggers <ebig...@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+9bf843...@syzkaller.appspotmail.com
Fixes: 4af78261870a ("crypto: x86/chacha20 - add XChaCha20 support")
Signed-off-by: Eric Biggers <ebig...@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

Herbert Xu

unread,
Dec 22, 2018, 11:03:20 PM12/22/18
to Eric Biggers, linux-...@vger.kernel.org, syzkall...@googlegroups.com, da...@davemloft.net, linux-...@vger.kernel.org
On Sat, Dec 15, 2018 at 12:40:17PM -0800, Eric Biggers wrote:
> From: Eric Biggers <ebig...@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+9bf843...@syzkaller.appspotmail.com
> Fixes: 4af78261870a ("crypto: x86/chacha20 - add XChaCha20 support")
> Signed-off-by: Eric Biggers <ebig...@google.com>
> ---
> arch/x86/crypto/chacha_glue.c | 33 ++++++++++++++++++++-------------
> 1 file changed, 20 insertions(+), 13 deletions(-)

Patch applied. Thanks.
--
Email: Herbert Xu <her...@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Reply all
Reply to author
Forward
0 new messages