WARNING in tty_set_ldisc

28 views
Skip to first unread message

syzbot

unread,
Nov 5, 2017, 3:45:03 AM11/5/17
to gre...@linuxfoundation.org, jsl...@suse.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzkaller hit the following crash on
9c323bff13f92832e03657cabdd70d731408d621
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/master
compiler: gcc (GCC) 7.1.1 20170620
.config is attached
Raw console output is attached.




RDX: 0000000020230ffc RSI: 0000000000000000 RDI: 0000000000000000
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
------------[ cut here ]------------
WARNING: CPU: 0 PID: 18069 at drivers/tty/tty_ldisc.c:530 tty_ldisc_restore
drivers/tty/tty_ldisc.c:530 [inline]
WARNING: CPU: 0 PID: 18069 at drivers/tty/tty_ldisc.c:530
tty_set_ldisc+0x4c6/0x7a0 drivers/tty/tty_ldisc.c:598
Kernel panic - not syncing: panic_on_warn set ...

CPU: 0 PID: 18069 Comm: syz-executor1 Not tainted 4.14.0-rc5+ #51
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:16 [inline]
dump_stack+0x194/0x257 lib/dump_stack.c:52
panic+0x1e4/0x417 kernel/panic.c:181
__warn+0x1c4/0x1d9 kernel/panic.c:542
report_bug+0x211/0x2d0 lib/bug.c:183
fixup_bug+0x40/0x90 arch/x86/kernel/traps.c:178
do_trap_no_signal arch/x86/kernel/traps.c:212 [inline]
do_trap+0x260/0x390 arch/x86/kernel/traps.c:261
do_error_trap+0x120/0x390 arch/x86/kernel/traps.c:298
do_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:311
invalid_op+0x18/0x20 arch/x86/entry/entry_64.S:905
RIP: 0010:tty_ldisc_restore drivers/tty/tty_ldisc.c:530 [inline]
RIP: 0010:tty_set_ldisc+0x4c6/0x7a0 drivers/tty/tty_ldisc.c:598
RSP: 0018:ffff8801d0b17908 EFLAGS: 00010246
RAX: 0000000000010000 RBX: ffff8801cd8f0a80 RCX: ffffc90003981000
RDX: 0000000000010000 RSI: ffffffff8272a5b6 RDI: 0000000000000282
RBP: ffff8801d0b17958 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: 00000000ffffffff
R13: ffff8801cd8f0ff0 R14: ffff8801d6051ec0 R15: fffffffffffffff4
tiocsetd drivers/tty/tty_io.c:2318 [inline]
tty_ioctl+0x48a/0x15f0 drivers/tty/tty_io.c:2562
vfs_ioctl fs/ioctl.c:45 [inline]
do_vfs_ioctl+0x1b1/0x1520 fs/ioctl.c:685
C_SYSC_ioctl fs/compat_ioctl.c:1615 [inline]
compat_SyS_ioctl+0x5d2/0x3290 fs/compat_ioctl.c:1540
do_syscall_32_irqs_on arch/x86/entry/common.c:329 [inline]
do_fast_syscall_32+0x3f2/0xf05 arch/x86/entry/common.c:391
entry_SYSENTER_compat+0x51/0x60 arch/x86/entry/entry_64_compat.S:124
RIP: 0023:0xf7f54c79
RSP: 002b:00000000f775001c EFLAGS: 00000296 ORIG_RAX: 0000000000000036
RAX: ffffffffffffffda RBX: 0000000000000013 RCX: 0000000000005423
RDX: 0000000020230ffc RSI: 0000000000000000 RDI: 0000000000000000
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
Dumping ftrace buffer:
(ftrace buffer empty)
Kernel Offset: disabled
Rebooting in 86400 seconds..


---
This bug is generated by a dumb bot. It may contain errors.
See https://goo.gl/tpsmEJ for details.
Direct all questions to syzk...@googlegroups.com.
Please credit me with: Reported-by: syzbot <syzk...@googlegroups.com>

syzbot will keep track of this bug report.
Once a fix for this bug is committed, please reply to this email with:
#syz fix: exact-commit-title
To mark this as a duplicate of another syzbot report, please reply with:
#syz dup: exact-subject-of-another-report
If it's a one-off invalid bug report, please reply with:
#syz invalid
Note: if the crash happens again, it will cause creation of a new bug
report.
Note: all commands must start from beginning of the line.
config.txt
raw.log

Greg KH

unread,
Nov 5, 2017, 5:33:54 AM11/5/17
to syzbot, jsl...@suse.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Sun, Nov 05, 2017 at 01:45:01AM -0700, syzbot wrote:
> Hello,
>
> syzkaller hit the following crash on
> 9c323bff13f92832e03657cabdd70d731408d621
> git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/master
> compiler: gcc (GCC) 7.1.1 20170620
> .config is attached
> Raw console output is attached.

Again, what am I supposed to do with this?

thanks,

greg k-h

Dmitry Vyukov

unread,
Nov 6, 2017, 7:12:48 AM11/6/17
to Greg KH, syzbot, Jiri Slaby, LKML, syzkall...@googlegroups.com

