kernel_samsung_a53x/drivers/usb/gadget/function
Lianqin Hu 3f649a6812 usb: gadget: u_serial: Fix the issue that gs_start_io crashed due to accessing null pointer
commit 4cfbca86f6a8b801f3254e0e3c8f2b1d2d64be2b upstream.

Considering that in some extreme cases,
when u_serial driver is accessed by multiple threads,
Thread A is executing the open operation and calling the gs_open,
Thread B is executing the disconnect operation and calling the
gserial_disconnect function,The port->port_usb pointer will be set to NULL.

E.g.
    Thread A                                 Thread B
    gs_open()                                gadget_unbind_driver()
    gs_start_io()                            composite_disconnect()
    gs_start_rx()                            gserial_disconnect()
    ...                                      ...
    spin_unlock(&port->port_lock)
    status = usb_ep_queue()                  spin_lock(&port->port_lock)
    spin_lock(&port->port_lock)              port->port_usb = NULL
    gs_free_requests(port->port_usb->in)     spin_unlock(&port->port_lock)
    Crash

This causes thread A to access a null pointer (port->port_usb is null)
when calling the gs_free_requests function, causing a crash.

If port_usb is NULL, the release request will be skipped as it
will be done by gserial_disconnect.

So add a null pointer check to gs_start_io before attempting
to access the value of the pointer port->port_usb.

Call trace:
 gs_start_io+0x164/0x25c
 gs_open+0x108/0x13c
 tty_open+0x314/0x638
 chrdev_open+0x1b8/0x258
 do_dentry_open+0x2c4/0x700
 vfs_open+0x2c/0x3c
 path_openat+0xa64/0xc60
 do_filp_open+0xb8/0x164
 do_sys_openat2+0x84/0xf0
 __arm64_sys_openat+0x70/0x9c
 invoke_syscall+0x58/0x114
 el0_svc_common+0x80/0xe0
 do_el0_svc+0x1c/0x28
 el0_svc+0x38/0x68

Fixes: c1dca562be8a ("usb gadget: split out serial core")
Cc: stable@vger.kernel.org
Suggested-by: Prashanth K <quic_prashk@quicinc.com>
Signed-off-by: Lianqin Hu <hulianqin@vivo.com>
Acked-by: Prashanth K <quic_prashk@quicinc.com>
Link: https://lore.kernel.org/r/TYUPR06MB62178DC3473F9E1A537DCD02D2362@TYUPR06MB6217.apcprd06.prod.outlook.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-01-02 17:00:49 +01:00
..
f_accessory.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_acm.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_audio_source.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_conn_gadget.c Fix clang 16 errors treewide 2024-06-15 16:28:48 -03:00
f_conn_gadget.ioctl.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_dm.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_dm1.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_ecm.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_eem.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_fs.c usb: gadget: f_fs: Fix race between aio_cancel() and AIO request complete 2024-11-19 14:19:01 +01:00
f_hid.c usb: gadget: f_hid: fix report descriptor allocation 2024-11-18 12:11:45 +01:00
f_loopback.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_mass_storage.c usb: f_mass_storage: forbid async queue when shutdown happen 2024-11-18 12:13:29 +01:00
f_mass_storage.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_midi.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_ncm.c usb: gadget: ncm: Fix handling of zero block length packets 2024-11-19 09:22:39 +01:00
f_obex.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_phonet.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_printer.c usb: gadget: printer: fix races against disable 2024-11-19 14:19:33 +01:00
f_rndis.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_serial.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_sourcesink.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_ss_mon_gadget.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_subset.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_tcm.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_uac1.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_uac1_legacy.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_uac2.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_uts.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_uvc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f_uvc.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
g_zero.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Makefile Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ndis.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
rndis.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
rndis.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
storage_common.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
storage_common.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tcm.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_audio.c usb: gadget: u_audio: Clear uac pointer when freed. 2024-11-19 12:27:04 +01:00
u_audio.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_ecm.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_eem.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_ether.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_ether.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_ether_configfs.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_fs.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_gether.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_hid.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_midi.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_ncm.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_phonet.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_printer.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_rndis.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_serial.c usb: gadget: u_serial: Fix the issue that gs_start_io crashed due to accessing null pointer 2025-01-02 17:00:49 +01:00
u_serial.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_tcm.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_uac1.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_uac1_legacy.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_uac1_legacy.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_uac2.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
u_uvc.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
uac_common.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
uvc.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
uvc_configfs.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
uvc_configfs.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
uvc_queue.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
uvc_queue.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
uvc_v4l2.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
uvc_v4l2.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
uvc_video.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
uvc_video.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00