From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E5FF22A7F6; Sat, 12 Sep 2026 13:53:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789221193; cv=none; b=R7BBFABGNG3KCDzDVALvmcO75huIk2MLWWLj5O9WlX0fNCAtBtPLFWyjbfTX3uWPlSKX3UZC2EvZBnqv6WTd2k2qv94QeJpimoLHhT+JXshfDC98COfEjpP8tIEmc/vl4FtdCuwXlwjOW/elY8UaLyW9NS7shvPU8f/CWWBL10E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789221193; c=relaxed/simple; bh=g1iO78nz4YuAsRBVwntRFZzhMg3gwg6Y+/4zdKqaYnI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DT1Bp3wTXZPaNSsiRQ/E/CEgvvLeRMADM3YFjtxFir0kcS+JhJmGFUym8PHeRsb78ibruAiWGQr+9qI/kCyoGVKrkvi2Qb2zAoRiZaLwE+z3M6lG/uKFkjEyYihS+UJShLlhtifbc+RBdMc/8RCe9hkbvQQ1FkND8Gu5vQHYQY8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jlN/14V6; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="jlN/14V6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 429141F000FF; Sat, 12 Sep 2026 13:53:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789221192; bh=LqIwdLePGRx29qE/pqb2708DSJGU5zhY9OSZbUL3am0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jlN/14V6G0Jp/npZ1ansAheVbLUcvfrKaqilQVKKzu3DDWAk43FbASNpukfbS22S6 19q3O4DvMtEehGFz8Br23is/lB8+HDFmylpsszt3FPzegtTOCIWcCBg2DgndFE6TPV XP7pABD66eUZRSdhjGu8jGnyqQAzzZqbwtY7WIyU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable , Eulgyu Kim , Jaeyoung Chung , Lovekesh Solanki , Alan Stern Subject: [PATCH 6.6 0332/1424] USB: gadget: fix NULL pointer dereference in gadget_dev_ioctl() Date: Sat, 12 Sep 2026 08:46:04 +0200 Message-ID: <20260912065614.722651839@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065607.279695368@linuxfoundation.org> References: <20260912065607.279695368@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lovekesh Solanki commit dd0eed9e165b1a6292f49e622e3dd0b7d99b106d upstream. 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 Reported-by: Eulgyu Kim Link: https://lore.kernel.org/all/20260824113510.1141236-1-jjy600901@snu.ac.kr/ Reported-by: Jaeyoung Chung Link: https://lore.kernel.org/all/20260824113510.1141236-1-jjy600901@snu.ac.kr/ Signed-off-by: Lovekesh Solanki Reviewed-by: Alan Stern Link: https://patch.msgid.link/20260825171343.459630-1-lovekeshsolanki00@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/legacy/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/usb/gadget/legacy/inode.c +++ b/drivers/usb/gadget/legacy/inode.c @@ -1247,10 +1247,11 @@ out: 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 */