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)

From: David Laight

Date: Wed Nov 25 2026 - 05:00:21 EST


On Tue, 24 Nov 2026 11:18:19 +0100
"Arnd Bergmann" <arnd@xxxxxxxx> 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@xxxxxxxxxxxxxx
> >>
> >> What an LLM came up with after I asked it to fix
> >> https://lore.kernel.org/lkml/202603030747.VX0v4otS-lkp@xxxxxxxxx/ 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
>