From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796383407; b=ePJpaZRRqQ0eiB6BOnz+7++/lGGTdbZ+vUPbOIJrjrd3GCVto2YRklYgGtkjJ0OLHJIS 3hRFR5nh3M5qmlktPvTc5zMczMy4n09axwPD7eDnjC+dR9CBEDH8C2KquQ9rlBI5HF/HF Rms8RZ5fmDgrfgZJ1Q+w+0XOOWPFuSBgl1Aw3COsLlSkqZBfIPxdkK+mW4CWmUqBbowbn pEuJ/uU8g1NrfaqqcMuXRcuIdM6SVXnpWd2Ysf6xI2OTAlsjObisUMBtysRLAO9YGJeDB rLdb9sYnxqClkdHwW83gtm0yUtCRUMJLrBU04vNMzLyDtnInWisne50pFKZHSosp6PA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383407; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=gfhtGDwID56SftcJ1C5qIKfAgZ0TnUSodJcGNv7+h3c=; b=WqdLTAFhnGf+SaKHqBmayRt/Yz68T6x2lFWjslKq5AcI7CVy/EkHAxCTKu+/LuzX0E5G npZCHT2lRyBRblHFO5DraJhNYqmOu0XIRLiLLX8ehvRho9Vh2eKJGgJZiejYojW3nhal/ Cqc6NEliH196EJtOoc6EX2aGQKRGTUx8IUOA72vvpgufG9XbzbKrKb3iDVzQTfTm71Y6s f1JzTARpzFtlz7FAnNh8+kZcF23JsO3OyPkrRiQ+VohFmLOvlcdsWEZrPp363mPRMrRgK neoyfrowvqQ9L7GIBkLC+9SkncqQhT39s5c3+Rv5PxXCxH/fIK7YClWwc2mBsQ5fgjA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=fZOAJUJo; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89192606A335; Fri, 4 Dec 2026 11:23:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=fZOAJUJo Received: by smtp.kernel.org (Postfix) with ESMTPSA id F282D1F0092C; Fri, 4 Dec 2026 11:23:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383407; bh=gfhtGDwID56SftcJ1C5qIKfAgZ0TnUSodJcGNv7+h3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fZOAJUJon7lEm8sYgBlpzl3OZ7g1a1KcHy4/F4PhpxdY1usJZFlOgtltkjhMo2QBm EJ1fmxPSZae6H92Cbq7hnjA448qZJjm81UX+JUmdu/abonfBbXDjq3biMmSS5vE1sM hwhq7ZfEqZyAtJ1B2CqMLcvKoTyMrxhgWOpdADk4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shunbo Shi , Sasha Levin Subject: [PATCH 6.12 213/555] usb: gadget: f_hid: fix report_list entries leak Date: Fri, 4 Dec 2026 19:04:16 +0900 Message-ID: <20261204100616.962896421@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shunbo Shi [ Upstream commit 19e8981057fb5947697f99a3c6a3f6ff4a2d85a1 ] Each GADGET_HID_WRITE_GET_REPORT ioctl for a report ID that is not yet in hidg->report_list allocates a report_entry and adds it to the list. hidg_release() frees report_desc and set_report_buf, but never walks report_list, so every accumulated entry leaks on function destroy (e.g. when the HID gadget is unbound and the device is removed). Free the entries in hidg_release(). This is safe without extra locking: at release time the function is unbound (the workqueue is already destroyed and userspace has no way to reach the ioctl). Fixes: a139c98f760e ("USB: gadget: f_hid: Add GET_REPORT via userspace IOCTL") Signed-off-by: Shunbo Shi Link: https://patch.msgid.link/20261117125051.5646-2-shishunbo@cmss.chinamobile.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/gadget/function/f_hid.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c index b5702ccb7b2f2..c48496efc2a30 100644 --- a/drivers/usb/gadget/function/f_hid.c +++ b/drivers/usb/gadget/function/f_hid.c @@ -118,6 +118,12 @@ static inline struct f_hidg *func_to_hidg(struct usb_function *f) static void hidg_release(struct device *dev) { struct f_hidg *hidg = container_of(dev, struct f_hidg, dev); + struct report_entry *entry, *tmp; + + list_for_each_entry_safe(entry, tmp, &hidg->report_list, node) { + list_del(&entry->node); + kfree(entry); + } kfree(hidg->report_desc); kfree(hidg->set_report_buf); -- 2.53.0