* [PATCH] slip: Fix use-after-free Read in slip_open
@ 2019-11-25 12:23 jouni.hogander
2019-11-25 12:28 ` Jouni Högander
2019-11-25 19:03 ` David Miller
0 siblings, 2 replies; 4+ messages in thread
From: jouni.hogander @ 2019-11-25 12:23 UTC (permalink / raw)
To: netdev; +Cc: Jouni Hogander, David Miller, Oliver Hartkopp, Lukas Bulwahn
From: Jouni Hogander <jouni.hogander@unikie.com>
Slip_open doesn't clean-up device which registration failed from the
slip_devs device list. On next open after failure this list is iterated
and freed device is accessed. Fix this by calling sl_free_netdev in error
path.
Here is the trace from the Syzbot:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0x197/0x210 lib/dump_stack.c:118
print_address_description.constprop.0.cold+0xd4/0x30b mm/kasan/report.c:374
__kasan_report.cold+0x1b/0x41 mm/kasan/report.c:506
kasan_report+0x12/0x20 mm/kasan/common.c:634
__asan_report_load8_noabort+0x14/0x20 mm/kasan/generic_report.c:132
sl_sync drivers/net/slip/slip.c:725 [inline]
slip_open+0xecd/0x11b7 drivers/net/slip/slip.c:801
tty_ldisc_open.isra.0+0xa3/0x110 drivers/tty/tty_ldisc.c:469
tty_set_ldisc+0x30e/0x6b0 drivers/tty/tty_ldisc.c:596
tiocsetd drivers/tty/tty_io.c:2334 [inline]
tty_ioctl+0xe8d/0x14f0 drivers/tty/tty_io.c:2594
vfs_ioctl fs/ioctl.c:46 [inline]
file_ioctl fs/ioctl.c:509 [inline]
do_vfs_ioctl+0xdb6/0x13e0 fs/ioctl.c:696
ksys_ioctl+0xab/0xd0 fs/ioctl.c:713
__do_sys_ioctl fs/ioctl.c:720 [inline]
__se_sys_ioctl fs/ioctl.c:718 [inline]
__x64_sys_ioctl+0x73/0xb0 fs/ioctl.c:718
do_syscall_64+0xfa/0x760 arch/x86/entry/common.c:290
entry_SYSCALL_64_after_hwframe+0x49/0xbe
Fixes: 3b5a39979daf ("slip: Fix memory leak in slip_open error path")
Reported-by: syzbot+4d5170758f3762109542@syzkaller.appspotmail.com
Cc: David Miller <davem@davemloft.net>
Cc: Oliver Hartkopp <socketcan@hartkopp.net>
Cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Signed-off-by: Jouni Hogander <jouni.hogander@unikie.com>
---
drivers/net/slip/slip.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/net/slip/slip.c b/drivers/net/slip/slip.c
index 4d479e3c817d..2a91c192659f 100644
--- a/drivers/net/slip/slip.c
+++ b/drivers/net/slip/slip.c
@@ -855,6 +855,7 @@ static int slip_open(struct tty_struct *tty)
sl->tty = NULL;
tty->disc_data = NULL;
clear_bit(SLF_INUSE, &sl->flags);
+ sl_free_netdev(sl->dev);
free_netdev(sl->dev);
err_exit:
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] slip: Fix use-after-free Read in slip_open
2019-11-25 12:23 [PATCH] slip: Fix use-after-free Read in slip_open jouni.hogander
@ 2019-11-25 12:28 ` Jouni Högander
2019-11-27 6:27 ` Lukas Bulwahn
2019-11-25 19:03 ` David Miller
1 sibling, 1 reply; 4+ messages in thread
From: Jouni Högander @ 2019-11-25 12:28 UTC (permalink / raw)
To: netdev; +Cc: David Miller, Oliver Hartkopp, Lukas Bulwahn
jouni.hogander@unikie.com writes:
> From: Jouni Hogander <jouni.hogander@unikie.com>
>
> Slip_open doesn't clean-up device which registration failed from the
> slip_devs device list. On next open after failure this list is iterated
> and freed device is accessed. Fix this by calling sl_free_netdev in error
> path.
>
> Here is the trace from the Syzbot:
>
> __dump_stack lib/dump_stack.c:77 [inline]
> dump_stack+0x197/0x210 lib/dump_stack.c:118
> print_address_description.constprop.0.cold+0xd4/0x30b mm/kasan/report.c:374
> __kasan_report.cold+0x1b/0x41 mm/kasan/report.c:506
> kasan_report+0x12/0x20 mm/kasan/common.c:634
> __asan_report_load8_noabort+0x14/0x20 mm/kasan/generic_report.c:132
> sl_sync drivers/net/slip/slip.c:725 [inline]
> slip_open+0xecd/0x11b7 drivers/net/slip/slip.c:801
> tty_ldisc_open.isra.0+0xa3/0x110 drivers/tty/tty_ldisc.c:469
> tty_set_ldisc+0x30e/0x6b0 drivers/tty/tty_ldisc.c:596
> tiocsetd drivers/tty/tty_io.c:2334 [inline]
> tty_ioctl+0xe8d/0x14f0 drivers/tty/tty_io.c:2594
> vfs_ioctl fs/ioctl.c:46 [inline]
> file_ioctl fs/ioctl.c:509 [inline]
> do_vfs_ioctl+0xdb6/0x13e0 fs/ioctl.c:696
> ksys_ioctl+0xab/0xd0 fs/ioctl.c:713
> __do_sys_ioctl fs/ioctl.c:720 [inline]
> __se_sys_ioctl fs/ioctl.c:718 [inline]
> __x64_sys_ioctl+0x73/0xb0 fs/ioctl.c:718
> do_syscall_64+0xfa/0x760 arch/x86/entry/common.c:290
> entry_SYSCALL_64_after_hwframe+0x49/0xbe
>
> Fixes: 3b5a39979daf ("slip: Fix memory leak in slip_open error path")
> Reported-by: syzbot+4d5170758f3762109542@syzkaller.appspotmail.com
Unfortunately I'm not able to reproduce this by myself. But to my
understanding scenario described above is possible path to this
use-after-free bug.
> Cc: David Miller <davem@davemloft.net>
> Cc: Oliver Hartkopp <socketcan@hartkopp.net>
> Cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>
> Signed-off-by: Jouni Hogander <jouni.hogander@unikie.com>
> ---
> drivers/net/slip/slip.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/net/slip/slip.c b/drivers/net/slip/slip.c
> index 4d479e3c817d..2a91c192659f 100644
> --- a/drivers/net/slip/slip.c
> +++ b/drivers/net/slip/slip.c
> @@ -855,6 +855,7 @@ static int slip_open(struct tty_struct *tty)
> sl->tty = NULL;
> tty->disc_data = NULL;
> clear_bit(SLF_INUSE, &sl->flags);
> + sl_free_netdev(sl->dev);
> free_netdev(sl->dev);
>
> err_exit:
BR,
Jouni Högander
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] slip: Fix use-after-free Read in slip_open
2019-11-25 12:23 [PATCH] slip: Fix use-after-free Read in slip_open jouni.hogander
2019-11-25 12:28 ` Jouni Högander
@ 2019-11-25 19:03 ` David Miller
1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2019-11-25 19:03 UTC (permalink / raw)
To: jouni.hogander; +Cc: netdev, socketcan, lukas.bulwahn
From: jouni.hogander@unikie.com
Date: Mon, 25 Nov 2019 14:23:43 +0200
> From: Jouni Hogander <jouni.hogander@unikie.com>
>
> Slip_open doesn't clean-up device which registration failed from the
> slip_devs device list. On next open after failure this list is iterated
> and freed device is accessed. Fix this by calling sl_free_netdev in error
> path.
>
> Here is the trace from the Syzbot:
...
> Fixes: 3b5a39979daf ("slip: Fix memory leak in slip_open error path")
> Reported-by: syzbot+4d5170758f3762109542@syzkaller.appspotmail.com
> Cc: David Miller <davem@davemloft.net>
> Cc: Oliver Hartkopp <socketcan@hartkopp.net>
> Cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>
> Signed-off-by: Jouni Hogander <jouni.hogander@unikie.com>
Applied and queued up for -stable.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] slip: Fix use-after-free Read in slip_open
2019-11-25 12:28 ` Jouni Högander
@ 2019-11-27 6:27 ` Lukas Bulwahn
0 siblings, 0 replies; 4+ messages in thread
From: Lukas Bulwahn @ 2019-11-27 6:27 UTC (permalink / raw)
To: Jouni Högander; +Cc: netdev, David Miller, Oliver Hartkopp
On Mon, Nov 25, 2019 at 1:28 PM Jouni Högander
<jouni.hogander@unikie.com> wrote:
>
> jouni.hogander@unikie.com writes:
>
> > From: Jouni Hogander <jouni.hogander@unikie.com>
> >
> > Slip_open doesn't clean-up device which registration failed from the
> > slip_devs device list. On next open after failure this list is iterated
> > and freed device is accessed. Fix this by calling sl_free_netdev in error
> > path.
> >
> > Here is the trace from the Syzbot:
> >
> > __dump_stack lib/dump_stack.c:77 [inline]
> > dump_stack+0x197/0x210 lib/dump_stack.c:118
> > print_address_description.constprop.0.cold+0xd4/0x30b mm/kasan/report.c:374
> > __kasan_report.cold+0x1b/0x41 mm/kasan/report.c:506
> > kasan_report+0x12/0x20 mm/kasan/common.c:634
> > __asan_report_load8_noabort+0x14/0x20 mm/kasan/generic_report.c:132
> > sl_sync drivers/net/slip/slip.c:725 [inline]
> > slip_open+0xecd/0x11b7 drivers/net/slip/slip.c:801
> > tty_ldisc_open.isra.0+0xa3/0x110 drivers/tty/tty_ldisc.c:469
> > tty_set_ldisc+0x30e/0x6b0 drivers/tty/tty_ldisc.c:596
> > tiocsetd drivers/tty/tty_io.c:2334 [inline]
> > tty_ioctl+0xe8d/0x14f0 drivers/tty/tty_io.c:2594
> > vfs_ioctl fs/ioctl.c:46 [inline]
> > file_ioctl fs/ioctl.c:509 [inline]
> > do_vfs_ioctl+0xdb6/0x13e0 fs/ioctl.c:696
> > ksys_ioctl+0xab/0xd0 fs/ioctl.c:713
> > __do_sys_ioctl fs/ioctl.c:720 [inline]
> > __se_sys_ioctl fs/ioctl.c:718 [inline]
> > __x64_sys_ioctl+0x73/0xb0 fs/ioctl.c:718
> > do_syscall_64+0xfa/0x760 arch/x86/entry/common.c:290
> > entry_SYSCALL_64_after_hwframe+0x49/0xbe
> >
> > Fixes: 3b5a39979daf ("slip: Fix memory leak in slip_open error path")
> > Reported-by: syzbot+4d5170758f3762109542@syzkaller.appspotmail.com
>
> Unfortunately I'm not able to reproduce this by myself. But to my
> understanding scenario described above is possible path to this
> use-after-free bug.
>
As slcan copies some parts from slip, would this use-after-free bug
also occur with the sclan_open function?
The err_free_chan error path in slcan_open does exactly the same as in
slip, so would we also need to add sl_free_netdev(sl->dev) there,
right?
Jouni, could you submit an additional patch to slcan?
Lukas
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-11-27 6:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-25 12:23 [PATCH] slip: Fix use-after-free Read in slip_open jouni.hogander
2019-11-25 12:28 ` Jouni Högander
2019-11-27 6:27 ` Lukas Bulwahn
2019-11-25 19:03 ` David Miller
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.