linux/drivers/char/xillybus
Ziyang Xuan 15c9a35909 char: xillybus: fix msg_ep UAF in xillyusb_probe()
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: a53d1202ae ("char: xillybus: Add driver for XillyUSB (Xillybus variant for USB)")
Cc: stable <stable@vger.kernel.org>
Acked-by: Eli Billauer <eli.billauer@gmail.com>
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
Link: https://lore.kernel.org/r/20211016052047.1611983-1-william.xuanziyang@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-10-19 09:40:18 +02:00
..
Kconfig char: xillybus: Add driver for XillyUSB (Xillybus variant for USB) 2021-05-27 14:07:41 +02:00
Makefile char: xillybus: Add driver for XillyUSB (Xillybus variant for USB) 2021-05-27 14:07:41 +02:00
xillybus_class.c char: xillybus: Remove unneeded MODULE_VERSION() usage 2021-06-03 14:10:03 +02:00
xillybus_class.h char: xillybus: Move class-related functions to new xillybus_class.c 2021-05-27 14:07:41 +02:00
xillybus_core.c char: xillybus: Eliminate redundant wrappers to DMA related calls 2021-10-05 16:11:11 +02:00
xillybus_of.c char: xillybus: Eliminate redundant wrappers to DMA related calls 2021-10-05 16:11:11 +02:00
xillybus_pcie.c char: xillybus: Eliminate redundant wrappers to DMA related calls 2021-10-05 16:11:11 +02:00
xillybus.h char: xillybus: Eliminate redundant wrappers to DMA related calls 2021-10-05 16:11:11 +02:00
xillyusb.c char: xillybus: fix msg_ep UAF in xillyusb_probe() 2021-10-19 09:40:18 +02:00