From: sashiko-bot@kernel.org
To: "Yehyeong Lee" <yhlee@isslab.korea.ac.kr>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH v4 2/2] nvme-fabrics: do not leave a timed-out command's id resolvable
Date: Wed, 02 Dec 2026 13:35:08 +0000 [thread overview]
Message-ID: <sashiko-outbox-245887@kernel.org> (raw)
In-Reply-To: <20261202131909.2556796-3-yhlee@isslab.korea.ac.kr>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] nvme-tcp: UAF and double completion via nvme_cid_to_rq() after
C2HData timeout
- [High] nvme-tcp: race with active io_work in
nvme_tcp_complete_timed_out()
--
commit 718cdfd33ac400884137a2b0ab0be73d96fee9e7
Author: Yehyeong Lee <yhlee@isslab.korea.ac.kr>
nvme-fabrics: do not leave a timed-out command's id resolvable
This commit increments the request generation counter in
nvmf_complete_timed_out_request() so that late responses arriving for an
abandoned command id are rejected by nvme_find_rq().
> diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h
> index caf5503d08332..2e3a4a5af2d44 100644
> --- a/drivers/nvme/host/fabrics.h
> +++ b/drivers/nvme/host/fabrics.h
> @@ -202,10 +202,19 @@ static inline char *nvmf_ctrl_subsysnqn(struct nvme_ctrl *ctrl)
> return ctrl->subsys->subnqn;
> }
>
> +/*
> + * This does not go through nvme_try_complete_req(), so advance the generation
> + * here: otherwise nvme_find_rq() keeps resolving the abandoned command id onto
> + * a request that is no longer in flight.
> + */
> static inline void nvmf_complete_timed_out_request(struct request *rq)
> {
> if (blk_mq_request_started(rq) && !blk_mq_request_completed(rq)) {
> - nvme_req(rq)->status = NVME_SC_HOST_ABORTED_CMD;
> + struct nvme_request *nr = nvme_req(rq);
> +
> + if (!(nr->ctrl->quirks & NVME_QUIRK_SKIP_CID_GEN))
> + nr->genctr++;
> + nr->status = NVME_SC_HOST_ABORTED_CMD;
> blk_mq_complete_request(rq);
> }
> }
[Severity: High]
Can an in-progress C2HData transfer bypass this generation increment via
nvme_cid_to_rq(), causing a use-after-free and double completion?
When a 24-byte C2HData PDU header arrives before the timeout (for example,
for an auth_receive command while NVME_TCP_Q_LIVE is not yet set),
nvme_tcp_handle_c2h_data() validates pdu->command_id with nvme_find_rq()
and sets queue->data_remaining, transitioning the queue to
NVME_TCP_RECV_DATA.
If the command times out before the payload or data digest arrives,
nvme_tcp_complete_timed_out() increments nr->genctr and completes rq,
freeing its bio, without resetting queue->data_remaining or
queue->ddgst_remaining (and without stopping queue->io_work when
NVME_TCP_Q_LIVE is clear). When the remaining bytes arrive,
nvme_tcp_recv_data() and nvme_tcp_recv_ddgst() resolve pdu->command_id
through nvme_cid_to_rq(), which strips the generation bits without
checking nr->genctr, writing into the freed bio and calling
nvme_tcp_end_request() a second time if NVME_TCP_F_DATA_SUCCESS is set.
[Severity: High]
Can nvmf_complete_timed_out_request() race with an active queue->io_work
when NVME_TCP_Q_LIVE is not set?
During in-band authentication, NVME_TCP_Q_LIVE is not yet set, so
nvme_tcp_stop_queue_nowait() skips __nvme_tcp_stop_queue() and leaves
queue->io_work running concurrently with nvme_tcp_complete_timed_out():
CPU0 (timeout) CPU1 (queue->io_work)
nvme_tcp_complete_timed_out()
nvme_tcp_stop_queue()
/* NVME_TCP_Q_LIVE is 0 */
nvme_tcp_drop_queue_ref()
nvme_tcp_try_recv()
nvme_tcp_handle_r2t()
nvme_find_rq() /* old genctr matches */
llist_add(&req->lentry,
&queue->req_list)
nvmf_complete_timed_out_request()
nr->genctr++
blk_mq_complete_request(rq)
nvme_tcp_try_send()
/* walks freed bio <-- use-after-free */
Similarly, if nvme_tcp_process_nvme_cqe() (or nvme_rdma_process_nvme_rsp()
before NVME_RDMA_Q_LIVE is set) passes nvme_find_rq() just before CPU0
increments nr->genctr, nvme_try_complete_req() and
nvmf_complete_timed_out_request() race without synchronization on
nr->genctr++ and rq->state and both complete the request.
In addition, nvme_tcp_stop_queue_nowait() clears queue->tls_enabled and
NVME_TCP_Q_IO_CPU_SET outside the test_and_clear_bit(NVME_TCP_Q_LIVE)
check, leaving queue->tls_enabled false if an authentication retry
recovers on the same TLS socket.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202131909.2556796-1-yhlee@isslab.korea.ac.kr?part=2
prev parent reply other threads:[~2026-12-02 13:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 13:19 [PATCH v4 0/2] nvme-tcp: do not refer to a timed-out request after completing it Yehyeong Lee
2026-12-02 13:19 ` [PATCH v4 1/2] nvme-tcp: drop the queue's reference to a timed-out request Yehyeong Lee
2026-12-02 13:48 ` sashiko-bot
2026-12-02 13:19 ` [PATCH v4 2/2] nvme-fabrics: do not leave a timed-out command's id resolvable Yehyeong Lee
2026-12-02 13:35 ` sashiko-bot [this message]
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=sashiko-outbox-245887@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yhlee@isslab.korea.ac.kr \
/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