From nobody Mon Sep 28 12:36:10 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CE3533B6C9 for ; Fri, 21 Aug 2026 13:39:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787319559; cv=none; b=jxLDKJN1yIOtgRh8cXfE6fAdXuhFbJeDz7h6ARcO3GEW031Cn+lv7vO3XiIAz4DAu7+0oOJ3MrvMjYQKIrmnQU5g7DfpcsH9rV6E2bR9RuTmFpOFkRCNHmaXu9KhU2fTZTXzEQbcXZy0/ce20KklSREnE7xLfMETvuzNPYmUmP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787319559; c=relaxed/simple; bh=oZZLN37q3HLrw0sd8Vtm71Tji9EbakhZcjiLow8cqQw=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=uuOD6ErtL7iz+r3CHdzbwj/e9tLmHfVzeheE/P5BVzwzE7Lo+t2Q5Bci6eqo2L3FtzKzhF7NGwd2VfIH71yVLlIEa/lT+8IMwC6LcWZVRwUgnxayHzTdObzm/z/T02vqF2HcC5u6Wxp/IQMqdFy8g9BWl5aqf7zy56N4FvPg28A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UC1UvlLR; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UC1UvlLR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B05F1F00A3A; Fri, 21 Aug 2026 13:39:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787319558; bh=5SIkLBh9k5NMyh4aIxxAfHVHVyhk7eYz9Rg72TQNH/8=; h=Date:From:To:cc:Subject:In-Reply-To:References; b=UC1UvlLRk70fjrdD5gtZRnughyqMrqMBT9xUKpnvdUrw8L3841ZU1fiwAc4EYXy9s mU+5jMSv/Bwi7Z+SJ2tT3xoH9WdfWq5yADYXyXefpUs87MJiR5yNtrju6jzEsz5X07 EH7NwKsYDqC61A/wvlJu21OPXBUudMFB1N38UpA71MwsiqHww9V64MJ2fgmU5CnJ0W Ava3s2C36xxKv35wWoNRnHcWjFiDkEKhzW9tEVvO9OQkPezXJ+8raaVAWzVtGKkT+6 CNsBRR782Wa2wdXqCyiiTsunUeDH6UFDECHiGtiiB8H1dlEWFX8Uup+SKQnrDjQv+o isYl/o0SItL0g== Date: Fri, 21 Aug 2026 15:39:15 +0200 (CEST) From: Jiri Kosina To: Benjamin Tissoires , =?ISO-8859-15?Q?J=FCrgen_Gro=DF?= cc: lkml , michael.bommarito@gmail.com, longli@microsoft.com, decui@microsoft.com, wei.liu@kernel.org, haiyangz@microsoft.com, kys@microsoft.com Subject: [PATCH v2] HID: hyperv: make pointer arithmetics understandable for FORTIFY_SOURCE In-Reply-To: Message-ID: <17q6s829-78pr-nrq1-qrr7-9qo9n750pq63@xreary.bet> References: <9b35a830-7497-4d1f-b292-5a7594289931@suse.com> <6r2on01s-03n0-5r0n-0s21-n7q5r86o71np@xreary.bet> <53b147e8-cc10-4d49-9d19-ae52288123a3@suse.com> <776pn42o-p481-6p04-n03p-291305n30569@xreary.bet> <6s739024-9652-16r2-270q-q2026q5157q3@xreary.bet> <662f5ab3-8be8-4df6-a92c-a402bdd512df@suse.com> <746q4npo-1s59-4824-q633-9qr343no4369@xreary.bet> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On Fri, 21 Aug 2026, Benjamin Tissoires wrote: > > - report =3D ((u8 *)&info->hid_descriptor) + info->hid_descriptor.bLeng= th; > > + report =3D (u8 *)info + offsetof(struct synthhid_device_info, hid_des= criptor) + info->hid_descriptor.bLength; >=20 > Isn't that overcomplicated?: >=20 > 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 =3D kunit_kzalloc(test, sizeof(*info) + 4, GFP_KERNEL); >=20 > so info is 0 allocated with the sizeof(struct synthhid_device_info) plus > 4 for the report (immediately after). >=20 > with the bLength being set a couple of lines above, we basically have: > + report =3D (u8 *)info + offsetof(struct synthhid_device_info, hid_descr= iptor) + sizeof(struct hid_descriptor); >=20 > So pointer address + offset of the last field + size of the last field. >=20 > Isn't that equivalent to: > report =3D (u8 *)info + sizeof(*info); >=20 > or even: `(u8 *)(info + 1)`? I considered that one as well, but then I decided to keep what the=20 original author intended as perhaps it's more self-explanatory what we're=20 actually doing. But the argument that whenever a new field is added after=20 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,=20 my allyesconfig with gcc-15 doesn't trigger it. From: Jiri Kosina Subject: [PATCH] HID: hyperv: make pointer arithmetics understandable for F= ORTIFY_SOURCE Commit 83df7b5fa6735b5084ecd2 ("HID: hyperv: add KUnit coverage for device = info bounds") introduced this piece of code report =3D ((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-s= ize 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(s= truct 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=C3=BCrgen Gro=C3=9F Signed-off-by: Jiri Kosina Acked-by: Benjamin Tissoires Tested-by: J=C3=BCrgen Gro=C3=9F --- drivers/hid/hid-hyperv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-hyperv.c b/drivers/hid/hid-hyperv.c index 6579bd19da13..cfc061dbdd24 100644 --- a/drivers/hid/hid-hyperv.c +++ b/drivers/hid/hid-hyperv.c @@ -687,7 +687,7 @@ static void mousevsc_device_info_valid_descriptor(struc= t kunit *test) =20 info->hid_descriptor.bLength =3D sizeof(struct hid_descriptor); info->hid_descriptor.rpt_desc.wDescriptorLength =3D cpu_to_le16(4); - report =3D ((u8 *)&info->hid_descriptor) + info->hid_descriptor.bLength; + report =3D (u8 *)(info + 1); memset(report, 0x42, 4); =20 mousevsc_on_receive_device_info(input_dev, info, sizeof(*info) + 4); @@ -713,7 +713,7 @@ static void mousevsc_device_info_report_desc_oob(struct= kunit *test) =20 info->hid_descriptor.bLength =3D sizeof(struct hid_descriptor); info->hid_descriptor.rpt_desc.wDescriptorLength =3D cpu_to_le16(64); - report =3D ((u8 *)&info->hid_descriptor) + info->hid_descriptor.bLength; + report =3D (u8 *)(info + 1); memset(report, 0x42, 8); =20 mousevsc_on_receive_device_info(input_dev, info, sizeof(*info) + 8); --=20 Jiri Kosina SUSE Labs