Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Bryan Gurney <bgurney@redhat.com>
To: linux-nvme@lists.infradead.org, kbusch@kernel.org, hch@lst.de,
	sagi@grimberg.me, axboe@kernel.dk
Cc: james.smart@broadcom.com, njavali@marvell.com,
	linux-scsi@vger.kernel.org, hare@suse.de,
	linux-hardening@vger.kernel.org, kees@kernel.org,
	gustavoars@kernel.org, bgurney@redhat.com, jmeneghi@redhat.com,
	emilne@redhat.com
Subject: [PATCH RFC] scsi: qla2xxx: zero default_item last in qla24xx_free_purex_item
Date: Thu, 25 Sep 2025 13:02:23 -0400	[thread overview]
Message-ID: <20250925170223.18238-1-bgurney@redhat.com> (raw)
In-Reply-To: <fbbef12e-fc43-464f-b92d-f42f3692a46c@redhat.com>

In order to avoid a null pointer dereference, the vha->default_item
should be set to 0 last if the item pointer passed to the function
matches.

BUG: kernel NULL pointer dereference, address: 0000000000000936
...
RIP: 0010:qla24xx_free_purex_item+0x5e/0x90 [qla2xxx]
...
Call Trace:
 <TASK>
 qla24xx_process_purex_list+0xda/0x110 [qla2xxx]
 qla2x00_do_dpc+0x8ac/0xab0 [qla2xxx]
 ? __pfx_qla2x00_do_dpc+0x10/0x10 [qla2xxx]
 kthread+0xf9/0x240
 ? __pfx_kthread+0x10/0x10
 ret_from_fork+0xf1/0x110
 ? __pfx_kthread+0x10/0x10

Also use a local variable to avoid multiple de-referencing of the item.

Fixes: 6f4b10226b6b ("scsi: qla2xxx: Fix memcpy() field-spanning write issue")
Signed-off-by: Bryan Gurney <bgurney@redhat.com>
---
 drivers/scsi/qla2xxx/qla_os.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 98a5c105fdfd..7e28c7e9aa60 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -6459,9 +6459,11 @@ void qla24xx_process_purex_rdp(struct scsi_qla_host *vha,
 void
 qla24xx_free_purex_item(struct purex_item *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);
+	scsi_qla_host_t *base_vha = item->vha;
+
+	if (item == &base_vha->default_item) {
+		memset(&base_vha->__default_item_iocb, 0, QLA_DEFAULT_PAYLOAD_SIZE);
+		memset(&base_vha->default_item, 0, sizeof(struct purex_item));
 	} else
 		kfree(item);
 }
-- 
2.51.0



  parent reply	other threads:[~2025-09-25 17:04 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-13 20:07 [PATCH v9 0/8] nvme-fc: FPIN link integrity handling Bryan Gurney
2025-08-13 20:07 ` [PATCH v9 1/9] fc_els: use 'union fc_tlv_desc' Bryan Gurney
2025-08-13 20:07 ` [PATCH v9 2/9] nvme: add NVME_CTRL_MARGINAL flag Bryan Gurney
2025-08-18 12:07   ` Hannes Reinecke
2025-08-13 20:07 ` [PATCH v9 3/9] nvme-fc: marginal path handling Bryan Gurney
2025-08-13 20:07 ` [PATCH v9 4/9] nvme-fc: nvme_fc_fpin_rcv() callback Bryan Gurney
2025-08-13 20:07 ` [PATCH v9 5/9] lpfc: enable FPIN notification for NVMe Bryan Gurney
2025-08-13 20:07 ` [PATCH v9 6/9] qla2xxx: " Bryan Gurney
2025-08-13 20:07 ` [PATCH v9 7/9] nvme: sysfs: emit the marginal path state in show_state() Bryan Gurney
2025-08-13 20:07 ` [PATCH v9 8/9] nvme-multipath: queue-depth support for marginal paths Bryan Gurney
2025-08-18 12:08   ` Hannes Reinecke
2025-08-13 20:07 ` [PATCH v9 9/9] scsi: qla2xxx: Fix memcpy field-spanning write issue Bryan Gurney
2025-08-18 12:09   ` Hannes Reinecke
2025-08-20  2:13   ` Martin K. Petersen
2025-08-20  2:18 ` [PATCH v9 0/8] nvme-fc: FPIN link integrity handling Martin K. Petersen
2025-08-26  2:33 ` (subset) " Martin K. Petersen
2025-09-23 19:21   ` John Meneghini
2025-09-25  1:43     ` Martin K. Petersen
2025-09-25 13:07       ` [PATCH] Revert "scsi: qla2xxx: Fix memcpy() field-spanning write issue" John Meneghini
2025-09-25 13:38         ` Gustavo A. R. Silva
2025-09-25 14:18           ` John Meneghini
2025-09-25 14:30             ` Gustavo A. R. Silva
2025-09-25 17:02             ` Bryan Gurney [this message]
     [not found]               ` <e58d743b-a999-4e00-8f2e-31707744c5bb@embeddedor.com>
2025-09-25 18:43                 ` [PATCH RFC] scsi: qla2xxx: zero default_item last in qla24xx_free_purex_item Bryan Gurney
2025-09-25 18:54                   ` Gustavo A. R. Silva
2025-09-25 18:57         ` [PATCH] Revert "scsi: qla2xxx: Fix memcpy() field-spanning write issue" Gustavo A. R. Silva
2025-09-30  9:35           ` John Meneghini
2025-09-30 20:13             ` Martin K. Petersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250925170223.18238-1-bgurney@redhat.com \
    --to=bgurney@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=emilne@redhat.com \
    --cc=gustavoars@kernel.org \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=james.smart@broadcom.com \
    --cc=jmeneghi@redhat.com \
    --cc=kbusch@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=njavali@marvell.com \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox