]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Revert "scsi: qla2xxx: Fix memcpy() field-spanning write issue"
authorJohn Meneghini <jmeneghi@redhat.com>
Thu, 25 Sep 2025 13:07:29 +0000 (09:07 -0400)
committerMartin K. Petersen <martin.petersen@oracle.com>
Mon, 29 Sep 2025 20:35:30 +0000 (16:35 -0400)
This reverts commit 6f4b10226b6b1e7d1ff3cdb006cf0f6da6eed71e.

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>
drivers/scsi/qla2xxx/qla_def.h
drivers/scsi/qla2xxx/qla_isr.c
drivers/scsi/qla2xxx/qla_nvme.c
drivers/scsi/qla2xxx/qla_os.c

index 604e66bead1e01e7bbecb0dc6afe25fec9b207e2..cb95b7b12051da78507d57eeac274a6616a4d031 100644 (file)
@@ -4890,7 +4890,9 @@ struct purex_item {
                             struct purex_item *pkt);
        atomic_t in_use;
        uint16_t size;
-       uint8_t iocb[] __counted_by(size);
+       struct {
+               uint8_t iocb[64];
+       } iocb;
 };
 
 #include "qla_edif.h"
@@ -5099,6 +5101,7 @@ typedef struct scsi_qla_host {
                struct list_head head;
                spinlock_t lock;
        } purex_list;
+       struct purex_item default_item;
 
        struct name_list_extended gnl;
        /* Count of active session/fcport */
@@ -5127,11 +5130,6 @@ typedef struct scsi_qla_host {
 #define DPORT_DIAG_IN_PROGRESS                 BIT_0
 #define DPORT_DIAG_CHIP_RESET_IN_PROGRESS      BIT_1
        uint16_t dport_status;
-
-       /* Must be last --ends in a flexible-array member. */
-       TRAILING_OVERLAP(struct purex_item, default_item, iocb,
-               uint8_t __default_item_iocb[QLA_DEFAULT_PAYLOAD_SIZE];
-       );
 } scsi_qla_host_t;
 
 struct qla27xx_image_status {
index 4559b490614d4b70f5cc2077787f421bb712eec6..c4c6b5c6658c0734f7ff68bcc31b33dde87296dd 100644 (file)
@@ -1077,17 +1077,17 @@ static struct purex_item *
 qla24xx_alloc_purex_item(scsi_qla_host_t *vha, uint16_t size)
 {
        struct purex_item *item = NULL;
+       uint8_t item_hdr_size = sizeof(*item);
 
        if (size > QLA_DEFAULT_PAYLOAD_SIZE) {
-               item = kzalloc(struct_size(item, iocb, size), GFP_ATOMIC);
+               item = kzalloc(item_hdr_size +
+                   (size - QLA_DEFAULT_PAYLOAD_SIZE), GFP_ATOMIC);
        } else {
                if (atomic_inc_return(&vha->default_item.in_use) == 1) {
                        item = &vha->default_item;
                        goto initialize_purex_header;
                } else {
-                       item = kzalloc(
-                               struct_size(item, iocb, QLA_DEFAULT_PAYLOAD_SIZE),
-                               GFP_ATOMIC);
+                       item = kzalloc(item_hdr_size, GFP_ATOMIC);
                }
        }
        if (!item) {
@@ -1127,16 +1127,17 @@ qla24xx_queue_purex_item(scsi_qla_host_t *vha, struct purex_item *pkt,
  * @vha: SCSI driver HA context
  * @pkt: ELS packet
  */
-static struct purex_item *
-qla24xx_copy_std_pkt(struct scsi_qla_host *vha, void *pkt)
+static struct purex_item
+*qla24xx_copy_std_pkt(struct scsi_qla_host *vha, void *pkt)
 {
        struct purex_item *item;
 
-       item = qla24xx_alloc_purex_item(vha, QLA_DEFAULT_PAYLOAD_SIZE);
+       item = qla24xx_alloc_purex_item(vha,
+                                       QLA_DEFAULT_PAYLOAD_SIZE);
        if (!item)
                return item;
 
-       memcpy(&item->iocb, pkt, QLA_DEFAULT_PAYLOAD_SIZE);
+       memcpy(&item->iocb, pkt, sizeof(item->iocb));
        return item;
 }
 
index 065f9bcca26f316a6e49a6109511042df97920a3..316594aa40cc5a9c70a6799fb1b1d36af116ccb4 100644 (file)
@@ -1308,7 +1308,7 @@ void qla2xxx_process_purls_iocb(void **pkt, struct rsp_que **rsp)
 
        ql_dbg(ql_dbg_unsol, vha, 0x2121,
               "PURLS OP[%01x] size %d xchg addr 0x%x portid %06x\n",
-              item->iocb[3], item->size, uctx->exchange_address,
+              item->iocb.iocb[3], item->size, uctx->exchange_address,
               fcport->d_id.b24);
        /* +48    0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
         * ----- -----------------------------------------------
index 98a5c105fdfd8249d021d0bb07cc98d241289376..9a2f328200abbf8ec3221dd9c6f9cf57231592de 100644 (file)
@@ -6459,10 +6459,9 @@ dealloc:
 void
 qla24xx_free_purex_item(struct purex_item *item)
 {
-       if (item == &item->vha->default_item) {
+       if (item == &item->vha->default_item)
                memset(&item->vha->default_item, 0, sizeof(struct purex_item));
-               memset(&item->vha->__default_item_iocb, 0, QLA_DEFAULT_PAYLOAD_SIZE);
-       } else
+       else
                kfree(item);
 }