Commit 6f4b102
scsi: qla2xxx: Fix memcpy() field-spanning write issue
purex_item.iocb is defined as a 64-element u8 array, but 64 is the
minimum size and it can be allocated larger. This makes it a standard
empty flex array.
This was motivated by field-spanning write warnings during FPIN testing:
https://lore.kernel.org/linux-nvme/20250709211919.49100-1-bgurney@redhat.com/
> kernel: memcpy: detected field-spanning write (size 60) of single field
> "((uint8_t *)fpin_pkt + buffer_copy_offset)"
> at drivers/scsi/qla2xxx/qla_isr.c:1221 (size 44)
I removed the outer wrapper from the iocb flex array, so that it can be
linked to 'purex_item.size' with '__counted_by'.
These changes remove the default minimum 64-byte allocation, requiring
further changes.
In 'struct scsi_qla_host' the embedded 'default_item' is now followed
by '__default_item_iocb[QLA_DEFAULT_PAYLOAD_SIZE]' to reserve space
that will be used as 'default_item.iocb'. This is wrapped using the
'TRAILING_OVERLAP()' macro helper, which effectively creates a union
between flexible-array member 'default_item.iocb' and
'__default_item_iocb'.
Since 'struct pure_item' now contains a flexible-array member, the
helper must be placed at the end of 'struct scsi_qla_host' to prevent
a '-Wflex-array-member-not-at-end' warning.
'qla24xx_alloc_purex_item()' is adjusted to no longer expect the
default minimum size to be part of 'sizeof(struct purex_item)', the
entire flexible array size is added to the structure size for
allocation.
This also slightly changes the layout of the purex_item struct, as
2-bytes of padding are added between 'size' and 'iocb'. The resulting
size is the same, but iocb is shifted 2-bytes (the original 'purex_item'
structure was padded at the end, after the 64-byte defined array size).
I don't think this is a problem.
Tested-by: Bryan Gurney <bgurney@redhat.com>
Co-developed-by: Chris Leech <cleech@redhat.com>
Signed-off-by: Chris Leech <cleech@redhat.com>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/20250813200744.17975-10-bgurney@redhat.com
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>1 parent 6b5da52 commit 6f4b102
4 files changed
Lines changed: 18 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4890 | 4890 | | |
4891 | 4891 | | |
4892 | 4892 | | |
4893 | | - | |
4894 | | - | |
4895 | | - | |
| 4893 | + | |
4896 | 4894 | | |
4897 | 4895 | | |
4898 | 4896 | | |
| |||
5101 | 5099 | | |
5102 | 5100 | | |
5103 | 5101 | | |
5104 | | - | |
5105 | 5102 | | |
5106 | 5103 | | |
5107 | 5104 | | |
| |||
5130 | 5127 | | |
5131 | 5128 | | |
5132 | 5129 | | |
| 5130 | + | |
| 5131 | + | |
| 5132 | + | |
| 5133 | + | |
| 5134 | + | |
5133 | 5135 | | |
5134 | 5136 | | |
5135 | 5137 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1077 | 1077 | | |
1078 | 1078 | | |
1079 | 1079 | | |
1080 | | - | |
1081 | 1080 | | |
1082 | 1081 | | |
1083 | | - | |
1084 | | - | |
| 1082 | + | |
1085 | 1083 | | |
1086 | 1084 | | |
1087 | 1085 | | |
1088 | 1086 | | |
1089 | 1087 | | |
1090 | | - | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
1091 | 1091 | | |
1092 | 1092 | | |
1093 | 1093 | | |
| |||
1127 | 1127 | | |
1128 | 1128 | | |
1129 | 1129 | | |
1130 | | - | |
1131 | | - | |
| 1130 | + | |
| 1131 | + | |
1132 | 1132 | | |
1133 | 1133 | | |
1134 | 1134 | | |
1135 | | - | |
1136 | | - | |
| 1135 | + | |
1137 | 1136 | | |
1138 | 1137 | | |
1139 | 1138 | | |
1140 | | - | |
| 1139 | + | |
1141 | 1140 | | |
1142 | 1141 | | |
1143 | 1142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1308 | 1308 | | |
1309 | 1309 | | |
1310 | 1310 | | |
1311 | | - | |
| 1311 | + | |
1312 | 1312 | | |
1313 | 1313 | | |
1314 | 1314 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6459 | 6459 | | |
6460 | 6460 | | |
6461 | 6461 | | |
6462 | | - | |
| 6462 | + | |
6463 | 6463 | | |
6464 | | - | |
| 6464 | + | |
| 6465 | + | |
6465 | 6466 | | |
6466 | 6467 | | |
6467 | 6468 | | |
| |||
0 commit comments