From: Juergen Gross <jgross@suse.com>
To: Jiri Kosina <jikos@kernel.org>, Benjamin Tissoires <bentiss@kernel.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
michael.bommarito@gmail.com, longli@microsoft.com,
decui@microsoft.com, wei.liu@kernel.org, haiyangz@microsoft.com,
kys@microsoft.com
Subject: Re: [PATCH v2] HID: hyperv: make pointer arithmetics understandable for FORTIFY_SOURCE
Date: Fri, 21 Aug 2026 15:54:35 +0200 [thread overview]
Message-ID: <f1164c4d-3fa4-4e58-8c5e-20e203b0d8bc@suse.com> (raw)
In-Reply-To: <17q6s829-78pr-nrq1-qrr7-9qo9n750pq63@xreary.bet>
[-- Attachment #1.1.1: Type: text/plain, Size: 2858 bytes --]
On 21.08.26 15:39, Jiri Kosina wrote:
> On Fri, 21 Aug 2026, Benjamin Tissoires wrote:
>
>>> - report = ((u8 *)&info->hid_descriptor) + info->hid_descriptor.bLength;
>>> + report = (u8 *)info + offsetof(struct synthhid_device_info, hid_descriptor) + info->hid_descriptor.bLength;
>>
>> Isn't that overcomplicated?:
>>
>> Above we have:
>> struct synthhid_device_info {
>> struct synthhid_msg_hdr header;
>> struct hv_input_dev_info hid_dev_info;
>> struct hid_descriptor hid_descriptor;
>> };
>> ...
>> struct synthhid_device_info *info;
>> ...
>> info = kunit_kzalloc(test, sizeof(*info) + 4, GFP_KERNEL);
>>
>> so info is 0 allocated with the sizeof(struct synthhid_device_info) plus
>> 4 for the report (immediately after).
>>
>> with the bLength being set a couple of lines above, we basically have:
>> + report = (u8 *)info + offsetof(struct synthhid_device_info, hid_descriptor) + sizeof(struct hid_descriptor);
>>
>> So pointer address + offset of the last field + size of the last field.
>>
>> Isn't that equivalent to:
>> report = (u8 *)info + sizeof(*info);
>>
>> or even: `(u8 *)(info + 1)`?
>
> I considered that one as well, but then I decided to keep what the
> original author intended as perhaps it's more self-explanatory what we're
> actually doing. But the argument that whenever a new field is added after
> hid_descriptor, this will silently break, is convicing enough :)
>
> Thanks. v2 below.
>
> Juergen, could you please re-Ack your Tested-by: on this? For some reason,
> my allyesconfig with gcc-15 doesn't trigger it.
>
>
>
>
> From: Jiri Kosina <jkosina@suse.com>
> Subject: [PATCH] HID: hyperv: make pointer arithmetics understandable for FORTIFY_SOURCE
>
> Commit 83df7b5fa6735b5084ecd2 ("HID: hyperv: add KUnit coverage for device info
> bounds") introduced this piece of code
>
> report = ((u8 *)&info->hid_descriptor) + info->hid_descriptor.bLength;
> memset(report, 0x42, 4);
>
> to populate the report descriptor, making use of the fact that the report
> &info->hid_descriptor points to a struct hid_descriptor (which is a fixed-size struct).
> GCC's FORTIFY_SOURCE infer the object size from that specific struct field rather than the
> outer dynamically allocated info buffer. As a result, writing past sizeof(struct hid_descriptor)
> triggers the __write_overflow_field warning.
>
> Calculate the pointer offset using info directly, so the compiler evaluates the
> memory bounds against the allocated flexible layout of struct
> synthhid_device_info instead of the nested struct.
>
> Fixes: 83df7b5fa6735b5084ecd2 ("HID: hyperv: add KUnit coverage for device info bounds")
> Reported-by: Jürgen Groß <jgross@suse.com>
> Signed-off-by: Jiri Kosina <jkosina@suse.com>
Tested-by: Jürgen Groß <jgross@suse.com>
Jürgen
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
next prev parent reply other threads:[~2026-08-21 13:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-21 6:38 Build error with kernel from 2026-08-21 Juergen Gross
2026-08-21 7:06 ` Juergen Gross
2026-08-21 8:41 ` Jiri Kosina
2026-08-21 8:51 ` Jürgen Groß
2026-08-21 8:52 ` Jürgen Groß
2026-08-21 9:24 ` Jiri Kosina
2026-08-21 9:35 ` Jiri Kosina
2026-08-21 10:13 ` Jürgen Groß
2026-08-21 10:23 ` [PATCH] HID: hyperv: make pointer arithmetics understandable for FORTIFY_SOURCE Jiri Kosina
2026-08-21 11:16 ` Jürgen Groß
2026-08-21 13:18 ` Benjamin Tissoires
2026-08-21 13:39 ` [PATCH v2] " Jiri Kosina
2026-08-21 13:50 ` Benjamin Tissoires
2026-08-21 13:54 ` Juergen Gross [this message]
2026-08-21 14:00 ` Jiri Kosina
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=f1164c4d-3fa4-4e58-8c5e-20e203b0d8bc@suse.com \
--to=jgross@suse.com \
--cc=bentiss@kernel.org \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=jikos@kernel.org \
--cc=kys@microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longli@microsoft.com \
--cc=michael.bommarito@gmail.com \
--cc=wei.liu@kernel.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
all inboxes | Powered by JetHome®