From: kensanya@163.com
To: bvanassche@acm.org, jgg@ziepe.ca, leon@kernel.org
Cc: linux-rdma@vger.kernel.org, target-devel@vger.kernel.org,
linux-kernel@vger.kernel.org, TanZheng <tanzheng@kylinos.cn>
Subject: [PATCH] RDMA/srpt: fix NULL deref when sending BUSY before target_init_cmd()
Date: Mon, 20 Jul 2026 10:59:41 +0800 [thread overview]
Message-ID: <20260720025941.69809-1-kensanya@163.com> (raw)
From: TanZheng <tanzheng@kylinos.cn>
If srpt_get_desc_tbl() fails, srpt_handle_cmd() jumps to
target_send_busy() before target_init_cmd() has set cmd->se_tfo.
target_send_busy() then dereferences a NULL se_tfo.
Call target_init_cmd() first with placeholder data_length and
data_direction, parse the descriptor table next, then fill in the
real data_length. That way target_send_busy() is safe if parsing
fails.
Fixes: 8b8807b9e982 ("scsi: RDMA/srpt: Fix handling of command / TMR submission failure")
Link: https://lore.kernel.org/all/20260717025402.64054-1-kensanya@163.com/
Suggested-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: TanZheng <tanzheng@kylinos.cn>
---
drivers/infiniband/ulp/srpt/ib_srpt.c | 31 ++++++++++++++++++---------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index f66cfd70c263..379718453a7d 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -1558,8 +1558,8 @@ static void srpt_handle_cmd(struct srpt_rdma_ch *ch,
struct srp_cmd *srp_cmd;
struct scatterlist *sg = NULL;
unsigned sg_cnt = 0;
- u64 data_len;
- enum dma_data_direction dir;
+ u64 data_len = 0;
+ enum dma_data_direction dir = DMA_NONE;
int rc;
BUG_ON(!send_ioctx);
@@ -1584,6 +1584,20 @@ static void srpt_handle_cmd(struct srpt_rdma_ch *ch,
break;
}
+ /*
+ * Before calling srpt_get_desc_tbl(), call target_init_cmd() first
+ * to set cmd->se_tfo and use target_send_busy(). The data_length
+ * will be filled after the successful call of srpt_get_desc_tbl().
+ */
+ rc = target_init_cmd(cmd, ch->sess, &send_ioctx->sense_data[0],
+ scsilun_to_int(&srp_cmd->lun), 0 /* data_len */,
+ TCM_SIMPLE_TAG, DMA_NONE, TARGET_SCF_ACK_KREF);
+ if (rc != 0) {
+ pr_debug("target_init_cmd() returned %d for tag %#llx\n", rc,
+ srp_cmd->tag);
+ goto busy;
+ }
+
rc = srpt_get_desc_tbl(recv_ioctx, send_ioctx, srp_cmd, &dir,
&sg, &sg_cnt, &data_len, ch->imm_data_offset);
if (rc) {
@@ -1594,14 +1608,11 @@ static void srpt_handle_cmd(struct srpt_rdma_ch *ch,
goto busy;
}
- rc = target_init_cmd(cmd, ch->sess, &send_ioctx->sense_data[0],
- scsilun_to_int(&srp_cmd->lun), data_len,
- TCM_SIMPLE_TAG, dir, TARGET_SCF_ACK_KREF);
- if (rc != 0) {
- pr_debug("target_submit_cmd() returned %d for tag %#llx\n", rc,
- srp_cmd->tag);
- goto busy;
- }
+ /*
+ * Replace the placeholder length from target_init_cmd(). Direction
+ * was already set inside srpt_get_desc_tbl() for srpt_alloc_rw_ctxs().
+ */
+ cmd->data_length = data_len;
if (target_submit_prep(cmd, srp_cmd->cdb, sg, sg_cnt, NULL, 0, NULL, 0,
GFP_KERNEL))
--
2.25.1
next reply other threads:[~2026-07-20 3:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 2:59 kensanya [this message]
2026-07-20 16:31 ` [PATCH] RDMA/srpt: fix NULL deref when sending BUSY before target_init_cmd() Bart Van Assche
2026-07-22 1:52 ` kensanya
2026-07-22 18:10 ` Bart Van Assche
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=20260720025941.69809-1-kensanya@163.com \
--to=kensanya@163.com \
--cc=bvanassche@acm.org \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=tanzheng@kylinos.cn \
--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