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: Bart Van Assche
Date: Mon Nov 23 2026 - 18:37:33 EST
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.
Bart.
scsi: qla2xxx: Fix the qla_tgt_sess_op layout assertion
qlt_queue_unknown_atio() allocates a struct qla_tgt_sess_op followed by
add_cdb_len bytes and copies an ATIO plus its additional CDB bytes into
the 'atio' member. Hence no other member may follow 'atio'. The
BUILD_BUG_ON() that is supposed to verify this compares the end of
'atio' with sizeof(struct qla_tgt_sess_op). That is wrong because it
also triggers if the compiler adds tail padding. This is what happens on
m68k since atomic_t is aligned on a four byte boundary: 'atio' ends at
offset 102 and the structure size is 104 bytes. This breaks the build
for CONFIG_COLDFIRE=y and CONFIG_SCSI_QLA_FC=y:
error: call to '__compiletime_assert_431' declared with attribute
error: BUILD_BUG_ON failed: offsetof(struct qla_tgt_sess_op, atio) +
sizeof(u->atio) != sizeof(*u)
Additionally, the BUILD_BUG_ON() does not detect all members that could
be added after 'atio', e.g. a zero-length array.
Fix this by adding a flexible array member after 'atio' that represents
the additional CDB bytes. The compiler rejects any member that is added
after a flexible array member. Assert that the flexible array member
follows 'atio' immediately instead of making assumptions about the
structure size. Use kzalloc_flex() to allocate the structure. This does
not change the allocation size.
This patch is based on a patch from Finn Thain and on a suggestion from
Tony Battersby.
Do not modify the memcpy() call in qlt_queue_unknown_atio(), which
still writes past the end of the 'atio' member.
Compile-tested only, for m68k (Coldfire) and x86_64.
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Closes: https://lore.kernel.org/oe-kbuild-all/202603030747.VX0v4otS-lkp@xxxxxxxxx/
Closes: https://lore.kernel.org/oe-kbuild-all/202609301230.CauIUXCF-lkp@xxxxxxxxx/
Link: https://lore.kernel.org/all/4808a5dc1a71528ffa3360868561009744277450.1791502886.git.fthain@xxxxxxxxxxxxxx/
Fixes: 091719c21d5a ("scsi: qla2xxx: target: Fix invalid memory access with big CDBs")
Fixes: e428b013d9df ("atomic: specify alignment for atomic_t and atomic64_t")
diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c
index 5a7caff61b16..afa96551c13c 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -212,9 +212,6 @@ static void qlt_queue_unknown_atio(scsi_qla_host_t *vha,
unsigned long flags;
unsigned int add_cdb_len = 0;
- /* atio must be the last member of qla_tgt_sess_op for add_cdb_len */
- BUILD_BUG_ON(offsetof(struct qla_tgt_sess_op, atio) + sizeof(u->atio) != sizeof(*u));
-
if (tgt->tgt_stop) {
ql_dbg(ql_dbg_async, vha, 0x502c,
"qla_target(%d): dropping unknown ATIO_TYPE7, because tgt is being stopped",
@@ -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;
diff --git a/drivers/scsi/qla2xxx/qla_target.h b/drivers/scsi/qla2xxx/qla_target.h
index 71bc1affb1bc..c1559f034f85 100644
--- a/drivers/scsi/qla2xxx/qla_target.h
+++ b/drivers/scsi/qla2xxx/qla_target.h
@@ -845,9 +845,16 @@ struct qla_tgt_sess_op {
struct rsp_que *rsp;
struct atio_from_isp atio;
- /* DO NOT ADD ANYTHING ELSE HERE - atio must be last member */
+ /*
+ * The part of atio.u.isp24.fcp_cmnd.add_cdb[] that extends past the
+ * end of atio. Must follow atio immediately.
+ */
+ uint8_t extra_cdb[];
};
+static_assert(offsetofend(struct qla_tgt_sess_op, atio) ==
+ offsetof(struct qla_tgt_sess_op, extra_cdb));
+
enum trace_flags {
TRC_NEW_CMD = BIT_0,
TRC_DO_WORK = BIT_1,