Stable Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 3/6] can: slcan: Fix use-after-free Read in slcan_open
       [not found] <20191203104703.14620-1-mkl@pengutronix.de>
@ 2019-12-03 10:47 ` Marc Kleine-Budde
  2019-12-03 11:21   ` Oliver Hartkopp
  2019-12-03 10:47 ` [PATCH 4/6] can: ucan: fix non-atomic allocation in completion handler Marc Kleine-Budde
  1 sibling, 1 reply; 4+ messages in thread
From: Marc Kleine-Budde @ 2019-12-03 10:47 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Jouni Hogander, Wolfgang Grandegger,
	Marc Kleine-Budde, Oliver Hartkopp, Lukas Bulwahn, linux-stable

From: Jouni Hogander <jouni.hogander@unikie.com>

Slcan_open doesn't clean-up device which registration failed from the
slcan_devs device list. On next open this list is iterated and freed
device is accessed. Fix this by calling slc_free_netdev in error path.

Driver/net/can/slcan.c is derived from slip.c. Use-after-free error was
identified in slip_open by syzboz. Same bug is in slcan.c. Here is the
trace from the Syzbot slip report:

__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: ed50e1600b44 ("slcan: Fix memory leak in error path")
Cc: Wolfgang Grandegger <wg@grandegger.com>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
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>
Cc: linux-stable <stable@vger.kernel.org> # >= v5.4
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/slcan.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c
index 0a9f42e5fedf..2e57122f02fb 100644
--- a/drivers/net/can/slcan.c
+++ b/drivers/net/can/slcan.c
@@ -617,6 +617,7 @@ static int slcan_open(struct tty_struct *tty)
 	sl->tty = NULL;
 	tty->disc_data = NULL;
 	clear_bit(SLF_INUSE, &sl->flags);
+	slc_free_netdev(sl->dev);
 	free_netdev(sl->dev);
 
 err_exit:
-- 
2.24.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 4/6] can: ucan: fix non-atomic allocation in completion handler
       [not found] <20191203104703.14620-1-mkl@pengutronix.de>
  2019-12-03 10:47 ` [PATCH 3/6] can: slcan: Fix use-after-free Read in slcan_open Marc Kleine-Budde
@ 2019-12-03 10:47 ` Marc Kleine-Budde
  1 sibling, 0 replies; 4+ messages in thread
From: Marc Kleine-Budde @ 2019-12-03 10:47 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Johan Hovold, stable,
	Jakob Unterwurzacher, Martin Elshuber, Philipp Tomsich,
	Marc Kleine-Budde

From: Johan Hovold <johan@kernel.org>

USB completion handlers are called in atomic context and must
specifically not allocate memory using GFP_KERNEL.

Fixes: 9f2d3eae88d2 ("can: ucan: add driver for Theobroma Systems UCAN devices")
Cc: stable <stable@vger.kernel.org>     # 4.19
Cc: Jakob Unterwurzacher <jakob.unterwurzacher@theobroma-systems.com>
Cc: Martin Elshuber <martin.elshuber@theobroma-systems.com>
Cc: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/ucan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/ucan.c b/drivers/net/can/usb/ucan.c
index 04aac3bb54ef..81e942f713e6 100644
--- a/drivers/net/can/usb/ucan.c
+++ b/drivers/net/can/usb/ucan.c
@@ -792,7 +792,7 @@ static void ucan_read_bulk_callback(struct urb *urb)
 			  up);
 
 	usb_anchor_urb(urb, &up->rx_urbs);
-	ret = usb_submit_urb(urb, GFP_KERNEL);
+	ret = usb_submit_urb(urb, GFP_ATOMIC);
 
 	if (ret < 0) {
 		netdev_err(up->netdev,
-- 
2.24.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 3/6] can: slcan: Fix use-after-free Read in slcan_open
  2019-12-03 10:47 ` [PATCH 3/6] can: slcan: Fix use-after-free Read in slcan_open Marc Kleine-Budde
@ 2019-12-03 11:21   ` Oliver Hartkopp
  2019-12-03 11:53     ` Marc Kleine-Budde
  0 siblings, 1 reply; 4+ messages in thread
From: Oliver Hartkopp @ 2019-12-03 11:21 UTC (permalink / raw)
  To: Marc Kleine-Budde, netdev
  Cc: davem, linux-can, kernel, Jouni Hogander, Wolfgang Grandegger,
	Lukas Bulwahn, linux-stable



