From mboxrd@z Thu Jan 1 00:00:00 1970 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 5D25C1B6D1A for ; Fri, 21 Aug 2026 13:18:40 +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=1787318330; cv=none; b=qDeajoAsIi6GaQAtAqrFh9YvvymrZlg8nlFjb9ZX0ugXx+jXTRPmWwYxAQBErli6AsF/iEUx7lkTKEshr+UJ2Oh5c06RiOticV7ZyTgj4tRSJTUwtrza1JvUUhkmBwYwABfVfdqhYX9+KHwf9MJjipGnl/AGAuqrQja4z907Y+g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787318330; c=relaxed/simple; bh=7U5ZLv5FAU7w/DU7r4RtWt7cVaDBMqHXnamW+Ynjq1Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LY4umDs6ujrA1cwJwxpbPDADhygbVVkkNV+oh8GTeMZUKnlz70cP2sVUZfk5HKUTaXMEEkMN1u27jIQ41atqjGC/r7kznK9pe3QYSsjoM5UJoGTNEo6ImdALgU7tdSFN7Sx2jlliCd7DH38F3U7c5Qa6ZclyfG189aJAPIb0J9Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FGxiVuza; 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="FGxiVuza" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50D751F00A3D; Fri, 21 Aug 2026 13:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787318318; bh=aUL854z7hYBhBehrC4DMkJxSPQxr/RZX8v/JsXi8R/0=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=FGxiVuzaqxb1U2q613h3J8DFl0vCZsZ0QIJpg0rhgHiwFDrBn2YxP0WaJssSqZXQ2 NzoUHO6DNlVwWZF7027rwkis51cB+TiVdKGIkzDbYyDJPHtfaxjqqknGDndBDIbLe2 n4l+3lZwLH/HvtMko1pRmJfQ0w7w4SH8soZ0lfflYQMqZoLGuqkqp7WqyDk1Al9wxx J1w9ibfllf4AZV5M4rJgJw6iYdVn0bkcy5OxCPxZLqpGdsbDCrUJpmdkyHek/MSuZZ Di0ir8fISJNGYQOtKSzEawWsxnKNP28lYECQ2KU5u9YGQpLbx05IzkU06EnmpMHaWK 5PIBiv8jMC8Gg== Date: Fri, 21 Aug 2026 15:18:33 +0200 From: Benjamin Tissoires To: Jiri Kosina Cc: =?utf-8?B?SsO8cmdlbiBHcm/Dnw==?= , lkml , michael.bommarito@gmail.com, longli@microsoft.com, decui@microsoft.com, wei.liu@kernel.org, haiyangz@microsoft.com, kys@microsoft.com Subject: Re: [PATCH] HID: hyperv: make pointer arithmetics understandable for FORTIFY_SOURCE Message-ID: 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-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <746q4npo-1s59-4824-q633-9qr343no4369@xreary.bet> On Aug 21 2026, Jiri Kosina wrote: > From: Jiri Kosina > > 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ß > Signed-off-by: Jiri Kosina > --- > 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(struct kunit *test) > > info->hid_descriptor.bLength = sizeof(struct hid_descriptor); > info->hid_descriptor.rpt_desc.wDescriptorLength = cpu_to_le16(4); > - 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)`? > memset(report, 0x42, 4); > > 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) > > info->hid_descriptor.bLength = sizeof(struct hid_descriptor); > info->hid_descriptor.rpt_desc.wDescriptorLength = cpu_to_le16(64); > - report = ((u8 *)&info->hid_descriptor) + info->hid_descriptor.bLength; > + report = (u8 *)info + offsetof(struct synthhid_device_info, hid_descriptor) + info->hid_descriptor.bLength; Same overcomplexification applies here. Unless of course there is something I missed in the string fortification. Cheers, Benjamin > memset(report, 0x42, 8); > > mousevsc_on_receive_device_info(input_dev, info, sizeof(*info) + 8); > > -- > Jiri Kosina > SUSE Labs > >