From: Jens Axboe <axboe@kernel.dk>
To: Christoph Hellwig <hch@lst.de>, Chao Shi <coshi036@gmail.com>
Cc: Keith Busch <kbusch@kernel.org>, Sagi Grimberg <sagi@grimberg.me>,
linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org,
Sungwoo Kim <iam@sung-woo.kim>, Dave Tian <daveti@purdue.edu>,
Weidong Zhu <weizhu@fiu.edu>
Subject: Re: [PATCH] nvme: reject completions for requests that are not in flight
Date: Wed, 27 May 2026 09:02:36 -0600 [thread overview]
Message-ID: <19251352-237e-4aaf-93ff-86b3e43bed8c@kernel.dk> (raw)
In-Reply-To: <20260527141909.GA13578@lst.de>
On 5/27/26 8:19 AM, Christoph Hellwig wrote:
> On Fri, May 22, 2026 at 11:30:34AM -0400, Chao Shi wrote:
>> nvme_find_rq() resolves a device-supplied command id to a request with
>> blk_mq_tag_to_rq(), which returns whatever request last used that tag -
>> possibly one that is no longer in flight (freed, or never dispatched and
>> thus with a NULL rq->mq_hctx). Commit e7006de6c238 ("nvme: code
>> command_id with a genctr for use-after-free validation") guards against
>> this, but its generation counter is only 4 bits wide and can be matched
>> by a malfunctioning or malicious device replaying command ids. The
>> driver then completes a request that is not outstanding, dereferencing a
>> NULL rq->mq_hctx or double-completing a command:
>
> I don't think an intentionally malicious device is part of the threat
> model here. This was added to protect against buggy devices.
Malicious devices are explicitly NOT part of the linux threat model. If
this is a real device, I'd say go talk to whomever made it and get the
firmware fixed. If this is a "hardening" effort to protect against the
threat of malicious devices, then I don't think we should bother.
>> + * blk_mq_tag_to_rq() returns whatever request last used this tag, which
>> + * may no longer be in flight if the device reports a bogus command id.
>> + * Completing it would deref a NULL rq->mq_hctx or double-complete a
>> + * command; the 4-bit genctr below only narrows the window.
>> + */
>> + if (unlikely(blk_mq_rq_state(rq) != MQ_RQ_IN_FLIGHT)) {
>> + dev_err(nvme_req(rq)->ctrl->device,
>> + "completion for request %#x not in flight\n", tag);
>> + return NULL;
>> + }
>
> Although this check looks cheap enough that it should not hurt to add
> it. So I think this should be ok, but maybe respin with your planned
> commit message update.
Only for the right reasons, imho.
--
Jens Axboe
next prev parent reply other threads:[~2026-05-27 15:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-22 15:30 [PATCH] nvme: reject completions for requests that are not in flight Chao Shi
2026-05-25 20:27 ` Chao S
2026-05-27 14:19 ` Christoph Hellwig
2026-05-27 15:02 ` Jens Axboe [this message]
2026-05-27 15:00 ` Keith Busch
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=19251352-237e-4aaf-93ff-86b3e43bed8c@kernel.dk \
--to=axboe@kernel.dk \
--cc=coshi036@gmail.com \
--cc=daveti@purdue.edu \
--cc=hch@lst.de \
--cc=iam@sung-woo.kim \
--cc=kbusch@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
--cc=weizhu@fiu.edu \
/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