From: David Laight <david.laight.linux@gmail.com>
To: "Arnd Bergmann" <arnd@arndb.de>
Cc: "Finn Thain" <fthain@linux-m68k.org>,
"Bart Van Assche" <bvanassche@acm.org>,
"Geert Uytterhoeven" <geert@linux-m68k.org>,
"kernel test robot" <lkp@intel.com>,
oe-kbuild-all@lists.linux.dev, linux-kernel@vger.kernel.org,
"Andrew Morton" <akpm@linux-foundation.org>,
"Linux Memory Management List" <linux-mm@kvack.org>,
"James E . J . Bottomley" <James.Bottomley@hansenpartnership.com>,
"Martin K. Petersen" <mkp@kernel.org>,
scsi <linux-scsi@vger.kernel.org>
Subject: Re: include/linux/compiler_types.h:631:45: error: call to '__compiletime_assert_433' declared with attribute error: BUILD_BUG_ON failed: offsetof(struct qla_tgt_sess_op, atio) + sizeof(u->atio) != sizeof(*u)
Date: Wed, 25 Nov 2026 10:00:13 +0000 [thread overview]
Message-ID: <20261125100013.356bc7c7@pumpkin> (raw)
In-Reply-To: <f0ec2845-245d-43ac-9c96-242e0d1d11ea@app.fastmail.com>
On Tue, 24 Nov 2026 11:18:19 +0100
"Arnd Bergmann" <arnd@arndb.de> wrote:
> On Tue, Nov 24, 2026, at 04:31, Finn Thain wrote:
> > On Mon, 23 Nov 2026, Bart Van Assche wrote:
> >
> >> On 11/23/26 3:05 PM, Finn Thain wrote:
> >> > Yes, two alternative solutions were submitted in March (either remove the
> >> > assertion or rework it). The build bot reported the problem again in
> >> > September so I resubmitted the "rework" alternative. Sashiko-bot didn't
> >> > have much praise for that*, so now I'm leaning towards the "remove"
> >> > alternative. I have been advised to keep re-submitting, and I will do so
> >> > after a suitable back-off in retry rate i.e. 2027 or 2028.
> >> >
> >> > *
> >> > https://lore.kernel.org/r/93e35f60-e465-7f76-0043-f997fe2ec8c7@linux-m68k.org
> >>
> >> What an LLM came up with after I asked it to fix
> >> https://lore.kernel.org/lkml/202603030747.VX0v4otS-lkp@intel.com/ can be
> >> found below. One of the comments of the LLM is "This is essentially Finn
> >> Thain's "Rework BUILD_BUG_ON() assertion" patch with your two review
> >> comments from this morning applied". Sashiko reports "No issues found"
> >> for the patch below. No Signed-off-by from me because I think Finn
> >> should be credited for his work instead of I.
> >>
> >
> > Thanks, Bart. I'll take that as a vote for "rework". There is an
> > associated risk though: I can't test the patch as I don't have access to
> > suitable hardware. (Perhaps someone with such access will volunteer.)
> >
> > Whereas, the "remove" alternative doesn't require testing as it doesn't
> > risk a regression.
> >
> > I have a question for your LLM. Sashiko-bot said, in response to my patch:
> >
> > Similarly, get_datalen_for_atio() accesses the array out-of-bounds
> > when len > 0:
> >
> > drivers/scsi/qla2xxx/qla_target.h:get_datalen_for_atio() {
> > ...
> > return get_unaligned_be32(&atio->u.isp24.fcp_cmnd.add_cdb[len * 4]);
> > ...
> > }
> >
> > I don't understand why the patch from your LLM did not raise the same OOB
> > access concerns.
>
> I suspect that is just from Bart specifically calling it out in the changelog
> already as a known limitation "Do not modify the memcpy() call in
> qlt_queue_unknown_atio(), which still writes past the end of the 'atio'
> member.".
>
> > Adding a flex array to struct qla_tgt_sess_op can prevent new struct
> > members being added in the wrong spot in that struct but can't prevent new
> > struct members being added to struct atio7_fcp_cmnd. Neither does the
> > assertion. So the "remove" alternative doesn't have all the disadvantages
> > that you might expect.
>
> This is probably just a difference in perception: atio_from_isp and
> everything inside is clearly marked as a hardware structure that is
> meant to align exactly to the 64 byte cacheline, so it would not
> make any sense to change its layout and add more members here.
> qla_tgt_sess_op on the other hand is clearly not a hardware structure
> but an in-kernel one, so it is quite unexpected that one of its members
> extends past the end, especially when the other three instances of
> atio_from_isp in data structures don't seem to do that.
>
> >> @@ -227,7 +224,7 @@ static void qlt_queue_unknown_atio(scsi_qla_host_t *vha,
> >> add_cdb_len =
> >> ((unsigned int) atio->u.isp24.fcp_cmnd.add_cdb_len) * 4;
> >>
> >> - u = kzalloc(sizeof(*u) + add_cdb_len, GFP_ATOMIC);
> >> + u = kzalloc_flex(*u, extra_cdb, add_cdb_len, GFP_ATOMIC);
> >> if (u == NULL)
> >> goto out_term;
>
> While this does make the current implementation more correct by having
> the correct length, I'm worried that it just ends up establishing
> the complexity more in the sense that extra_cdb extends both into
> the padding and beyond qla_tgt_sess_op.
Isn't the struct also embedded in the middle of other structures
so can't end in a flex array?
> If the driver is still actively maintained, it would be nice to
> reduce the complexity instead, in one of two ways:
>
> a) make atio_from_isp naturally aligned by dropping the bogus
> __packed attribute, so it is actually at the end of qla_tgt_sess_op
> as the driver was written to expect. Note that having the
> outer structure as __packed but the union and the inner
> structs as aligned is itself problematic and can lead to
> undefined behavior, if some code ever takes a pointer to
> one of the inner aggregates and expects it to be aligned.
> The only effect that I see from the __packed annotation is
> that it forces expensive byte access on dma-coherent memory
> despite it being fully aligned.
It looks to me like almost all of the __packed in that header
are bogus - there is one on an le64 member which could easily
be on an odd 32bit boundary.
What it really wants is an 'error if any padding' flag.
(And maybe a compile-time check on the longer structures.)
If the hardware does dma onto those structures then you really
don't want them misaligned either.
Bag of worms :-)
David
>
> b) rework the driver more broadly to never actually do any
> accesses beyond a struct boundary and make it work with
> sanitizers enabled. One way to do this would be to
> have a separate isp24 atio structure that is not in the
> union but that encloses the actual maximum length.
> Not sure how this would actually be done, but it appears
> that the current design keeps causing problems, see e.g.
> 091719c21d5a ("scsi: qla2xxx: target: Fix invalid memory
> access with big CDBs") which adds more complexity around
> keeping an extra copy for it.
>
> Arnd
>
prev parent reply other threads:[~2026-11-25 10:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 2:49 include/linux/compiler_types.h:631:45: error: call to '__compiletime_assert_433' declared with attribute error: BUILD_BUG_ON failed: offsetof(struct qla_tgt_sess_op, atio) + sizeof(u->atio) != sizeof(*u) kernel test robot
2026-11-21 4:10 ` Finn Thain
2026-11-23 9:48 ` Geert Uytterhoeven
2026-11-23 23:05 ` Finn Thain
2026-11-23 23:37 ` Bart Van Assche
2026-11-24 3:31 ` Finn Thain
2026-11-24 10:18 ` Arnd Bergmann
2026-11-25 0:18 ` Finn Thain
2026-11-25 7:25 ` Arnd Bergmann
2026-11-25 8:53 ` Finn Thain
2026-11-25 10:00 ` David Laight [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=20261125100013.356bc7c7@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=James.Bottomley@hansenpartnership.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=bvanassche@acm.org \
--cc=fthain@linux-m68k.org \
--cc=geert@linux-m68k.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-scsi@vger.kernel.org \
--cc=lkp@intel.com \
--cc=mkp@kernel.org \
--cc=oe-kbuild-all@lists.linux.dev \
/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