2017-12-22 21:20:05

by syzbot

[permalink] [raw]
Subject: WARNING in tty_set_ldisc

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
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..


Attachments:
config.txt (123.42 kB)
raw.log (9.01 kB)
repro.txt (701.00 B)
Download all attachments

2018-04-05 10:50:07

by Tetsuo Handa

[permalink] [raw]
Subject: Re: WARNING in tty_set_ldisc

On 2017/11/05 19:34, Greg KH wrote:
> 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
>

From 023cf07f799d0efd160ec1c1617d5b8902577765 Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <[email protected]>
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 <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Jiri Slaby <[email protected]>
Cc: Dmitry Vyukov <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Alan Cox <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Michal Hocko <[email protected]>
---
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


2018-04-05 13:26:46

by Alan Cox

[permalink] [raw]
Subject: Re: WARNING in tty_set_ldisc

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 <[email protected]>
> Cc: Greg Kroah-Hartman <[email protected]>
> Cc: Jiri Slaby <[email protected]>
> Cc: Dmitry Vyukov <[email protected]>
> Cc: Johannes Weiner <[email protected]>
> Cc: Alan Cox <[email protected]>
> Cc: Christoph Hellwig <[email protected]>
> Cc: Michal Hocko <[email protected]>

Seems reasonable to me

Alan

2018-04-16 12:21:54

by Tetsuo Handa

[permalink] [raw]
Subject: [PATCH] tty: Avoid possible error pointer dereference at tty_ldisc_restore().

Greg and Jiri, are you OK with this patch?

Alan Cox wrote:
> > 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 <[email protected]>
> > Cc: Greg Kroah-Hartman <[email protected]>
> > Cc: Jiri Slaby <[email protected]>
> > Cc: Dmitry Vyukov <[email protected]>
> > Cc: Johannes Weiner <[email protected]>
> > Cc: Alan Cox <[email protected]>
> > Cc: Christoph Hellwig <[email protected]>
> > Cc: Michal Hocko <[email protected]>
>
> Seems reasonable to me
>
> Alan
>

>From 023cf07f799d0efd160ec1c1617d5b8902577765 Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <[email protected]>
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 <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Jiri Slaby <[email protected]>
Cc: Dmitry Vyukov <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Alan Cox <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Michal Hocko <[email protected]>
---
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

2018-04-23 09:00:27

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] tty: Avoid possible error pointer dereference at tty_ldisc_restore().

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

2018-04-25 11:09:28

by Tetsuo Handa

[permalink] [raw]
Subject: Re: [PATCH] tty: Avoid possible error pointer dereference at tty_ldisc_restore().

OK. Patch is in tty.git#tty-linus as 598c2d41ff44889d.

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


2017-11-06 12:13:54

by Dmitry Vyukov

[permalink] [raw]
Subject: Re: WARNING in tty_set_ldisc

On Sun, Nov 5, 2017 at 11:34 AM, Greg KH <[email protected]> wrote:
> 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?

FTR, answered here:
https://groups.google.com/d/msg/syzkaller-bugs/XxrI4Vje8gA/8pF9WDgoAwAJ

From 1583221931985174263@xxx Sun Nov 05 10:34:53 +0000 2017
X-GM-THRID: 1583221931985174263
X-Gmail-Labels: Inbox,Category Promotions,HistoricalUnread

2017-11-05 10:34:53

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: WARNING in tty_set_ldisc

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

From 1583239409714175899@xxx Sun Nov 05 15:12:41 +0000 2017
X-GM-THRID: 1583056957567251846
X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread