All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6] nvme-tcp: do not refer to a timed-out request after completing it
@ 2026-12-05 11:47 Yehyeong Lee
  2026-12-05 12:27 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Yehyeong Lee @ 2026-12-05 11:47 UTC (permalink / raw)
  To: kbusch, hch, sagi; +Cc: linux-nvme, axboe, linux-kernel

nvme_tcp_error_recovery() reaches RESETTING only from NEW or LIVE, so a
command that times out while the controller is CONNECTING is completed in
place: nvme_tcp_complete_timed_out() stops the queue and ends the request,
freeing its bio.  The request is not taken away from the queue, and a
queue that never reached NVME_TCP_Q_LIVE - the one carrying a connect or
an in-band authentication command - is not stopped at all, so the send
references outlive the completion, a C2HData header leaves the receive
context aimed at the request, and nvme_find_rq() still resolves its
command id, nothing on this path having advanced the generation.

The send references alone suffice: the completion unblocks the reconnect,
the controller goes LIVE while this queue is still stopped, and the send
path walks the freed bio:

  BUG: KASAN: slab-use-after-free in nvme_tcp_try_send_data+0xb12/0xd10
  Read of size 8 at addr ffff888009432b70 by task kworker/0:1H/105

  Workqueue: nvme_tcp_wq nvme_tcp_io_work
  Call Trace:
   <TASK>
   dump_stack_lvl+0x53/0x70
   print_report+0xd0/0x640
   kasan_report+0xce/0x100
   nvme_tcp_try_send_data+0xb12/0xd10
   nvme_tcp_try_send+0x856/0x1140
   nvme_tcp_io_work+0x125/0x720
   process_one_work+0x6bb/0x1090
   worker_thread+0x45b/0xd10
   kthread+0x2c8/0x3b0
   ret_from_fork+0x36e/0x5a0
   ret_from_fork_asm+0x1a/0x30
   </TASK>

  Allocated by task 135:
   kasan_save_stack+0x33/0x60
   kasan_save_track+0x14/0x40
   __kasan_slab_alloc+0x6e/0x70
   kmem_cache_alloc_noprof+0x10e/0x340
   bio_alloc_bioset+0x214/0x1130
   blkdev_direct_IO+0xd6c/0x1900
   blkdev_write_iter+0x756/0xdc0
   vfs_write+0x5d2/0xcd0
   ksys_write+0xf7/0x1c0
   do_syscall_64+0xdf/0x4c0
   entry_SYSCALL_64_after_hwframe+0x77/0x7f

  Freed by task 105:
   kasan_save_stack+0x33/0x60
   kasan_save_track+0x14/0x40
   kasan_save_free_info+0x3b/0x60
   __kasan_slab_free+0x57/0x80
   kmem_cache_free+0x1b8/0x380
   mempool_free+0xbd/0x110
   bio_free+0x1ab/0x250
   blk_update_request+0x229/0x10e0
   blk_mq_end_request+0x48/0x70
   nvme_tcp_timeout+0x7d3/0xc20
   blk_mq_handle_expired+0x256/0x420
   bt_iter+0x24b/0x340
   blk_mq_queue_tag_busy_iter+0x587/0x12a0
   blk_mq_timeout_work+0x39e/0x4e0
   process_one_work+0x6bb/0x1090
   worker_thread+0x45b/0xd10
   kthread+0x2c8/0x3b0
   ret_from_fork+0x36e/0x5a0
   ret_from_fork_asm+0x1a/0x30

Stopping the queue is not a fence: it keeps its data_ready callback, so
io_work is queued again right after the cancel, and nvme_tcp_poll() guards
only on the bit just cleared.  Retire the command id, drop the send
references and the receive context, and complete the request under
queue_lock, send_mutex and the socket lock, the order nvme_tcp_try_send()
already uses.  queue_lock is outermost because nvme_tcp_free_queue()
clears queue->sock under it and frees queue->pdu once it is dropped, so
the receive context is only read while the socket is there.  A retry is a
new dispatch through nvme_setup_cmd(), which recomputes the id.

nvme-rdma has the same timeout-completion shape - commit 0475a8dcbcee92
("nvme-rdma: fix timeout handler") is this handler's twin - and the same
latent issue; it is not exercised here and will be addressed in a
separate, rdma-tested patch.

