From: Eric-Terminal <ericterminal@gmail.com>
To: marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com
Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org,
Yufan Chen <ericterminal@gmail.com>
Subject: [PATCH v2] Bluetooth: HIDP: cap report descriptor size in HID setup
Date: Sun, 1 Mar 2026 01:26:57 +0800 [thread overview]
Message-ID: <20260228172657.53040-1-ericterminal@gmail.com> (raw)
In-Reply-To: <CABBYNZ+9Z8Yd9mRhgz0N9kSSvLR-6euPf9CRA1Sop_D8zV8wqQ@mail.gmail.com>
From: Yufan Chen <ericterminal@gmail.com>
hidp_setup_hid() duplicates the report descriptor from userspace based on
req->rd_size. Large values can trigger oversized copies.
Do not reject the connection when rd_size exceeds
HID_MAX_DESCRIPTOR_SIZE. Instead, cap rd_size in hidp_setup_hid()
and use the capped value for memdup_user() and session->rd_size.
This keeps compatibility with existing userspace behavior while
bounding memory usage in the HID setup path.
Signed-off-by: Yufan Chen <ericterminal@gmail.com>
---
net/bluetooth/hidp/core.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index 6fe815241..31aeffa39 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -755,13 +755,16 @@ static int hidp_setup_hid(struct hidp_session *session,
const struct hidp_connadd_req *req)
{
struct hid_device *hid;
+ unsigned int rd_size;
int err;
- session->rd_data = memdup_user(req->rd_data, req->rd_size);
+ rd_size = min_t(unsigned int, req->rd_size, HID_MAX_DESCRIPTOR_SIZE);
+
+ session->rd_data = memdup_user(req->rd_data, rd_size);
if (IS_ERR(session->rd_data))
return PTR_ERR(session->rd_data);
- session->rd_size = req->rd_size;
+ session->rd_size = rd_size;
hid = hid_allocate_device();
if (IS_ERR(hid)) {
--
2.47.3
next prev parent reply other threads:[~2026-02-28 17:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-25 1:35 [PATCH] Bluetooth: HIDP: reject oversized report descriptor Eric-Terminal
2026-02-25 4:25 ` bluez.test.bot
2026-02-27 15:04 ` [PATCH] " Luiz Augusto von Dentz
2026-02-28 17:26 ` Eric-Terminal [this message]
2026-02-28 18:06 ` [v2] Bluetooth: HIDP: cap report descriptor size in HID setup bluez.test.bot
2026-03-01 9:19 ` [PATCH v2] " Bastien Nocera
2026-03-11 10:18 ` Benjamin Tissoires
2026-03-22 15:37 ` Eric_Terminal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260228172657.53040-1-ericterminal@gmail.com \
--to=ericterminal@gmail.com \
--cc=johan.hedberg@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox