From nobody Mon Sep 28 13:19:50 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 CEB6B45BD7F for ; Fri, 21 Aug 2026 10:24:08 +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=1787307853; cv=none; b=W711GVNkqtIeb7uCKRseg/ScIK/FUZ3rbMb4+bDddvTHEYmXO6aVC2Jr5VtZPxoJ1bygkg4udpPYCQsznyNoSJpiXt7cvsQXgSNgbnoamDU2C3BpcwSp6ODZpvj4c3A6JOA8jSehPvXop/8DSO3TevD+VH44zPGDmVL0QgcuGpQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787307853; c=relaxed/simple; bh=XXlRDmx0Nf3piQrVyh7oyDd5Vyazkvbh/sH4BnhNi8k=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=AtKyZNYv0LGgKcaOkaMc70cLaBc5/o8OsGnglaf2ASwUJ4Va6UCJvLsjNKNZwJPKWn9qei8aqZH49CG+BiTF6P6mFr/XKjCBH5obrPpHr1cmBuFehhbPDg5zDWGls1Uom1j7EFXHSxd9UBOX675p9378SoCtjSHHfsQr8o9qv+4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f2zfhm8P; 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="f2zfhm8P" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DEA11F000E9; Fri, 21 Aug 2026 10:24:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787307841; bh=XXlRDmx0Nf3piQrVyh7oyDd5Vyazkvbh/sH4BnhNi8k=; h=Date:From:To:cc:Subject:In-Reply-To:References; b=f2zfhm8P3RCeQ8bItCN+/yjcDiRtg/pBidQoB7TvFxCWlaT3i7hvxUwH7i3WWDmN7 8+UUsoyRTTHjTPzrf0LSbpndjEPjOxWOslOOla6Haal+VY32dXXBSRy5JRzpePTeST htKYq/FsNVDXcP2/q1A83tAJWN23XQVMg2xJUnk1LF7y0ZdMnxVaSrxuno179EtvAA HU99DydtRHqDVdErKZeM+9gEsq7pM1F5fMAKjadtBiWcKHDmCvWlMxkbutD3oyhpmM eiLTRQmuM3gqj+DZkvbp7H+bE731w7Qu9TPK84OXfe7OFHFws6Ovs75QXVxZszYEH2 bmrYzAd7TQe5g== Date: Fri, 21 Aug 2026 12:23:59 +0200 (CEST) From: Jiri Kosina To: =?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, Benjamin Tissoires Subject: [PATCH] HID: hyperv: make pointer arithmetics understandable for FORTIFY_SOURCE In-Reply-To: <662f5ab3-8be8-4df6-a92c-a402bdd512df@suse.com> Message-ID: <746q4npo-1s59-4824-q633-9qr343no4369@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> 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" From: Jiri Kosina 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 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..4a10b24da9fa 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 + offsetof(struct synthhid_device_info, hid_descrip= tor) + info->hid_descriptor.bLength; 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 + offsetof(struct synthhid_device_info, hid_descrip= tor) + info->hid_descriptor.bLength; memset(report, 0x42, 8); =20 mousevsc_on_receive_device_info(input_dev, info, sizeof(*info) + 8); --=20 Jiri Kosina SUSE Labs