Skip to content

Commit 285654d

Browse files
johnmeneghinimartinkpetersen
authored andcommitted
Revert "scsi: qla2xxx: Fix memcpy() field-spanning write issue"
This reverts commit 6f4b102. We've been testing this patch and it turns out there is a significant bug here. This leaks memory and causes a driver hang. Link: https://lore.kernel.org/linux-scsi/yq1zfajqpec.fsf@ca-mkp.ca.oracle.com/ Signed-off-by: John Meneghini <jmeneghi@redhat.com> Acked-by: Gustavo A. R. Silva <gustavoars@kernel.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 27e0665 commit 285654d

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

drivers/scsi/qla2xxx/qla_def.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4890,7 +4890,9 @@ struct purex_item {
48904890
struct purex_item *pkt);
48914891
atomic_t in_use;
48924892
uint16_t size;
4893-
uint8_t iocb[] __counted_by(size);
4893+
struct {
4894+
uint8_t iocb[64];
4895+
} iocb;
48944896
};
48954897

48964898
#include "qla_edif.h"
@@ -5099,6 +5101,7 @@ typedef struct scsi_qla_host {
50995101
struct list_head head;
51005102
spinlock_t lock;
51015103
} purex_list;
5104+
struct purex_item default_item;
51025105

51035106
struct name_list_extended gnl;
51045107
/* Count of active session/fcport */
@@ -5127,11 +5130,6 @@ typedef struct scsi_qla_host {
51275130
#define DPORT_DIAG_IN_PROGRESS BIT_0
51285131
#define DPORT_DIAG_CHIP_RESET_IN_PROGRESS BIT_1
51295132
uint16_t dport_status;
5130-
5131-
/* Must be last --ends in a flexible-array member. */
5132-
TRAILING_OVERLAP(struct purex_item, default_item, iocb,
5133-
uint8_t __default_item_iocb[QLA_DEFAULT_PAYLOAD_SIZE];
5134-
);
51355133
} scsi_qla_host_t;
51365134

51375135
struct qla27xx_image_status {

drivers/scsi/qla2xxx/qla_isr.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,17 +1077,17 @@ static struct purex_item *
10771077
qla24xx_alloc_purex_item(scsi_qla_host_t *vha, uint16_t size)
10781078
{
10791079
struct purex_item *item = NULL;
1080+
uint8_t item_hdr_size = sizeof(*item);
10801081

10811082
if (size > QLA_DEFAULT_PAYLOAD_SIZE) {
1082-
item = kzalloc(struct_size(item, iocb, size), GFP_ATOMIC);
1083+
item = kzalloc(item_hdr_size +
1084+
(size - QLA_DEFAULT_PAYLOAD_SIZE), GFP_ATOMIC);
10831085
} else {
10841086
if (atomic_inc_return(&vha->default_item.in_use) == 1) {
10851087
item = &vha->default_item;
10861088
goto initialize_purex_header;
10871089
} else {
1088-
item = kzalloc(
1089-
struct_size(item, iocb, QLA_DEFAULT_PAYLOAD_SIZE),
1090-
GFP_ATOMIC);
1090+
item = kzalloc(item_hdr_size, GFP_ATOMIC);
10911091
}
10921092
}
10931093
if (!item) {
@@ -1127,16 +1127,17 @@ qla24xx_queue_purex_item(scsi_qla_host_t *vha, struct purex_item *pkt,
11271127
* @vha: SCSI driver HA context
11281128
* @pkt: ELS packet
11291129
*/
1130-
static struct purex_item *
1131-
qla24xx_copy_std_pkt(struct scsi_qla_host *vha, void *pkt)
1130+
static struct purex_item
1131+
*qla24xx_copy_std_pkt(struct scsi_qla_host *vha, void *pkt)
11321132
{
11331133
struct purex_item *item;
11341134

1135-
item = qla24xx_alloc_purex_item(vha, QLA_DEFAULT_PAYLOAD_SIZE);
1135+
item = qla24xx_alloc_purex_item(vha,
1136+
QLA_DEFAULT_PAYLOAD_SIZE);
11361137
if (!item)
11371138
return item;
11381139

1139-
memcpy(&item->iocb, pkt, QLA_DEFAULT_PAYLOAD_SIZE);
1140+
memcpy(&item->iocb, pkt, sizeof(item->iocb));
11401141
return item;
11411142
}
11421143

drivers/scsi/qla2xxx/qla_nvme.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ void qla2xxx_process_purls_iocb(void **pkt, struct rsp_que **rsp)
13081308

13091309
ql_dbg(ql_dbg_unsol, vha, 0x2121,
13101310
"PURLS OP[%01x] size %d xchg addr 0x%x portid %06x\n",
1311-
item->iocb[3], item->size, uctx->exchange_address,
1311+
item->iocb.iocb[3], item->size, uctx->exchange_address,
13121312
fcport->d_id.b24);
13131313
/* +48 0 1 2 3 4 5 6 7 8 9 A B C D E F
13141314
* ----- -----------------------------------------------

drivers/scsi/qla2xxx/qla_os.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6459,10 +6459,9 @@ void qla24xx_process_purex_rdp(struct scsi_qla_host *vha,
64596459
void
64606460
qla24xx_free_purex_item(struct purex_item *item)
64616461
{
6462-
if (item == &item->vha->default_item) {
6462+
if (item == &item->vha->default_item)
64636463
memset(&item->vha->default_item, 0, sizeof(struct purex_item));
6464-
memset(&item->vha->__default_item_iocb, 0, QLA_DEFAULT_PAYLOAD_SIZE);
6465-
} else
6464+
else
64666465
kfree(item);
64676466
}
64686467

0 commit comments

Comments
 (0)