syzbot

unread,
Dec 22, 2017, 4:20:02 PM12/22/17
to dvy...@google.com, gre...@linuxfoundation.org, jsl...@suse.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
syzkaller has found reproducer for the following crash on
ead68f216110170ec729e2c4dec0aad6d38259d7
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/master
compiler: gcc (GCC) 7.1.1 20170620
.config is attached
Raw console output is attached.

syzkaller reproducer is attached. See https://goo.gl/kgGztJ
for information about syzkaller reproducers


R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
WARNING: CPU: 1 PID: 3154 at drivers/tty/tty_ldisc.c:531 tty_ldisc_restore
drivers/tty/tty_ldisc.c:531 [inline]
WARNING: CPU: 1 PID: 3154 at drivers/tty/tty_ldisc.c:531
tty_set_ldisc+0x4c6/0x7a0 drivers/tty/tty_ldisc.c:599
Kernel panic - not syncing: panic_on_warn set ...

CPU: 1 PID: 3154 Comm: syz-executor0 Not tainted 4.15.0-rc4+ #144
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:17 [inline]
dump_stack+0x194/0x257 lib/dump_stack.c:53
panic+0x1e4/0x41c kernel/panic.c:183
__warn+0x1dc/0x200 kernel/panic.c:547
report_bug+0x211/0x2d0 lib/bug.c:184
fixup_bug.part.11+0x37/0x80 arch/x86/kernel/traps.c:177
fixup_bug arch/x86/kernel/traps.c:246 [inline]
do_error_trap+0x2d7/0x3e0 arch/x86/kernel/traps.c:295
do_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:314
invalid_op+0x22/0x40 arch/x86/entry/entry_64.S:1061
RIP: 0010:tty_ldisc_restore drivers/tty/tty_ldisc.c:531 [inline]
RIP: 0010:tty_set_ldisc+0x4c6/0x7a0 drivers/tty/tty_ldisc.c:599
RSP: 0018:ffff8801c85af970 EFLAGS: 00010293
RAX: ffff8801c849a4c0 RBX: ffff8801c851d480 RCX: ffffffff8287e3d6
RDX: 0000000000000000 RSI: 1ffff100390935b0 RDI: 0000000000000282
RBP: ffff8801c85af9c0 R08: 1ffff100390b5eee R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: 00000000ffffffff
R13: ffff8801c851d9f0 R14: ffff8801ca162780 R15: fffffffffffffff4
tiocsetd drivers/tty/tty_io.c:2319 [inline]
tty_ioctl+0x492/0x1610 drivers/tty/tty_io.c:2563
vfs_ioctl fs/ioctl.c:46 [inline]
do_vfs_ioctl+0x1b1/0x1520 fs/ioctl.c:686
C_SYSC_ioctl fs/compat_ioctl.c:1495 [inline]
compat_SyS_ioctl+0x4ef/0x2a30 fs/compat_ioctl.c:1419
do_syscall_32_irqs_on arch/x86/entry/common.c:327 [inline]
do_fast_syscall_32+0x3ee/0xf9d arch/x86/entry/common.c:389
entry_SYSENTER_compat+0x54/0x63 arch/x86/entry/entry_64_compat.S:125
RIP: 0023:0xf7fa6c79
RSP: 002b:000000000844f86c EFLAGS: 00000216 ORIG_RAX: 0000000000000036
RAX: ffffffffffffffda RBX: 0000000000000004 RCX: 0000000000005423
RDX: 0000000020fdd000 RSI: 0000000000000000 RDI: 0000000000000000
config.txt
raw.log
repro.txt

Tetsuo Handa

unread,
Apr 5, 2018, 6:46:49 AM4/5/18
to Greg KH, jsl...@suse.com, syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com, Dmitry Vyukov, Johannes Weiner, Alan Cox, Christoph Hellwig, Michal Hocko
From 023cf07f799d0efd160ec1c1617d5b8902577765 Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <penguin...@I-love.SAKURA.ne.jp>
Date: Thu, 5 Apr 2018 11:27:06 +0900
Subject: [PATCH] tty: Avoid possible error pointer dereference at tty_ldisc_restore().

syzbot is reporting crashes [1] triggered by memory allocation failure at
tty_ldisc_get() from tty_ldisc_restore(). While syzbot stops at WARN_ON()
due to panic_on_warn == true, panic_on_warn == false will after all trigger
an OOPS by dereferencing old->ops->num if IS_ERR(old) == true.

We can simplify tty_ldisc_restore() as three calls (old->ops->num, N_TTY,
N_NULL) to tty_ldisc_failto() in addition to avoiding possible error
pointer dereference.

If someone reports kernel panic triggered by forcing all memory allocations
for tty_ldisc_restore() to fail, we can consider adding __GFP_NOFAIL for
tty_ldisc_restore() case.

[1] https://syzkaller.appspot.com/bug?id=6ac359c61e71d22e06db7f8f88243feb11d927e7

