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=1796380163; b=0G8VOjCiaYg+4gk4E37Y3DrR57yhcfRlIn1UesBfMeJ6wmjOn84S3DxrxT3MkWa6QcBa AYExvR+ul9sRMrytUb5XNMEu30alraYq8AcUY3jcbk7JM+bjRHNFROFiaMcc5tx8wDsIf W7cOLF2OzW0GnnB5XSdf99672lyoCcD3EkrHhOR6vDLrIrMY8MZuSwteQ9WX+tBer14Wq WaI36bL3Aj3jYN6Azre8BQ/f88QlDX5xg+YlNwL+ZVaHLdcsoWKNRYFv6OthM7HcMVGTp zec80cGMexaRXmCfV5tYY3wnY/WfgQATCt9lZcSMZM9hUeQ0HzpOAxSt26iQfWAgxCw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380163; 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=UZtFRHTzfIqPi1ace7wh5SeXT2pftWWFAAjwNay7qhw=; b=mZKBmYirSs2T1d/KBC+MZx+876l+LdpkokuBYmNDgG1pJ7TZJfL67VMFwLwJX22F38H9 1C5Sl3WHEjAXUiYM9JMZPj8cqGN/99VXAHBmzxcLaWdZqPGR40EBRDKtkihanG5VklRZi aTd7IS01Zcz8DCsH6BdnIWudNaNvEboYAA4qdXs/DB7lCMy3sfw4g1zwGrsPFk7XPgrSM Ri0D4zHoZrBjpz2qpJzTyG4hbyp/93Y38ZROWzO9SeZ2/0zNbYOGf/UcrqOHi6lwouism g9vNlJTDgIlyS6CbBbVXeiU6r5MUPSoSxyt0MzJihvLq4lpi78IEMvlFJRocmwVH9bw== 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=EfNPON2Q; 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 DE6CF60A2607; Fri, 4 Dec 2026 10:29:23 +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=EfNPON2Q Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5896C1F01814; Fri, 4 Dec 2026 10:29:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380163; bh=UZtFRHTzfIqPi1ace7wh5SeXT2pftWWFAAjwNay7qhw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EfNPON2QG5H40RHfH9OZIQH5c92w7jUTkVGvgDZoOKu4Ni1cL2YMtSuZ/+v397S+q GQX5cAx4ke5qptAtlUHdQbKtNCHF8XJLET+i/FMcg4Re/Qf7ZDUREehkgV0yYWv636 pwDg6bkrZRLj54Be/LhYLhW80ROLjCgCvmq3sh+8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shunbo Shi , Sasha Levin Subject: [PATCH 7.3 154/742] usb: gadget: f_hid: fix report_list entries leak Date: Fri, 4 Dec 2026 19:00:18 +0900 Message-ID: <20261204100639.207345006@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-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 3c6b43d06a6d1..670ae7959bbd7 100644 --- a/drivers/usb/gadget/function/f_hid.c +++ b/drivers/usb/gadget/function/f_hid.c @@ -121,6 +121,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