Fixes: 236187c4ed19 ("nvme-tcp: fix timeout handler")
Fixes: e4fdb2b167ed ("nvme: increment request genctr on completion")
Cc: stable@vger.kernel.org
Signed-off-by: Yehyeong Lee <yhlee@isslab.korea.ac.kr>
---
Link: https://lore.kernel.org/linux-nvme/20261204135345.2994739-1-yhlee@isslab.korea.ac.kr/ [v5]

Changes since v5:

- One patch instead of two, and it touches one file: drivers/nvme/host/tcp.c.
  The helper the second patch used to call now ships with its only caller.
- The generation advance moved out of the shared fabrics helper into a static
  helper inside nvme-tcp, so nvmf_complete_timed_out_request() is mainline
  byte for byte, fabrics.h has no diff at all, and nvme-rdma, nvme-fc and
  nvmet-loop are untouched - rdma.o builds identical.  A timed-out command
  now advances the generation once rather than twice.
- Retire the command id, drop the send references, drop the receive context
  and complete the request now happen together under queue_lock, send_mutex
  and the socket lock; the explicit cancel_work_sync() is gone.
- nvme_tcp_drop_queue_ref() no longer takes send_mutex; the caller holds it
  and the helper asserts that.
- The socket is read under queue_lock rather than cached across two sleeping
  calls, and the receive context is left alone when the socket is already
  NULL, since nvme_tcp_free_queue() frees queue->pdu once that lock is
  dropped.
- Code comments cut back to two: the queue->pdu lifetime rule above the NULL
  socket guard, and the one-line note on why a single entry cannot be
  unlinked from a lockless list.  The reasoning that was duplicated in
  comments is in the changelog above.
- The full report is kept in the changelog rather than trimmed, as requested
  on v5.
- Fixes: names the handler (236187c4ed19) and the commit after which an
  abandoned id stopped self-invalidating (e4fdb2b167ed).  v5 named
  93ba75c90524, which only factored the shared helper out.

Earlier revisions:

v1: https://lore.kernel.org/linux-nvme/20261129031537.1993449-1-yhlee@isslab.korea.ac.kr/
v2: https://lore.kernel.org/linux-nvme/20261130104426.2140231-1-yhlee@isslab.korea.ac.kr/
v3: https://lore.kernel.org/linux-nvme/20261201113916.2322397-1-yhlee@isslab.korea.ac.kr/
v4: https://lore.kernel.org/linux-nvme/20261202131909.2556796-1-yhlee@isslab.korea.ac.kr/
v5: https://lore.kernel.org/linux-nvme/20261204135345.2994739-1-yhlee@isslab.korea.ac.kr/

Earlier completion-side proposals in this area:

[1] https://lore.kernel.org/linux-nvme/20261103-nvme-double-cmpl-uaf-blk-mq-v1-1-b10fea474423@igalia.com/
[2] https://lore.kernel.org/linux-nvme/20260913124053.86565-1-mateusz.nowicki@posteo.net/

 drivers/nvme/host/tcp.c | 66 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 64 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 62a594b8ab9bfa..41c98750253057 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -3031,13 +3031,75 @@ static void nvme_tcp_submit_async_event(struct nvme_ctrl *arg)
 	nvme_tcp_queue_request(&ctrl->async_req, true);
 }
 
+static void nvme_tcp_drop_queue_ref(struct nvme_tcp_request *req)
+{
+	struct nvme_tcp_queue *queue = req->queue;
+
+	lockdep_assert_held(&queue->send_mutex);
+
+	if (queue->request == req)
+		queue->request = NULL;
+
+	/* a single entry cannot be unlinked from a lockless list */
+	nvme_tcp_process_req_list(queue);
+	if (!list_empty(&req->entry))
+		list_del_init(&req->entry);
+	init_llist_node(&req->lentry);
+}
+
+static void nvme_tcp_drop_recv_ctx(struct nvme_tcp_request *req)
+{
+	struct nvme_tcp_queue *queue = req->queue;
+	struct nvme_tcp_data_pdu *pdu = (void *)queue->pdu;
+
+	if (nvme_tcp_recv_state(queue) == NVME_TCP_RECV_PDU)
+		return;
+
+	if (nvme_cid_to_rq(nvme_tcp_tagset(queue), pdu->command_id) !=
+	    blk_mq_rq_from_pdu(req))
+		return;
+
+	nvme_tcp_init_recv_ctx(queue);
+}
+
+static void nvme_tcp_retire_command_id(struct request *rq)
+{
+	struct nvme_request *nr = nvme_req(rq);
+
+	if (!(nr->ctrl->quirks & NVME_QUIRK_SKIP_CID_GEN))
+		nr->genctr++;
+}
+
 static void nvme_tcp_complete_timed_out(struct request *rq)
 {
 	struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq);