Signed-off-by: Tetsuo Handa <penguin...@I-love.SAKURA.ne.jp>
Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Cc: Jiri Slaby <jsl...@suse.com>
Cc: Dmitry Vyukov <dvy...@google.com>
Cc: Johannes Weiner <han...@cmpxchg.org>
Cc: Alan Cox <al...@llwyncelyn.cymru>
Cc: Christoph Hellwig <h...@lst.de>
Cc: Michal Hocko <mho...@suse.com>
---
drivers/tty/tty_ldisc.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index 08ddb2c..de007e1 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -527,19 +527,16 @@ static int tty_ldisc_failto(struct tty_struct *tty, int ld)
static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old)
{
/* There is an outstanding reference here so this is safe */
- old = tty_ldisc_get(tty, old->ops->num);
- WARN_ON(IS_ERR(old));
- tty->ldisc = old;
- tty_set_termios_ldisc(tty, old->ops->num);
- if (tty_ldisc_open(tty, old) < 0) {
- tty_ldisc_put(old);
+ if (tty_ldisc_failto(tty, old->ops->num) < 0) {
+ const char *name = tty_name(tty);
+
+ pr_warn("Falling back ldisc for %s.\n", name);
/* The traditional behaviour is to fall back to N_TTY, we
want to avoid falling back to N_NULL unless we have no
choice to avoid the risk of breaking anything */
if (tty_ldisc_failto(tty, N_TTY) < 0 &&
tty_ldisc_failto(tty, N_NULL) < 0)
- panic("Couldn't open N_NULL ldisc for %s.",
- tty_name(tty));
+ panic("Couldn't open N_NULL ldisc for %s.", name);
}
}

--
1.8.3.1

Alan Cox

unread,
Apr 5, 2018, 9:25:08 AM4/5/18
to Tetsuo Handa, Greg KH, jsl...@suse.com, syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com, Dmitry Vyukov, Johannes Weiner, Christoph Hellwig, Michal Hocko
rror pointer dereference at tty_ldisc_restore().
>
> syzbot is reporting crashes [1] triggered by memory allocation failure at
> tty_ldisc_get() from tty_ldisc_restore(). While syzbot stops at WARN_ON()
> due to panic_on_warn == true, panic_on_warn == false will after all trigger
> an OOPS by dereferencing old->ops->num if IS_ERR(old) == true.
>
> We can simplify tty_ldisc_restore() as three calls (old->ops->num, N_TTY,
> N_NULL) to tty_ldisc_failto() in addition to avoiding possible error
> pointer dereference.
>
> If someone reports kernel panic triggered by forcing all memory allocations
> for tty_ldisc_restore() to fail, we can consider adding __GFP_NOFAIL for
> tty_ldisc_restore() case.
>
> [1] https://syzkaller.appspot.com/bug?id=6ac359c61e71d22e06db7f8f88243feb11d927e7
>
> Signed-off-by: Tetsuo Handa <penguin...@I-love.SAKURA.ne.jp>
> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
> Cc: Jiri Slaby <jsl...@suse.com>
> Cc: Dmitry Vyukov <dvy...@google.com>
> Cc: Johannes Weiner <han...@cmpxchg.org>
> Cc: Alan Cox <al...@llwyncelyn.cymru>
> Cc: Christoph Hellwig <h...@lst.de>
> Cc: Michal Hocko <mho...@suse.com>

Seems reasonable to me

Alan

Tetsuo Handa

unread,
Apr 16, 2018, 7:06:42 AM4/16/18
to gre...@linuxfoundation.org, jsl...@suse.com, al...@llwyncelyn.cymru, bot+1a77aeddeaf6331794...@syzkaller.appspotmail.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com, dvy...@google.com, han...@cmpxchg.org, h...@lst.de, mho...@suse.com
Greg and Jiri, are you OK with this patch?
>From 023cf07f799d0efd160ec1c1617d5b8902577765 Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <penguin...@I-love.SAKURA.ne.jp>
Date: Thu, 5 Apr 2018 11:27:06 +0900
Subject: [PATCH] tty: Avoid possible error pointer dereference at tty_ldisc_restore().

Greg KH

unread,
Apr 23, 2018, 4:59:03 AM4/23/18
to Tetsuo Handa, jsl...@suse.com, al...@llwyncelyn.cymru, bot+1a77aeddeaf6331794...@syzkaller.appspotmail.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com, dvy...@google.com, han...@cmpxchg.org, h...@lst.de, mho...@suse.com
On Mon, Apr 16, 2018 at 08:06:34PM +0900, Tetsuo Handa wrote:
> Greg and Jiri, are you OK with this patch?

Yes, I'll queue it up now, thanks.

greg k-h

Tetsuo Handa

unread,
Apr 25, 2018, 7:08:12 AM4/25/18
to bot+1a77aeddeaf6331794...@syzkaller.appspotmail.com, syzkall...@googlegroups.com, Greg KH, jsl...@suse.com, al...@llwyncelyn.cymru, linux-...@vger.kernel.org, dvy...@google.com, han...@cmpxchg.org, h...@lst.de, mho...@suse.com
OK. Patch is in tty.git#tty-linus as 598c2d41ff44889d.

#syz fix: tty: Avoid possible error pointer dereference at tty_ldisc_restore().

Reply all
Reply to author
Forward
0 new messages