linux/drivers/usb/core
Ruihan Li 0143d148d1 usb: usbfs: Enforce page requirements for mmap
The current implementation of usbdev_mmap uses usb_alloc_coherent to
allocate memory pages that will later be mapped into the user space.
Meanwhile, usb_alloc_coherent employs three different methods to
allocate memory, as outlined below:
 * If hcd->localmem_pool is non-null, it uses gen_pool_dma_alloc to
   allocate memory;
 * If DMA is not available, it uses kmalloc to allocate memory;
 * Otherwise, it uses dma_alloc_coherent.

However, it should be noted that gen_pool_dma_alloc does not guarantee
that the resulting memory will be page-aligned. Furthermore, trying to
map slab pages (i.e., memory allocated by kmalloc) into the user space
is not resonable and can lead to problems, such as a type confusion bug
when PAGE_TABLE_CHECK=y [1].

To address these issues, this patch introduces hcd_alloc_coherent_pages,
which addresses the above two problems. Specifically,
hcd_alloc_coherent_pages uses gen_pool_dma_alloc_align instead of
gen_pool_dma_alloc to ensure that the memory is page-aligned. To replace
kmalloc, hcd_alloc_coherent_pages directly allocates pages by calling
__get_free_pages.

Reported-by: syzbot+fcf1a817ceb50935ce99@syzkaller.appspotmail.comm
Closes: https://lore.kernel.org/lkml/000000000000258e5e05fae79fc1@google.com/ [1]
Fixes: f7d34b445a ("USB: Add support for usbfs zerocopy.")
Fixes: ff2437befd ("usb: host: Fix excessive alignment restriction for local memory allocations")
Cc: stable@vger.kernel.org
Signed-off-by: Ruihan Li <lrh2000@pku.edu.cn>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/r/20230515130958.32471-2-lrh2000@pku.edu.cn
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-05-29 16:14:28 +01:00
..
buffer.c usb: usbfs: Enforce page requirements for mmap 2023-05-29 16:14:28 +01:00
config.c USB: core: Change configuration warnings to notices 2022-11-03 23:46:00 +09:00
devices.c usb: core: devices: drop redundant buffer overflow checks 2022-04-26 13:57:38 +02:00
devio.c usb: usbfs: Enforce page requirements for mmap 2023-05-29 16:14:28 +01:00
driver.c USB: mark all struct bus_type as const 2023-03-23 13:22:00 +01:00
endpoint.c usb: common: add function to get interval expressed in us unit 2021-03-10 09:37:17 +01:00
file.c driver core: class: remove module * from class_create() 2023-03-17 15:16:33 +01:00
generic.c usb: core: Fix file path that does not exist 2021-12-05 14:24:19 +01:00
hcd-pci.c xhci: disable U3 suspended ports in S4 hibernate poweroff_late stage 2022-11-30 12:10:48 +01:00
hcd.c usb: core: hcd: Fix return value check in usb_hcd_setup_local_mem() 2022-11-29 08:56:09 +01:00
hub.c USB: core: Don't hold device lock while reading the "descriptors" sysfs file 2023-01-31 21:54:35 +01:00
hub.h usb: core: stop USB enumeration if too many retries 2022-11-08 16:50:21 +01:00
Kconfig USB: hub: Add Kconfig option to reduce number of port initialization retries 2020-10-02 11:29:02 +02:00
ledtrig-usbport.c usb: core: ledtrig-usbport: Demote obvious misuse of kerneldoc to standard comment blocks 2020-07-09 16:46:57 +02:00
Makefile usb: misc: Add onboard_usb_hub driver 2022-07-08 14:53:50 +02:00
message.c USB: core: Fix docs warning caused by wireless_status feature 2023-04-06 17:14:14 +02:00
notify.c
of.c drivers: usb: Fix trivial spelling 2020-06-18 10:13:16 +02:00
otg_productlist.h USB: OTG: rename product list of devices 2020-06-19 08:58:55 +02:00
phy.c
phy.h
port.c usb: core: stop USB enumeration if too many retries 2022-11-08 16:50:21 +01:00
quirks.c usb: core: add quirk for Alcor Link AK9563 smartcard reader 2023-02-09 13:23:51 +01:00
sysfs.c USB: core: Add wireless_status sysfs attribute 2023-04-03 13:30:08 +02:00
urb.c kmsan: handle memory sent to/from USB 2022-10-03 14:03:22 -07:00
usb-acpi.c usb: acpi: Switch to use acpi_evaluate_dsm_typed() 2023-03-16 12:15:10 +01:00
usb.c USB: core: Add routines for endpoint checks in old drivers 2023-04-20 11:43:22 +02:00
usb.h Driver core changes for 6.4-rc1 2023-04-27 11:53:57 -07:00