-	struct nvme_ctrl *ctrl = &req->queue->ctrl->ctrl;
+	struct nvme_tcp_queue *queue = req->queue;
+	struct nvme_ctrl *ctrl = &queue->ctrl->ctrl;
+	struct sock *sk;
+
+	nvme_tcp_stop_queue(ctrl, nvme_tcp_queue_id(queue));
 
-	nvme_tcp_stop_queue(ctrl, nvme_tcp_queue_id(req->queue));
+	mutex_lock(&queue->queue_lock);
+	mutex_lock(&queue->send_mutex);
+	sk = queue->sock ? queue->sock->sk : NULL;
+	if (sk)
+		lock_sock(sk);
+
+	if (blk_mq_request_started(rq) && !blk_mq_request_completed(rq))
+		nvme_tcp_retire_command_id(rq);
+	nvme_tcp_drop_queue_ref(req);
+	/*
+	 * nvme_tcp_free_queue() frees queue->pdu once it has dropped
+	 * queue_lock, so only read the receive context while sock is set.
+	 */
+	if (sk)
+		nvme_tcp_drop_recv_ctx(req);
 	nvmf_complete_timed_out_request(rq);
+
+	if (sk)
+		release_sock(sk);
+	mutex_unlock(&queue->send_mutex);
+	mutex_unlock(&queue->queue_lock);
 }
 
 static enum blk_eh_timer_return nvme_tcp_timeout(struct request *rq)
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v6] nvme-tcp: do not refer to a timed-out request after completing it
  2026-12-05 11:47 [PATCH v6] nvme-tcp: do not refer to a timed-out request after completing it Yehyeong Lee
@ 2026-12-05 12:27 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-05 12:27 UTC (permalink / raw)
  To: Yehyeong Lee; +Cc: linux-nvme

Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] nvme-tcp: UAF on sock and pdu racing with
  nvme_tcp_alloc_queue()
- [High] nvme-tcp: RX/TX PDU framing corruption after dropping timed-out
  request
- [High] nvme-tcp: double completion and retry abort from stop_queue
  before locks
- [Medium] nvme-tcp: list corruption in nvme_tcp_drop_queue_ref() on
  stale req->entry
- [Medium] nvme-tcp: dangling queue->sock on sock_alloc_file() failure
- [Medium] nvme-tcp: req_list self-loop in nvme_tcp_drop_queue_ref() on
  retry
- [Medium] nvme-tcp: nvme_tcp_drop_queue_ref() strands requests without
  io_work
- [Low] nvme-tcp: inaccurate commit message claims on data_ready and
  nvme_tcp_poll()
--

commit aea7ab2f5094c7c6483c1a10b23c0d5ee1788322
Author: Yehyeong Lee <yhlee@isslab.korea.ac.kr>

nvme-tcp: do not refer to a timed-out request after completing it

This commit updates nvme_tcp_complete_timed_out() to retire the timed-out
request's command ID, drop its send queue references, and reset the
receive context under queue_lock, send_mutex, and the socket lock before
completing the request.

> Stopping the queue is not a fence: it keeps its data_ready callback, so
> io_work is queued again right after the cancel, and nvme_tcp_poll() guards
> only on the bit just cleared.

[Severity: Low]
Is this description of __nvme_tcp_stop_queue() and nvme_tcp_poll()
accurate?

__nvme_tcp_stop_queue() calls nvme_tcp_restore_sock_ops() before
cancel_work_sync(&queue->io_work), so a stopped queue does not keep its
nvme_tcp_data_ready callback.  Instead, a non-LIVE queue skips
__nvme_tcp_stop_queue() altogether, and submission paths can still queue
io_work.

Similarly, nvme_tcp_poll() holds queue->queue_lock across both the
NVME_TCP_Q_LIVE check and nvme_tcp_try_recv(), so clearing NVME_TCP_Q_LIVE
under queue->queue_lock in nvme_tcp_stop_queue_nowait() already fences it.

> diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
> index 8a5040b3cb7ac..4e8de7a30f7c2 100644
> --- a/drivers/nvme/host/tcp.c
> +++ b/drivers/nvme/host/tcp.c
> @@ -3031,13 +3031,75 @@ static void nvme_tcp_submit_async_event(struct nvme_ctrl *arg)
>  	nvme_tcp_queue_request(&ctrl->async_req, true);
>  }
>  
> +static void nvme_tcp_drop_queue_ref(struct nvme_tcp_request *req)
> +{
> +	struct nvme_tcp_queue *queue = req->queue;
> +
> +	lockdep_assert_held(&queue->send_mutex);
> +
> +	if (queue->request == req)
> +		queue->request = NULL;
> +
> +	/* a single entry cannot be unlinked from a lockless list */
> +	nvme_tcp_process_req_list(queue);

[Severity: Medium]
Can draining queue->req_list here strand other requests on
queue->send_list without scheduling queue->io_work?

nvme_tcp_process_req_list() moves all pending requests from req_list onto
send_list, and this function only unlinks req.  Previously, only
nvme_tcp_io_work() and inline nvme_tcp_queue_request() took send_mutex,
and both ensured io_work remained scheduled when work was left.

CPU0 (timeout)                    CPU1 (nvme_tcp_io_work)
mutex_lock(&queue->send_mutex)
                                  mutex_trylock(&queue->send_mutex) -> 0
nvme_tcp_process_req_list()
  /* moves req2 to send_list */
                                  nvme_tcp_try_recv() -> 0
                                  /* got_send_mutex == false, skips
                                   * pending check and exits */
mutex_unlock(&queue->send_mutex)  <-- req2 stranded on send_list

The same stall occurs with batched dispatch (bd->last == false), where
nvme_tcp_commit_rqs() only checks !llist_empty(&queue->req_list) and
misses requests already moved to send_list.  Other commands on the queue
then sit until their blk-mq timeout expires.  Scheduling io_work when
nvme_tcp_queue_has_pending(queue) is true after dropping req would avoid
stranding them.

> +	if (!list_empty(&req->entry))
> +		list_del_init(&req->entry);
> +	init_llist_node(&req->lentry);
> +}

[Severity: Medium]
Can init_llist_node(&req->lentry) create a self-loop in queue->req_list if
a retried request is concurrently re-dispatched?

For a retryable command (such as an auth command submitted with
NVME_SUBMIT_RETRY), a concurrent completion can requeue rq via
__blk_mq_requeue_request(), which resets rq->state to MQ_RQ_IDLE and
clears RQF_TIMED_OUT without waiting for bt_iter() to drop rq->ref.
nvme_tcp_queue_rq() can then push req->lentry onto queue->req_list without
holding queue_lock, send_mutex, or the socket lock:

CPU0 (timeout)                    CPU1 (retry re-dispatch)
nvme_tcp_process_req_list()
                                  nvme_tcp_queue_rq(rq)
                                    nvme_tcp_queue_request(req)
                                      llist_add(&req->lentry, &req_list)
init_llist_node(&req->lentry)     <-- req->lentry.next = &req->lentry

The next nvme_tcp_process_req_list() walks req->lentry.next in an infinite
loop while holding queue->send_mutex, locking up nvme_tcp_wq and
corrupting queue->send_list.  If llist_add() lands after
nvme_tcp_drop_queue_ref() instead, completing rq leaves req->lentry on
req_list after its bio is freed.

> +static void nvme_tcp_drop_recv_ctx(struct nvme_tcp_request *req)
> +{
> +	struct nvme_tcp_queue *queue = req->queue;
> +	struct nvme_tcp_data_pdu *pdu = (void *)queue->pdu;
> +
> +	if (nvme_tcp_recv_state(queue) == NVME_TCP_RECV_PDU)
> +		return;
> +
> +	if (nvme_cid_to_rq(nvme_tcp_tagset(queue), pdu->command_id) !=
> +	    blk_mq_rq_from_pdu(req))
> +		return;
> +
> +	nvme_tcp_init_recv_ctx(queue);
> +}

[Severity: High]
Does resetting the receive context mid-C2HData or mid-DDGST without
disabling reads or shutting down the socket desynchronize PDU framing?

