From: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>
To: syzkaller-bugs@googlegroups.com,
syzbot <syzbot+5f47a8cea6a12b77a876@syzkaller.appspotmail.com>
Cc: gregkh@linuxfoundation.org, jirislaby@kernel.org,
linux-kernel@vger.kernel.org, Marco Elver <elver@google.com>
Subject: Re: [syzbot] BUG: sleeping function called from invalid context in __might_resched
Date: Tue, 16 Nov 2021 08:57:49 +0100 [thread overview]
Message-ID: <10635720.r0gBeNIlcX@localhost.localdomain> (raw)
In-Reply-To: <0000000000003efce905d0b135e6@google.com>
[-- Attachment #1: Type: text/plain, Size: 4978 bytes --]
On Saturday, November 13, 2021 9:13:24 PM CET syzbot wrote:
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: f2e19fd15bd7 Add linux-next specific files for 20211112
> git tree: linux-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=15def132b00000
> kernel config: https://syzkaller.appspot.com/x/.config?x=ba9c83199208e103
> dashboard link: https://syzkaller.appspot.com/bug?
extid=5f47a8cea6a12b77a876
> compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils
for Debian) 2.35.2
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=12bdb2c9b00000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=109194aab00000
>
> IMPORTANT: if you fix the issue, please add the following tag to the
commit:
> Reported-by: syzbot+5f47a8cea6a12b77a876@syzkaller.appspotmail.com
>
> BUG: sleeping function called from invalid context at kernel/printk/
printk.c:2525
> in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 6529, name: syz-
executor925
> preempt_count: 1, expected: 0
> RCU nest depth: 0, expected: 0
> 3 locks held by syz-executor925/6529:
> #0: ffff888018d79098 (&tty->ldisc_sem){++++}-{0:0}, at:
tty_ldisc_ref_wait+0x22/0x80 drivers/tty/tty_ldisc.c:252
> #1: ffff888018d79468 (&tty->flow.lock){....}-{2:2}, at: spin_lock_irq
include/linux/spinlock.h:379 [inline]
> #1: ffff888018d79468 (&tty->flow.lock){....}-{2:2}, at:
n_tty_ioctl_helper+0xb6/0x2d0 drivers/tty/tty_ioctl.c:877
> #2: ffff888018d79098 (&tty->ldisc_sem){++++}-{0:0}, at:
tty_ldisc_ref+0x1d/0x80 drivers/tty/tty_ldisc.c:273
> irq event stamp: 16252
> hardirqs last enabled at (16251): [<ffffffff8952dbc0>]
__raw_spin_unlock_irqrestore include/linux/spinlock_api_smp.h:151 [inline]
> hardirqs last enabled at (16251): [<ffffffff8952dbc0>]
_raw_spin_unlock_irqrestore+0x50/0x70 kernel/locking/spinlock.c:194
> hardirqs last disabled at (16252): [<ffffffff8952d921>] __raw_spin_lock_irq
include/linux/spinlock_api_smp.h:117 [inline]
> hardirqs last disabled at (16252): [<ffffffff8952d921>]
_raw_spin_lock_irq+0x41/0x50 kernel/locking/spinlock.c:170
> softirqs last enabled at (14452): [<ffffffff812bc45c>] fpu_reset_fpregs
arch/x86/kernel/fpu/core.c:601 [inline]
> softirqs last enabled at (14452): [<ffffffff812bc45c>]
fpu_flush_thread+0x23c/0x390 arch/x86/kernel/fpu/core.c:647
> softirqs last disabled at (14450): [<ffffffff812bc3eb>] fpstate_reset arch/
x86/kernel/fpu/core.c:452 [inline]
> softirqs last disabled at (14450): [<ffffffff812bc3eb>]
fpu_flush_thread+0x1cb/0x390 arch/x86/kernel/fpu/core.c:646
> Preemption disabled at:
> [<0000000000000000>] 0x0
> CPU: 0 PID: 6529 Comm: syz-executor925 Not tainted 5.15.0-next-20211112-
syzkaller #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
> Call Trace:
> <TASK>
> __dump_stack lib/dump_stack.c:88 [inline]
> dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
> __might_resched.cold+0x222/0x26b kernel/sched/core.c:9554
> console_lock+0x17/0x80 kernel/printk/printk.c:2525
> do_con_write+0x10f/0x1e40 drivers/tty/vt/vt.c:2908
> con_write+0x21/0x40 drivers/tty/vt/vt.c:3295
> n_hdlc_send_frames+0x24b/0x490 drivers/tty/n_hdlc.c:290
> tty_wakeup+0xe1/0x120 drivers/tty/tty_io.c:534
> __start_tty drivers/tty/tty_io.c:806 [inline]
> __start_tty+0xfb/0x130 drivers/tty/tty_io.c:799
> n_tty_ioctl_helper+0x299/0x2d0 drivers/tty/tty_ioctl.c:880
> n_hdlc_tty_ioctl+0xd2/0x340 drivers/tty/n_hdlc.c:633
> tty_ioctl+0xc69/0x1670 drivers/tty/tty_io.c:2814
> vfs_ioctl fs/ioctl.c:51 [inline]
> __do_sys_ioctl fs/ioctl.c:874 [inline]
> __se_sys_ioctl fs/ioctl.c:860 [inline]
> __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:860
> do_syscall_x64 arch/x86/entry/common.c:50 [inline]
> do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
> entry_SYSCALL_64_after_hwframe+0x44/0xae
> RIP: 0033:0x7f16c8522349
> Code: 28 c3 e8 2a 14 00 00 66 2e 0f 1f 84 00 00 00 00 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
73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48
> RSP: 002b:00007fff6ccb8b98 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
> RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f16c8522349
> RDX: 0000000000000001 RSI: 000000000000540a RDI: 0000000000000005
> RBP: 00007f16c84e61d0 R08: 0000000000000000 R09: 0000000000000000
> R10: 00000000000
I think that thanks to Marco Elver we have a solution for this issue.
However I'd propose a transformation on Marco's solution based on one of the
De Morgan's laws: !(A && B) <=> !A || !B.
I think that this is more readable and comprehensible.
Therefore, if I'm not wrong, Marco's "!preemptible()", that is "if (!
(preempt_count() == 0 && !irqs_disabled())", might be rewritten to an easier
to understand "if (preempt_count() || irqs_disabled())".
Am I wrong? Let's test it...
#syz test:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
--
Fabio M. De Francesco
[-- Attachment #2: vt.c.diff --]
[-- Type: text/x-patch, Size: 402 bytes --]
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 7359c3e80d63..a0c6d29eb2a6 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -2902,7 +2902,7 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
struct vt_notifier_param param;
bool rescan;
- if (in_interrupt())
+ if (preempt_count() || irqs_disabled())
return count;
console_lock();
next prev parent reply other threads:[~2021-11-16 7:58 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-10 10:18 [syzbot] BUG: sleeping function called from invalid context in __might_resched syzbot
2021-11-12 12:22 ` Fabio M. De Francesco
2021-11-12 13:58 ` Marco Elver
2021-11-12 16:05 ` Fabio M. De Francesco
2021-11-12 16:27 ` Marco Elver
2021-11-12 17:15 ` Fabio M. De Francesco
2021-11-13 20:13 ` syzbot
2021-11-16 7:57 ` Fabio M. De Francesco [this message]
2021-11-16 8:09 ` syzbot
2021-11-16 8:53 ` Fabio M. De Francesco
2021-11-16 8:55 ` syzbot
2021-11-16 9:03 ` Fabio M. De Francesco
2021-11-16 9:03 ` syzbot
2021-11-16 9:20 ` syzbot
2021-11-16 9:13 ` Fabio M. De Francesco
2021-11-16 9:38 ` syzbot
2021-11-16 10:24 ` Marco Elver
2021-11-16 11:35 ` Fabio M. De Francesco
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=10635720.r0gBeNIlcX@localhost.localdomain \
--to=fmdefrancesco@gmail.com \
--cc=elver@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=syzbot+5f47a8cea6a12b77a876@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.