On 03/12/2019 11.47, Marc Kleine-Budde wrote:
> From: Jouni Hogander <jouni.hogander@unikie.com>
> 
> Slcan_open doesn't clean-up device which registration failed from the
> slcan_devs device list. On next open this list is iterated and freed
> device is accessed. Fix this by calling slc_free_netdev in error path.
> 
> Driver/net/can/slcan.c is derived from slip.c. Use-after-free error was
> identified in slip_open by syzboz. Same bug is in slcan.c. Here is the
> trace from the Syzbot slip report:
> 
> __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: ed50e1600b44 ("slcan: Fix memory leak in error path")
> Cc: Wolfgang Grandegger <wg@grandegger.com>
> Cc: Marc Kleine-Budde <mkl@pengutronix.de>
> 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>
> Cc: linux-stable <stable@vger.kernel.org> # >= v5.4

I think this problem existed from the initial commit in 2010 and is not 
restricted to >= v5.4

Together with commit commit ed50e1600b4483c049 ("slcan: Fix memory leak 
in error path") from Jouni Hogander.

Regards,
Oliver

> Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> ---
>   drivers/net/can/slcan.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c
> index 0a9f42e5fedf..2e57122f02fb 100644
> --- a/drivers/net/can/slcan.c
> +++ b/drivers/net/can/slcan.c
> @@ -617,6 +617,7 @@ static int slcan_open(struct tty_struct *tty)
>   	sl->tty = NULL;
>   	tty->disc_data = NULL;
>   	clear_bit(SLF_INUSE, &sl->flags);
> +	slc_free_netdev(sl->dev);
>   	free_netdev(sl->dev);
>   
>   err_exit:
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 3/6] can: slcan: Fix use-after-free Read in slcan_open
  2019-12-03 11:21   ` Oliver Hartkopp
@ 2019-12-03 11:53     ` Marc Kleine-Budde
  0 siblings, 0 replies; 4+ messages in thread
From: Marc Kleine-Budde @ 2019-12-03 11:53 UTC (permalink / raw)
  To: Oliver Hartkopp, netdev
  Cc: davem, linux-can, kernel, Jouni Hogander, Wolfgang Grandegger,
	Lukas Bulwahn, linux-stable

[-- Attachment #1.1: Type: text/plain, Size: 2739 bytes --]

On 12/3/19 12:21 PM, Oliver Hartkopp wrote:
> 
> 
> On 03/12/2019 11.47, Marc Kleine-Budde wrote:
>> From: Jouni Hogander <jouni.hogander@unikie.com>
>>
>> Slcan_open doesn't clean-up device which registration failed from the
>> slcan_devs device list. On next open this list is iterated and freed
>> device is accessed. Fix this by calling slc_free_netdev in error path.
>>
>> Driver/net/can/slcan.c is derived from slip.c. Use-after-free error was
>> identified in slip_open by syzboz. Same bug is in slcan.c. Here is the
>> trace from the Syzbot slip report:
>>
>> __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: ed50e1600b44 ("slcan: Fix memory leak in error path")
>> Cc: Wolfgang Grandegger <wg@grandegger.com>
>> Cc: Marc Kleine-Budde <mkl@pengutronix.de>
>> 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>
>> Cc: linux-stable <stable@vger.kernel.org> # >= v5.4
> 
> I think this problem existed from the initial commit in 2010 and is not 
> restricted to >= v5.4
> 
> Together with commit commit ed50e1600b4483c049 ("slcan: Fix memory leak 
> in error path") from Jouni Hogander.

Yes, both patches shoud be backported:

ed50e1600b44 slcan: Fix memory leak in error path
9ebd796e2400 can: slcan: Fix use-after-free Read in slcan_open

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20191203104703.14620-1-mkl@pengutronix.de>
2019-12-03 10:47 ` [PATCH 3/6] can: slcan: Fix use-after-free Read in slcan_open Marc Kleine-Budde
2019-12-03 11:21   ` Oliver Hartkopp
2019-12-03 11:53     ` Marc Kleine-Budde
2019-12-03 10:47 ` [PATCH 4/6] can: ucan: fix non-atomic allocation in completion handler Marc Kleine-Budde

Stable Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/stable/0 stable/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 stable stable/ https://lore.kernel.org/stable \
		stable@vger.kernel.org
	public-inbox-index stable

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.stable


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git