When an auth_send or auth_receive command times out during
NVME_CTRL_CONNECTING, NVME_TCP_Q_LIVE is not set yet, so
nvme_tcp_stop_queue_nowait() skips __nvme_tcp_stop_queue().  The socket
stays open with callbacks armed and queue->rd_enabled set to true.

Calling nvme_tcp_init_recv_ctx() here discards data_remaining and
ddgst_remaining without draining the remaining bytes from the TCP stream,
so trailing payload or digest bytes are parsed by nvme_tcp_recv_pdu() as
new PDU headers.

On the send side, clearing queue->request in nvme_tcp_drop_queue_ref()
similarly abandons a partially sent PDU on the still-open socket; because
nvme_auth_submit() sets NVME_SUBMIT_RETRY and __nvme_check_ready() allows
auth commands while CONNECTING, the retried command is spliced into the
middle of the truncated PDU.  Even on a previously LIVE queue,
kernel_sock_shutdown() leaves already-queued skbs in sk_receive_queue and
keeps queue->rd_enabled true.

[ ... ]

>  static void nvme_tcp_complete_timed_out(struct request *rq)
>  {
>  	struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq);
> -	struct nvme_ctrl *ctrl = &req->queue->ctrl->ctrl;
> +	struct nvme_tcp_queue *queue = req->queue;
> +	struct nvme_ctrl *ctrl = &queue->ctrl->ctrl;
> +	struct sock *sk;
>  
> -	nvme_tcp_stop_queue(ctrl, nvme_tcp_queue_id(req->queue));
> +	nvme_tcp_stop_queue(ctrl, nvme_tcp_queue_id(queue));
> +
> +	mutex_lock(&queue->queue_lock);
> +	mutex_lock(&queue->send_mutex);
> +	sk = queue->sock ? queue->sock->sk : NULL;
> +	if (sk)
> +		lock_sock(sk);

[Severity: Medium]
Can reading queue->sock without checking NVME_TCP_Q_ALLOCATED dereference
a dangling pointer left by a failed sock_alloc_file()?

In nvme_tcp_alloc_queue(), sock_create_kern() stores the socket in
queue->sock before calling sock_alloc_file():

drivers/nvme/host/tcp.c:nvme_tcp_alloc_queue() {
	...
	sock_file = sock_alloc_file(queue->sock, O_CLOEXEC, NULL);
	if (IS_ERR(sock_file))
		return PTR_ERR(sock_file);
	...
}

On failure, sock_alloc_file() calls sock_release(sock) and frees
queue->sock, but nvme_tcp_alloc_queue() returns without clearing
queue->sock to NULL.  Because other readers of queue->sock gate on
NVME_TCP_Q_ALLOCATED or NVME_TCP_Q_LIVE, this unchecked read exposes a
use-after-free on struct socket.

> +	if (blk_mq_request_started(rq) && !blk_mq_request_completed(rq))
> +		nvme_tcp_retire_command_id(rq);

[Severity: High]
Can calling nvme_tcp_stop_queue() before taking the locks and checking
rq->state with two separate loads cause a double completion or abort a
freshly re-dispatched retry?

__nvme_tcp_stop_queue() calls kernel_sock_shutdown(SHUT_RDWR) without
queue->send_mutex before cancel_work_sync(&queue->io_work), and
nvme_tcp_wait_queue() then sleeps up to 100 ms while req is still on the
send path.  A concurrent nvme_tcp_try_send() hits -EPIPE and completes
req via nvme_tcp_fail_request() -> nvme_tcp_end_request().

CPU0 (timeout)                    CPU1 (send / completion)
nvme_tcp_stop_queue()
  kernel_sock_shutdown()
                                  nvme_tcp_try_send() -> -EPIPE
                                    nvme_tcp_fail_request(req)
                                      blk_mq_complete_request_remote()
                                        /* rq->state = MQ_RQ_COMPLETE */
blk_mq_request_started(rq) -> 1
                                      blk_mq_free_request(rq)
                                        /* rq->state = MQ_RQ_IDLE */
!blk_mq_request_completed(rq) -> 1
nvmf_complete_timed_out_request() <-- double completion

