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 1A90C5678D7; Wed, 9 Sep 2026 14:36:23 +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=1788964584; cv=none; b=je7va111oDqFOZLyk655sYn44Q6c48KeezcO9qQH9j6QELcqM/2t/v7IKBAYO+jOtoUoGYSj0SHruLuPr3b1Mw84s/NGrZRb+dgIxGmG5tE8BFweuI7nnJ8irsFXzhgqqhK1TgV8PTSvtwZmeC9YTtOGtTXNB76sQX0qWDOszZU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788964584; c=relaxed/simple; bh=MczveIvOV22KOdvCaLjTQ5KctAG85Aq8Fay6wG5kbrw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WVw93hrrWsNBh7/kvGxyok/b0iBLpdtDxzScrUKVHMIp7aqABu3vQlgrfPVAsMM7cplv9yeR8LP0bh2EZb33b9JHDTpyKALeDkRdlX7s0Apd0gVC3stDoiJFQtlHI00CWGIk6S2ghlbFcujWlk2O8Gd7qXRm6TvWLhsiHh0XvMI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=sHYFnf6m; 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="sHYFnf6m" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F0EE1F00A3D; Wed, 9 Sep 2026 14:36:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788964583; bh=Y4eHrbmqTKfRqHjoyUDxFXYjdFDRDBYqJLNIqwBzqb8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=sHYFnf6mk/gjrPfBERNoIlIEdDLBYTMWiJGVYuXZ/uwbC0pNwnGpNu4HZS+r7zrQ3 y6pn9pk4w/ZdIlhrn02ihwXnzMaIxS74LCqFayG7so9MhP6JTwOBcGmD5H8LxlD61X UOf3NcWashIoMYjMayHk2aF4c/Sq0fw1+KBP4An8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Doruk Tan Ozturk , Jiri Kosina , Sasha Levin Subject: [PATCH 6.18 472/583] HID: sony: clean up device list on probe failure Date: Wed, 9 Sep 2026 15:42:37 +0200 Message-ID: <20260909134254.221681569@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260909134237.773280130@linuxfoundation.org> References: <20260909134237.773280130@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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Doruk Tan Ozturk [ Upstream commit 7c65699a3a311198a07659a614fe64d45924839e ] sony_input_configured() adds some controllers to sony_device_list before HID core registers their input devices. input_register_device() can fail after the callback returns successfully. sony_probe() then observes that HID_CLAIMED_INPUT is clear and unwinds, but only stops the HID hardware. The devres-managed sony_sc is freed while its list node remains linked, so the next matching controller traverses freed memory. Initialize the list node and device ID to inactive states. Make list removal idempotent and run the driver-private cleanup on every probe failure path. This also makes a second cleanup safe when sony_input_configured() already unwound a partial initialization before sony_probe() handles the missing input claim. Found by 0sec (https://0sec.ai) using automated source analysis; verified against the HID input registration and probe unwind paths. Fixes: 4f967f6d7374 ("HID: sony: Fix memory issue when connecting device using both Bluetooth and USB") Cc: stable@vger.kernel.org Reported-by: Doruk Tan Ozturk Link: https://lore.kernel.org/linux-input/20260724143925.007D61F00A3A@smtp.kernel.org/ Assisted-by: 0sec:multi-model Signed-off-by: Doruk Tan Ozturk Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-sony.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -1741,11 +1741,10 @@ out: static void sony_remove_dev_list(struct sony_sc *sc) { - if (sc->list_node.next) { - scoped_guard(spinlock_irqsave, &sony_dev_list_lock) { - list_del(&(sc->list_node)); - } - } + guard(spinlock_irqsave)(&sony_dev_list_lock); + + if (!list_empty(&sc->list_node)) + list_del_init(&sc->list_node); } static int sony_get_bt_devaddr(struct sony_sc *sc) @@ -1880,6 +1879,13 @@ static inline void sony_cancel_work_sync } } +static void sony_cleanup(struct sony_sc *sc) +{ + sony_cancel_work_sync(sc); + sony_remove_dev_list(sc); + sony_release_device_id(sc); +} + static int sony_input_configured(struct hid_device *hdev, struct hid_input *hidinput) { @@ -2038,9 +2044,7 @@ static int sony_input_configured(struct err_close: hid_hw_close(hdev); err_stop: - sony_cancel_work_sync(sc); - sony_remove_dev_list(sc); - sony_release_device_id(sc); + sony_cleanup(sc); return ret; } @@ -2066,6 +2070,8 @@ static int sony_probe(struct hid_device } spin_lock_init(&sc->lock); + INIT_LIST_HEAD(&sc->list_node); + sc->device_id = -1; sc->quirks = quirks; hid_set_drvdata(hdev, sc); @@ -2094,6 +2100,7 @@ static int sony_probe(struct hid_device ret = hid_hw_start(hdev, connect_mask); if (ret) { hid_err(hdev, "hw start failed\n"); + sony_cleanup(sc); return ret; } @@ -2145,7 +2152,7 @@ static int sony_probe(struct hid_device err: usb_free_urb(sc->ghl_urb); - + sony_cleanup(sc); hid_hw_stop(hdev); return ret; } @@ -2162,13 +2169,7 @@ static void sony_remove(struct hid_devic } hid_hw_close(hdev); - - sony_cancel_work_sync(sc); - - sony_remove_dev_list(sc); - - sony_release_device_id(sc); - + sony_cleanup(sc); hid_hw_stop(hdev); }