From nobody Mon Jun 8 22:51:24 2026 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4C4A36D4F3 for ; Tue, 26 May 2026 07:06:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779779203; cv=none; b=qdeWS2t08JxyVydgfTnWMJyWdK/+obqGvW+TS21nroXxD76z9hC4MUIrmmFfKq55Y1ofbdcDQMnAO3wqBy9lq7EW8RfTTwZbPubduoMXXwGqkqc9XZYCNw7XuB7snL+Wo8P8PHHL1EbaQkKWg2yTIFoerNOjaClLLUzYn2tZmFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779779203; c=relaxed/simple; bh=JDU+r+4eAFHPbUpIU0DFrV5eLnEjfElHbf2/4HA8k0Q=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=NCVIfpgl2imkfPvZdGQVg8ZrqiyHcK81jlC177Go5Tc8u2etskdREC3KR+sfXXMDTb40aVAXPjsq7Nf3stLFWGm4oNgI856VU1nrLMtNzPfKeoERG6F5pxcLTpfJlZJJJk3kXKnEU1U4aESBzg28aVI6eP8KtFfL99mDo4febgQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--hhhuuu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CDPmq9uW; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--hhhuuu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CDPmq9uW" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-8386367b23cso7142699b3a.3 for ; Tue, 26 May 2026 00:06:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779779200; x=1780384000; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=DmSH083zLCvpnjRw/E18mHYgSCn8sHqasuCuNLVFOPM=; b=CDPmq9uW3U2EawacsSfQUsmJNtCYNwTdzQC5unwVYfZX02ceHDkv/XdVavnZxa7grV TFjw7lwN6w+QyQyXQBTSqUEjAfb2PGXkaGb7uJckc2s3lPQplP/2WzgRjxvC69BEvAe5 qPnEAbagwtRwZFZtjACzNDCngZMjglFOCJFIAPBXVjoOkSadjytzyyzfwRfBj6ZxgzUd J3s39/wZUXDxGMRg1vyOL+htXjxhIsgAf9iS9VcfSfOxDQcYDqeWdgHUJVQkhtTyVJZz FIas6+JX5MfwvLsPX7SyfqaMdVJVQTZD8vOOxFwKgdgN1LCFkUtJFt8qI2YXWpzfSuJS 0giw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779779200; x=1780384000; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=DmSH083zLCvpnjRw/E18mHYgSCn8sHqasuCuNLVFOPM=; b=NS6SYfeeBLKiWmJJv0pqwUzLLGztCZZmCpgDN20epLiHDTL5FQpXhh8Gm5Lq80LJzg ajXDQVfQ/cc6Jl0yn4n/0GIS6B+n+W/5RCbacN17TLLnoTn2eYd+hyQqylewQ676OAXp tJeExCOyQ5wcHdQLs8y6EV2RYrAEk4VwYGcLR24r1l70w9X1MMjDxMakjqAN1i2D82lS ebxnB65UTmmCLLvD8/J2gyiR01BekyKentN4ZkYio7GbF6qm9eYHZ/1Hc2CfeQ4AtLOR bNLayJsxCKLUpRMzY8VVmv4HxzCqJZW06zwKrxHS2Nt5mrPgDXnWcz9iOYSWd57QCnUM TWWA== X-Forwarded-Encrypted: i=1; AFNElJ8Qsmi6RNp2ZODjUDP5dOFMIXpIFITd545Y/TO3ICZisJ8Yb7+GI83LebV3zNjEoMGhHM/Mh0HEEayNato=@vger.kernel.org X-Gm-Message-State: AOJu0YxT9Aj5qPCi8T5nAhPEN3+bCfbIVwEXvpQj1WNVCX/jMRKra5xw nK+tXpQq9UicPWLFqzDzGnBFaafoddVRX3Sr8nhbBAmla8JzPcjoozr+83q3FmPB0dk/AX3kOFG KHfQvEw== X-Received: from pfny9.prod.google.com ([2002:aa7:8549:0:b0:838:f05:69ac]) (user=hhhuuu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3a08:b0:82f:2226:5aeb with SMTP id d2e1a72fcca58-8415f426d0bmr15966910b3a.20.1779779200135; Tue, 26 May 2026 00:06:40 -0700 (PDT) Date: Tue, 26 May 2026 15:06:35 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.54.0.746.g67dd491aae-goog Message-ID: <20260526070635.839701-1-hhhuuu@google.com> Subject: [PATCH] usb: gadget: udc: Fix NULL pointer dereference in gadget_match_driver From: Jimmy Hu To: Greg Kroah-Hartman Cc: Alan Stern , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Jimmy Hu , stable@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A NULL pointer dereference occurs in gadget_match_driver() because a race condition exists between the DRD mode-switch work and the configfs UDC write path: 1. The DRD mode-switch work invokes __dwc3_set_mode(), which calls dwc3_gadget_exit() and subsequently frees the UDC device name via device_unregister(&udc->dev). 2. The configfs UDC write path invokes gadget_dev_desc_UDC_store(), which calls usb_gadget_register_driver() and subsequently compares the UDC device name via gadget_match_driver(). If gadget_match_driver() runs concurrently during UDC unregistration, it may access the freed UDC device name. Once the freed memory is zeroed, dev_name(&udc->dev) returns NULL, causing a panic in strcmp(). [39430.908615][ T1171] Unable to handle kernel NULL pointer dereference at = virtual address 0000000000000000 [39430.911397][ T1171] pc : __pi_strcmp+0x20/0x140 [39430.911441][ T1171] lr : gadget_match_driver+0x34/0x60 ... [39430.911890][ T1171] usb_gadget_register_driver_owner+0x50/0xf8 [39430.911910][ T1171] gadget_dev_desc_UDC_store+0xf4/0x140 [39430.931308][ T1171] configfs_write_iter+0xec/0x134 ... [39430.957058][ T1171] Workqueue: events_freezable __dwc3_set_mode [39430.957287][ T1171] dwc3_gadget_exit+0x34/0x8c [39430.957304][ T1171] __dwc3_set_mode+0xc0/0x664 [39430.957341][ T1171] worker_thread+0x244/0x334 Fix this by checking dev_name(&udc->dev) before calling strcmp(). Fixes: fc274c1e9973 ("USB: gadget: Add a new bus for gadgets") Cc: stable@vger.kernel.org Signed-off-by: Jimmy Hu --- drivers/usb/gadget/udc/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c index e8861eaad907..79baed640428 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -1594,7 +1594,7 @@ static int gadget_match_driver(struct device *dev, co= nst struct device_driver *d struct usb_gadget_driver, driver); =20 /* If the driver specifies a udc_name, it must match the UDC's name */ - if (driver->udc_name && + if (driver->udc_name && dev_name(&udc->dev) && strcmp(driver->udc_name, dev_name(&udc->dev)) !=3D 0) return 0; =20 base-commit: 5d6919055dec134de3c40167a490f33c74c12581 --=20 2.54.0.746.g67dd491aae-goog