Linux Hardening
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Kees Cook <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Karol Herbst <kherbst@redhat.com>, Lyude Paul <lyude@redhat.com>,
	Danilo Krummrich <dakr@redhat.com>,
	David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
	dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] drm/nouveau: Avoid -Wflex-array-member-not-at-end warning
Date: Tue, 27 Aug 2024 13:09:46 -0600	[thread overview]
Message-ID: <2065d0f6-660e-4647-95b4-8d1a9a7eaefe@embeddedor.com> (raw)
In-Reply-To: <202408221011.82876DA0C4@keescook>



On 22/08/24 11:27, Kees Cook wrote:
> On Wed, Aug 21, 2024 at 02:16:21PM -0600, Gustavo A. R. Silva wrote:
>> Use the `DEFINE_RAW_FLEX()` helper for an on-stack definition of
>> a flexible structure where the size of the flexible-array member
>> is known at compile-time, and refactor the rest of the code,
>> accordingly.
>>
>> So, with this, fix the following warning:
>>
>> drivers/gpu/drm/nouveau/dispnv50/disp.c:779:47: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
>>
>> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
>> ---
>>   drivers/gpu/drm/nouveau/dispnv50/disp.c | 20 +++++++++-----------
>>   1 file changed, 9 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/nouveau/dispnv50/disp.c b/drivers/gpu/drm/nouveau/dispnv50/disp.c
>> index eed579a6c858..ddddc69640be 100644
>> --- a/drivers/gpu/drm/nouveau/dispnv50/disp.c
>> +++ b/drivers/gpu/drm/nouveau/dispnv50/disp.c
>> @@ -774,11 +774,9 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc,
>>   	struct drm_hdmi_info *hdmi = &nv_connector->base.display_info.hdmi;
>>   	union hdmi_infoframe infoframe = { 0 };
>>   	const u8 rekey = 56; /* binary driver, and tegra, constant */
>> +	DEFINE_RAW_FLEX(struct nvif_outp_infoframe_v0, args, data, 17);
>> +	const u8 data_len = 17; /* same length as in DEFINE_RAW_FLEX above. */
> 
> To avoid repeating the open-coded "17", this could either be a define:
> 
> nv50_hdmi_enable(...)
> {
> ...
> #define data_len	17
> 	DEFINE_RAW_FLEX(struct nvif_outp_infoframe_v0, args, data, data_len);
> ...rest of function...
> #undef data_len
> }
> 
> or an ungainly but compile-time calculated value that exposes some
> DEFINE_FLEX internals:
> 
> 	const u8 data_len = (sizeof(args_u) - sizeof(*args)) / sizeof(*args->data);

Yeah, I actually thought of something more like just __struct_size(args) - sizeof(*args),
as the flex array member is `__u8 data[]`.

> 
> (Maybe a helper is needed for that?)
> 
> #define STACK_FLEX_COUNT(name, member)	\
> 	((sizeof(name##_u) = sizeof(*(name))) / sizeof(*(name)->member))

I don't like this `sizeof(name##_u)` part as it is detached from the DEFINE_RAW_FLEX()
internals. Probably use `__struct_size(args)` instead, as in the example above.

> 
>> @@ -815,29 +813,29 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc,
>>   		return;
>>   
>>   	/* AVI InfoFrame. */
>> -	args.infoframe.version = 0;
>> -	args.infoframe.head = nv_crtc->index;
>> +	args->version = 0;
>> +	args->head = nv_crtc->index;
> 
> The stack variable (was before and is again) already zero-initialized,
> so the "= 0" line shouldn't be needed.
> 
> But neither of these comments are show-stoppers, IMO.
> 
> Reviewed-by: Kees Cook <kees@kernel.org>
> 

Thanks!

--
Gustavo

  reply	other threads:[~2024-08-27 19:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-21 20:16 [PATCH][next] drm/nouveau: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
2024-08-22 17:27 ` Kees Cook
2024-08-27 19:09   ` Gustavo A. R. Silva [this message]
2024-09-13  8:09 ` Gustavo A. R. Silva
2024-09-13 10:23   ` Danilo Krummrich
2024-10-03 18:36     ` Danilo Krummrich
2024-10-03 18:44       ` Gustavo A. R. Silva
2024-10-03 19:09         ` Danilo Krummrich
2024-10-03 19:13           ` Gustavo A. R. Silva
2024-10-05 16:04         ` Kees Cook
2024-10-14 22:43           ` Danilo Krummrich

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=2065d0f6-660e-4647-95b4-8d1a9a7eaefe@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=airlied@gmail.com \
    --cc=dakr@redhat.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gustavoars@kernel.org \
    --cc=kees@kernel.org \
    --cc=kherbst@redhat.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lyude@redhat.com \
    --cc=nouveau@lists.freedesktop.org \
    /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