All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Alex Deucher <alexdeucher@gmail.com>
Cc: "Alex Deucher" <alexander.deucher@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Xinhui Pan" <Xinhui.Pan@amd.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Jesse Zhang" <jesse.zhang@amd.com>,
	"Tim Huang" <Tim.Huang@amd.com>,
	"Srinivasan Shanmugam" <srinivasan.shanmugam@amd.com>,
	"Alexander Richards" <electrodeyt@gmail.com>,
	"Lijo Lazar" <lijo.lazar@amd.com>,
	"Mario Limonciello" <mario.limonciello@amd.com>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	"Al Viro" <viro@zeniv.linux.org.uk>,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH] drm/amdgpu/atom: Work around vbios NULL offset false positive
Date: Tue, 22 Apr 2025 07:56:28 -0700	[thread overview]
Message-ID: <202504220755.179FD11DAD@keescook> (raw)
In-Reply-To: <CADnq5_MbGS+DBRZhQccqP-o50vvv6uiT31msefRTw5bMydAAKg@mail.gmail.com>

On Tue, Apr 22, 2025 at 09:22:26AM -0400, Alex Deucher wrote:
> On Mon, Apr 21, 2025 at 5:59 PM Kees Cook <kees@kernel.org> wrote:
> >
> > GCC really does not want to consider NULL (or near-NULL) addresses as
> > valid, so calculations based off of NULL end up getting range-tracked into
> > being an offset wthin a 0 byte array. It gets especially mad about this:
> >
> >                 if (vbios_str == NULL)
> >                         vbios_str += sizeof(BIOS_ATOM_PREFIX) - 1;
> >         ...
> >         if (vbios_str != NULL && *vbios_str == 0)
> >                 vbios_str++;
> >
> > It sees this as being "sizeof(BIOS_ATOM_PREFIX) - 1" byte offset from
> > NULL, when building with -Warray-bounds (and the coming
> > -fdiagnostic-details flag):
> >
> > In function 'atom_get_vbios_pn',
> >     inlined from 'amdgpu_atom_parse' at drivers/gpu/drm/amd/amdgpu/atom.c:1553:2:
> > drivers/gpu/drm/amd/amdgpu/atom.c:1447:34: error: array subscript 0 is outside array bounds of 'unsigned char[0]' [-Werror=array-bounds=]
> >  1447 |         if (vbios_str != NULL && *vbios_str == 0)
> >       |                                  ^~~~~~~~~~
> >   'amdgpu_atom_parse': events 1-2
> >  1444 |                 if (vbios_str == NULL)
> >       |                    ^
> >       |                    |
> >       |                    (1) when the condition is evaluated to true
> > ......
> >  1447 |         if (vbios_str != NULL && *vbios_str == 0)
> >       |                                  ~~~~~~~~~~
> >       |                                  |
> >       |                                  (2) out of array bounds here
> > In function 'amdgpu_atom_parse':
> > cc1: note: source object is likely at address zero
> >
> > As there isn't a sane way to convince it otherwise, hide vbios_str from
> > GCC's optimizer to avoid the warning so we can get closer to enabling
> > -Warray-bounds globally.
> >
> > Signed-off-by: Kees Cook <kees@kernel.org>
> 
> Acked-by: Alex Deucher <alexander.deucher@amd.com>

Thanks!

> Do you want me to pick this up, or do you want to take this through
> some other tree?

Whatever is easier for you. I'm happy to carry it if you'd like. :)
There's no rush on these -- it's been a long road to getting
-Warray-bounds enabled. ;)

-- 
Kees Cook

  reply	other threads:[~2025-04-22 14:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-21 21:58 [PATCH] drm/amdgpu/atom: Work around vbios NULL offset false positive Kees Cook
2025-04-22 13:22 ` Alex Deucher
2025-04-22 14:56   ` Kees Cook [this message]
2025-04-22 15:24     ` Alex Deucher

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=202504220755.179FD11DAD@keescook \
    --to=kees@kernel.org \
    --cc=Tim.Huang@amd.com \
    --cc=Xinhui.Pan@amd.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=alexdeucher@gmail.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=electrodeyt@gmail.com \
    --cc=gustavoars@kernel.org \
    --cc=jesse.zhang@amd.com \
    --cc=lijo.lazar@amd.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=simona@ffwll.ch \
    --cc=srinivasan.shanmugam@amd.com \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.