mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
To: Ram Vegesna <ram.vegesna@broadcom.com>,
	"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	"Martin K. Petersen" <mkp@kernel.org>
Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] scsi: efct: Fix potential use-after-free on RQ setup failure
Date: Thu, 12 Nov 2026 21:58:59 +0800	[thread overview]
Message-ID: <20261112-88a3a7ff32-scsi-efct@mail.sdu.edu.cn> (raw)

Receive queues are linked to their completion queues before all tracker
allocations succeed. On failure, the RQs are freed but CQ teardown still
walks their list nodes. Publish the RQs only after all allocations succeed.

This issue was found by our static analysis tool under development.

Fixes: e10fc2335980 ("scsi: elx: efct: Hardware queue creation and deletion")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 drivers/scsi/elx/efct/efct_hw_queues.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/elx/efct/efct_hw_queues.c b/drivers/scsi/elx/efct/efct_hw_queues.c
index 3c27f927f96c..784eadabd3aa 100644
--- a/drivers/scsi/elx/efct/efct_hw_queues.c
+++ b/drivers/scsi/elx/efct/efct_hw_queues.c
@@ -362,15 +362,18 @@ efct_hw_new_rq_set(struct hw_cq *cqs[], struct hw_rq *rqs[],
 	}
 
 	for (i = 0; i < num_rq_pairs; i++) {
-		hw->hw_rq[rqs[i]->instance] = rqs[i];
-		INIT_LIST_HEAD(&rqs[i]->list_entry);
-		list_add_tail(&rqs[i]->list_entry, &cqs[i]->q_list);
 		size = sizeof(struct efc_hw_sequence *) * rqs[i]->entry_count;
 		rqs[i]->rq_tracker = kzalloc(size, GFP_KERNEL);
 		if (!rqs[i]->rq_tracker)
 			goto error;
 	}
 
+	for (i = 0; i < num_rq_pairs; i++) {
+		hw->hw_rq[rqs[i]->instance] = rqs[i];
+		INIT_LIST_HEAD(&rqs[i]->list_entry);
+		list_add_tail(&rqs[i]->list_entry, &cqs[i]->q_list);
+	}
+
 	return 0;
 
 error:

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

                 reply	other threads:[~2026-11-12 13:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261112-88a3a7ff32-scsi-efct@mail.sdu.edu.cn \
    --to=liguangshuo@mail.sdu.edu.cn \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@kernel.org \
    --cc=ram.vegesna@broadcom.com \
    --cc=target-devel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®