mirror of
https://github.com/torvalds/linux.git
synced 2026-09-12 04:23:03 +02:00
USB: gadget: fix NULL pointer dereference in gadget_dev_ioctl()
gadget_dev_ioctl() reads dev->gadget before acquiring dev->lock, but dev->state is checked after acquiring the lock. Therefore a concurrent bind can change the device state between these operations, which can leave ioctl with a stale NULL gadget pointer and causing a NULL pointer dereference at gadget->ops->ioctl. Read dev->gadget while holding dev->lock so that the gadget pointer and device state are sampled consistently. Cc: stable <stable@kernel.org> Reported-by: Eulgyu Kim <eulgyukim@snu.ac.kr> Link: https://lore.kernel.org/all/20260824113510.1141236-1-jjy600901@snu.ac.kr/ Reported-by: Jaeyoung Chung <jjy600901@snu.ac.kr> Link: https://lore.kernel.org/all/20260824113510.1141236-1-jjy600901@snu.ac.kr/ Signed-off-by: Lovekesh Solanki <lovekeshsolanki00@gmail.com> Reviewed-by: Alan Stern <stern@rowland.harvard.edu> Link: https://patch.msgid.link/20260825171343.459630-1-lovekeshsolanki00@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
7e07d3e4c3
commit
dd0eed9e16
|
|
@ -1260,10 +1260,11 @@ ep0_poll (struct file *fd, poll_table *wait)
|
|||
static long gadget_dev_ioctl (struct file *fd, unsigned code, unsigned long value)
|
||||
{
|
||||
struct dev_data *dev = fd->private_data;
|
||||
struct usb_gadget *gadget = dev->gadget;
|
||||
struct usb_gadget *gadget;
|
||||
long ret = -ENOTTY;
|
||||
|
||||
spin_lock_irq(&dev->lock);
|
||||
gadget = dev->gadget;
|
||||
if (dev->state == STATE_DEV_OPENED ||
|
||||
dev->state == STATE_DEV_UNBOUND) {
|
||||
/* Not bound to a UDC */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user