All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] char: xillybus: fix msg_ep UAF in xillyusb_probe()
@ 2021-10-16  5:20 Ziyang Xuan
  2021-10-16 15:43 ` Eli Billauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ziyang Xuan @ 2021-10-16  5:20 UTC (permalink / raw)
  To: eli.billauer; +Cc: arnd, gregkh, linux-kernel

When endpoint_alloc() return failed in xillyusb_setup_base_eps(),
'xdev->msg_ep' will be freed but not set to NULL. That lets program
enter fail handling to cleanup_dev() in xillyusb_probe(). Check for
'xdev->msg_ep' is invalid in cleanup_dev() because 'xdev->msg_ep' did
not set to NULL when was freed. So the UAF problem for 'xdev->msg_ep'
is triggered.

==================================================================
BUG: KASAN: use-after-free in fifo_mem_release+0x1f4/0x210
CPU: 0 PID: 166 Comm: kworker/0:2 Not tainted 5.15.0-rc5+ #19
Call Trace:
 dump_stack_lvl+0xe2/0x152
 print_address_description.constprop.0+0x21/0x140
 ? fifo_mem_release+0x1f4/0x210
 kasan_report.cold+0x7f/0x11b
 ? xillyusb_probe+0x530/0x700
 ? fifo_mem_release+0x1f4/0x210
 fifo_mem_release+0x1f4/0x210
 ? __sanitizer_cov_trace_pc+0x1d/0x50
 endpoint_dealloc+0x35/0x2b0
 cleanup_dev+0x90/0x120
 xillyusb_probe+0x59a/0x700
...

Freed by task 166:
 kasan_save_stack+0x1b/0x40
 kasan_set_track+0x1c/0x30
 kasan_set_free_info+0x20/0x30
 __kasan_slab_free+0x109/0x140
 kfree+0x117/0x4c0
 xillyusb_probe+0x606/0x700

Set 'xdev->msg_ep' to NULL after being freed in xillyusb_setup_base_eps()
to fix the UAF problem.

Fixes: a53d1202aef1 ("char: xillybus: Add driver for XillyUSB (Xillybus variant for USB)")
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
---
 drivers/char/xillybus/xillyusb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xillyusb.c
index e7f88f35c702..dc3551796e5e 100644
--- a/drivers/char/xillybus/xillyusb.c
+++ b/drivers/char/xillybus/xillyusb.c
@@ -1912,6 +1912,7 @@ static int xillyusb_setup_base_eps(struct xillyusb_dev *xdev)
 
 dealloc:
 	endpoint_dealloc(xdev->msg_ep); /* Also frees FIFO mem if allocated */
+	xdev->msg_ep = NULL;
 	return -ENOMEM;
 }
 
-- 
2.25.1


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

* Re: [PATCH] char: xillybus: fix msg_ep UAF in xillyusb_probe()
  2021-10-16  5:20 [PATCH] char: xillybus: fix msg_ep UAF in xillyusb_probe() Ziyang Xuan
@ 2021-10-16 15:43 ` Eli Billauer
  0 siblings, 0 replies; 2+ messages in thread
From: Eli Billauer @ 2021-10-16 15:43 UTC (permalink / raw)
  To: Ziyang Xuan; +Cc: arnd, gregkh, linux-kernel

Correct. Thanks a lot.

Acked-by: Eli Billauer <eli.billauer@gmail.com>

On 16/10/21 08:20, Ziyang Xuan wrote:
> When endpoint_alloc() return failed in xillyusb_setup_base_eps(),
> 'xdev->msg_ep' will be freed but not set to NULL. That lets program
> enter fail handling to cleanup_dev() in xillyusb_probe(). Check for
> 'xdev->msg_ep' is invalid in cleanup_dev() because 'xdev->msg_ep' did
> not set to NULL when was freed. So the UAF problem for 'xdev->msg_ep'
> is triggered.
>
> ==================================================================
> BUG: KASAN: use-after-free in fifo_mem_release+0x1f4/0x210
> CPU: 0 PID: 166 Comm: kworker/0:2 Not tainted 5.15.0-rc5+ #19
> Call Trace:
>   dump_stack_lvl+0xe2/0x152
>   print_address_description.constprop.0+0x21/0x140
>   ? fifo_mem_release+0x1f4/0x210
>   kasan_report.cold+0x7f/0x11b
>   ? xillyusb_probe+0x530/0x700
>   ? fifo_mem_release+0x1f4/0x210
>   fifo_mem_release+0x1f4/0x210
>   ? __sanitizer_cov_trace_pc+0x1d/0x50
>   endpoint_dealloc+0x35/0x2b0
>   cleanup_dev+0x90/0x120
>   xillyusb_probe+0x59a/0x700
> ...
>
> Freed by task 166:
>   kasan_save_stack+0x1b/0x40
>   kasan_set_track+0x1c/0x30
>   kasan_set_free_info+0x20/0x30
>   __kasan_slab_free+0x109/0x140
>   kfree+0x117/0x4c0
>   xillyusb_probe+0x606/0x700
>
> Set 'xdev->msg_ep' to NULL after being freed in xillyusb_setup_base_eps()
> to fix the UAF problem.
>
> Fixes: a53d1202aef1 ("char: xillybus: Add driver for XillyUSB (Xillybus variant for USB)")
> Signed-off-by: Ziyang Xuan<william.xuanziyang@huawei.com>
> ---
>   drivers/char/xillybus/xillyusb.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xillyusb.c
> index e7f88f35c702..dc3551796e5e 100644
> --- a/drivers/char/xillybus/xillyusb.c
> +++ b/drivers/char/xillybus/xillyusb.c
> @@ -1912,6 +1912,7 @@ static int xillyusb_setup_base_eps(struct xillyusb_dev *xdev)
>
>   dealloc:
>   	endpoint_dealloc(xdev->msg_ep); /* Also frees FIFO mem if allocated */
> +	xdev->msg_ep = NULL;
>   	return -ENOMEM;
>   }
>
>    


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

end of thread, other threads:[~2021-10-16 15:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-16  5:20 [PATCH] char: xillybus: fix msg_ep UAF in xillyusb_probe() Ziyang Xuan
2021-10-16 15:43 ` Eli Billauer

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.