From: Markus Elfring <Markus.Elfring@web.de>
To: sashiko-reviews@lists.linux.dev, linux-input@vger.kernel.org,
linux-usb@vger.kernel.org,
Benjamin Tissoires <bentiss@kernel.org>,
Jiri Kosina <jikos@kernel.org>,
Mahad Ibrahim <mahad.ibrahim.dev@gmail.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>,
Woradorn Laodhanadhaworn <woradorn.laon@gmail.com>,
LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] HID: usbhid: Use seq_buf_putc() in three functions
Date: Thu, 25 Jun 2026 18:55:21 +0200 [thread overview]
Message-ID: <393fdf99-e6ac-4cb4-8d82-02c55b9e83a4@web.de> (raw)
In-Reply-To: <20260625093209.34B6B1F000E9@smtp.kernel.org>
>> +++ b/drivers/hid/usbhid/hid-core.c
>> @@ -1412,7 +1412,7 @@ static int usbhid_probe(struct usb_interface *intf, const struct usb_device_id *
>>
>> if (dev->product) {
>> if (dev->manufacturer)
>> - seq_buf_puts(&hid_name, " ");
>> + seq_buf_putc(&hid_name, ' ');
>
> [Severity: Medium]
> Does this change introduce a missing null termination bug in usbhid_probe()
> if the manufacturer string is exactly 127 bytes long?
>
> The previous code using seq_buf_puts() requires two bytes of available
> capacity (one for the space, one for the trailing null byte) and safely fails
> if there isn't enough room.
I see a need to reconsider such information in more detail.
> Looking at seq_buf_putc(), it only checks if there is room for one byte.
> If the sequence buffer is exactly 128 bytes long
This is the case as such a technical detail can be determined from the member “name”
of the data structure “hid_device”.
https://elixir.bootlin.com/linux/v7.1.1/source/include/linux/hid.h#L721
> and already contains 127
> characters from dev->manufacturer plus the null terminator, seq_buf_putc()
> will overwrite the null terminator at index 127 with a space character.
Other contributors can add further experiences for corresponding data length characteristics.
> This leaves hid->name completely unterminated.
I would like to point the comment “Don't count the trailing null byte against the capacity”
once more from the implementation of the function “seq_buf_puts”.
https://elixir.bootlin.com/linux/v7.1.1/source/lib/seq_buf.c#L193-L194
> When exposed to userspace via
> sysfs or input ioctls, this could lead to an out-of-bounds read into the
> adjacent hid->phys memory field.
If such a data reuse would be attempted, API requirements for sequence buffers
should probably be taken better into account at a concrete place.
Regards,
Markus
prev parent reply other threads:[~2026-06-25 16:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-25 9:22 [PATCH] HID: usbhid: Use seq_buf_putc() in three functions Markus Elfring
2026-06-25 9:32 ` sashiko-bot
2026-06-25 9:55 ` Markus Elfring
2026-06-25 16:55 ` Markus Elfring [this message]
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=393fdf99-e6ac-4cb4-8d82-02c55b9e83a4@web.de \
--to=markus.elfring@web.de \
--cc=bentiss@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=jikos@kernel.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mahad.ibrahim.dev@gmail.com \
--cc=rostedt@goodmis.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=woradorn.laon@gmail.com \
/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