Re: [PATCH] HID: hyperv: make pointer arithmetics understandable for FORTIFY_SOURCE
From: Jürgen Groß
Date: Fri Aug 21 2026 - 07:35:28 EST
On 21.08.26 12:23, Jiri Kosina wrote:
From: Jiri Kosina <jkosina@xxxxxxxx>
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@xxxxxxxx>
Signed-off-by: Jiri Kosina <jkosina@xxxxxxxx>
Tested-by: Jürgen Groß <jgross@xxxxxxxx>
Jürgen
Attachment:
OpenPGP_0xB0DE9DD628BF132F.asc
Description: OpenPGP public key
Attachment:
OpenPGP_signature.asc
Description: OpenPGP digital signature