linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Kosina <jikos@kernel.org>
To: Kees Cook <kees@kernel.org>
Cc: srinivas pandruvada <srinivas.pandruvada@linux.intel.com>,
	 Erick Archer <erick.archer@outlook.com>,
	 Benjamin Tissoires <bentiss@kernel.org>,
	linux-kernel@vger.kernel.org,  linux-input@vger.kernel.org,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH v2] HID: ishtp-hid-client: replace fake-flex arrays with flex-array members
Date: Tue, 8 Oct 2024 08:52:55 +0200 (CEST)	[thread overview]
Message-ID: <nycvar.YFH.7.76.2410080852440.20286@cbobk.fhfr.pm> (raw)
In-Reply-To: <20240923002249.it.617-kees@kernel.org>

On Sun, 22 Sep 2024, Kees Cook wrote:

> From: Erick Archer <erick.archer@outlook.com>
> 
> One-element arrays as fake flex arrays are deprecated[1] as the kernel
> has switched to C99 flexible-array members instead. This case, however,
> has more complexity because it is a flexible array of flexible arrays
> and this patch needs to be ready to enable the new compiler flag
> -Wflex-array-member-not-at-end (coming in GCC-14) globally.
> 
> So, define a new struct type for the single reports:
> 
> struct report {
> 	uint16_t size;
> 	struct hostif_msg_hdr msg;
> } __packed;
> 
> but without the payload (flex array) in it. And add this payload to the
> "hostif_msg" structure. This way, in the "report_list" structure we can
> declare a flex array of single reports which now do not contain another
> flex array.
> 
> struct report_list {
> 	[...]
>         struct report reports[];
> } __packed;
> 
> Therefore, the "struct hostif_msg" is now made up of a header and a
> payload. And the "struct report" uses only the "hostif_msg" header.
> The perfect solution would be for the "report" structure to use the
> whole "hostif_msg" structure but this is not possible due to nested
> flexible arrays. Anyway, the end result is equivalent since this patch
> does attempt to change the behaviour of the code.
> 
> Now as well, we have more clarity after the cast from the raw bytes to
> the new structures. Refactor the code accordingly to use the new
> structures.
> 
> Also, use "container_of()" whenever we need to retrieve a pointer to
> the flexible structure, through which we can access the flexible array
> if needed.
> 
> Link: https://www.kernel.org/doc/html/next/process/deprecated.html#zero-length-and-one-element-arrays [1]
> Closes: https://github.com/KSPP/linux/issues/333
> Signed-off-by: Erick Archer <erick.archer@outlook.com>
> Link: https://lore.kernel.org/r/AS8PR02MB723760CB93942370E92F00638BF72@AS8PR02MB7237.eurprd02.prod.outlook.com
> [kees: tweaked commit log and dropped struct_size() uses]
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
>  v2: - update based on feedback
>  rfc: https://lore.kernel.org/lkml/AS8PR02MB723760CB93942370E92F00638BF72@AS8PR02MB7237.eurprd02.prod.outlook.com/

Applied, thanks.

-- 
Jiri Kosina
SUSE Labs


      parent reply	other threads:[~2024-10-08  6:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-23  0:22 [PATCH v2] HID: ishtp-hid-client: replace fake-flex arrays with flex-array members Kees Cook
2024-09-23 19:32 ` srinivas pandruvada
2024-10-08  6:52 ` Jiri Kosina [this message]

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=nycvar.YFH.7.76.2410080852440.20286@cbobk.fhfr.pm \
    --to=jikos@kernel.org \
    --cc=bentiss@kernel.org \
    --cc=erick.archer@outlook.com \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=srinivas.pandruvada@linux.intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).