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=1796381842; b=Eg1/Dw5XgljwAFel0iMoO29KCu/SNYEp0FIU53d2FPdsvY9lIQc8XDlZKu5DAQ9wksOQ Px40xL+UdhlsR+wb/cH5yURcK367e/+iZX/ssCE+n+/fwBdjgqOCqUCNUGbhtNzrurTgS oy6DRkEPrdrmQRk4SwxNitAasLhiQTB8Qo9JhbpH/Cr2b4ztCIsqpJsFAPgLqdQUHKTA9 iB1Dea5Ih9R5qgw4yMvykikNrH0QYcMGqPNMJFzXfd1xzJj2499tmbGI1i9SdICTwUBn3 Fr1jDoMikjH7AMw0Ngjdlape19COZggNvJXrbZ0dgQqJarn60V20BKU54Juf5oaL3dA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381842; 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=tUIHYmM0t5tRwoI9EuzeGhYWOeoywAxsH4WmCY5fQaE=; b=vTS8CpVrJbB0gauqFNf7rdPv3I4HkZAaJr45tXm4iclJigH+QAFURtYQFSZ0CM9mucvs +AETSlRbFK9jKzR4rxI41ilE1u5lpg68Ze1AiMYSLFhBEcFS5FeCQxEYbMwtPNyv0Du0a 4W1hQ/N2kvI/vQac48k8lIYiTl3VvcDziiHkWZS1qhswQTa9+VojcPS1usiiL7jApRoR2 YOaPb6b6voQKOGtqdLQ3O0AA7YBfg/cSxLdCQWQRcnELkxK4jp2LSzqTwpWXa5mxUcT3D Gt2dy69Gt2a3hPFj5udfIw7NdYgKBtnSdVpSYPBJtzircw9h/gl+fC7vLCPk7G0TgXA== 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=Itz1Hi9U; 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 2A03E606A336; Fri, 4 Dec 2026 10:57:22 +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=Itz1Hi9U Received: by smtp.kernel.org (Postfix) with ESMTPSA id 938A81F00897; Fri, 4 Dec 2026 10:57:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381842; bh=tUIHYmM0t5tRwoI9EuzeGhYWOeoywAxsH4WmCY5fQaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Itz1Hi9UdGvT2QTs+ldfV+Fu3gF8kPWYfJ6L3Cel6r94+Znv8JDzL5PQJ9O4Rqr6M KNUC2umaTLUlEaj8DmFmAFyjY7hKwD1VI1x8LbGdN9QgFGGxWLFxFCR1C9AcU6UJm8 R3YsQbwaTSu6CLV1kHKz7wKXyOGY2g9mwpNMgJSA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shunbo Shi , Sasha Levin Subject: [PATCH 6.18 198/703] usb: gadget: f_hid: fix report_list entries leak Date: Fri, 4 Dec 2026 19:01:37 +0900 Message-ID: <20261204100633.120681849@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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 4fe9c38dd2cab..a2c705c730ec2 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