Because blk_mq_free_request() resets rq->state to MQ_RQ_IDLE without
waiting for bt_iter() to drop rq->ref, the two-load check in both this
guard and nvmf_complete_timed_out_request() can pass and complete rq a
second time, prematurely dropping rq->ref.  If the concurrent
NVME_SC_HOST_PATH_ERROR instead triggers nvme_retry_req() while
nvme_tcp_wait_queue() sleeps, blk_mq_requeue_work() can re-dispatch rq
back to MQ_RQ_IN_FLIGHT, and this handler then retires, strips, and aborts
the new retry.

> +	nvme_tcp_drop_queue_ref(req);

[Severity: Medium]
Can calling nvme_tcp_drop_queue_ref(req) unconditionally corrupt
queue->send_list after the request was cancelled and the queue
reallocated?

Neither ctrl->fabrics_q nor ctrl->connect_q is drained with
blk_sync_queue() during teardown.  When teardown cancels a timed-out
request on one of those queues via nvme_cancel_admin_tagset() or
nvme_cancel_tagset(), nvme_cancel_request() completes rq without unlinking
req->entry from queue->send_list.

CPU0 (timeout)                    CPU1 (teardown / reconnect)
nvme_tcp_stop_queue()
                                  nvme_cancel_request(rq)
                                    /* req->entry still linked */
                                  nvme_tcp_free_queue()
                                  nvme_tcp_alloc_queue()
                                    INIT_LIST_HEAD(&queue->send_list)
mutex_lock(&queue->send_mutex)
nvme_tcp_drop_queue_ref(req)
  list_del_init(&req->entry)      <-- writes into new send_list / peer

Because nvme_tcp_alloc_queue() reinitializes queue->send_list without
send_mutex or detaching orphaned entries, req->entry still holds non-self
pointers into the reinitialized list or a reused sibling request, so
list_del_init() corrupts the active send_list.

> +	/*
> +	 * nvme_tcp_free_queue() frees queue->pdu once it has dropped
> +	 * queue_lock, so only read the receive context while sock is set.
> +	 */
> +	if (sk)
> +		nvme_tcp_drop_recv_ctx(req);

[Severity: High]
Does checking only queue->sock under queue_lock guarantee that sk and
queue->pdu are valid and initialized?

Because ctrl->fabrics_q and ctrl->connect_q are not synced with
blk_sync_queue() during teardown, a lingering nvme_tcp_complete_timed_out()
can overlap nvme_tcp_free_queue() and an immediate nvme_tcp_alloc_queue()
during reconnect, reset, or secure concatenation restart.
nvme_tcp_alloc_queue() never holds queue->queue_lock or queue->send_mutex:

CPU0 (timeout)                    CPU1 (nvme_tcp_alloc_queue)
                                  /* queue->pdu still dangling from
                                   * prior nvme_tcp_free_queue() */
                                  sock_create_kern(..., &queue->sock)
                                  queue->pdu_remaining = 0
                                  queue->ddgst_remaining = 0
mutex_lock(&queue->queue_lock)
sk = queue->sock->sk
lock_sock(sk)
nvme_tcp_drop_recv_ctx(req)
  /* state == NVME_TCP_RECV_DATA */
  pdu->command_id                 <-- use-after-free on queue->pdu

Because nvme_tcp_recv_state() returns NVME_TCP_RECV_DATA whenever
pdu_remaining and ddgst_remaining are 0, nvme_tcp_drop_recv_ctx()
dereferences pdu->command_id on the freed queue->pdu (or NULL on initial
allocation).

Two more windows open during nvme_tcp_alloc_queue(): after kmalloc()
allocates queue->pdu (unzeroed) and across blocking connect, TLS, and
ICResp calls before nvme_tcp_start_queue() initializes the receive
context, pdu->command_id reads uninitialized memory and lock_sock(sk) can
race with nvme_tcp_reclassify_socket().  On the err_rcv_pdu and err_sock
error paths, nvme_tcp_alloc_queue() frees queue->pdu and calls
__fput_sync(queue->sock->file) without queue_lock, causing a
use-after-free on both struct sock and queue->pdu.

Gating on NVME_TCP_Q_ALLOCATED (and bailing out when rq is already
completed) or synchronizing nvme_tcp_alloc_queue() with queue_lock would
prevent racing with allocation and teardown.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205114759.3239590-1-yhlee@isslab.korea.ac.kr?part=1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-05 12:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 11:47 [PATCH v6] nvme-tcp: do not refer to a timed-out request after completing it Yehyeong Lee
2026-12-05 12:27 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.