All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nilay Shroff" <nilay@linux.ibm.com>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH v2 07/22] nvmet: add context annotation for nvmet_ns::size
Date: Wed, 18 Nov 2026 07:50:07 +0000	[thread overview]
Message-ID: <sashiko-outbox-220364@kernel.org> (raw)
In-Reply-To: <20261118073505.288910-8-nilay@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] nvmet: double READ_ONCE() in nvmet_file_check_lba_range() can
  underflow
--

commit d3bcca86a53dabf9c0c2d63509a67010aa5e3ea3
Author: Nilay Shroff <nilay@linux.ibm.com>

nvmet: add context annotation for nvmet_ns::size

This commit annotates nvmet_ns::size with __guarded_by(&subsys->lock),
introduces nvmet_ns_size() using data_race(READ_ONCE()) for lockless reads,
and pairs those reads with WRITE_ONCE() on updates.

> diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c
> index e1e02f5f5efb1..c87de131037d4 100644
> --- a/drivers/nvme/target/io-cmd-file.c
> +++ b/drivers/nvme/target/io-cmd-file.c
[ ... ]
> @@ -123,7 +123,8 @@ static bool nvmet_file_check_lba_range(struct nvmet_req *req, u64 slba,
>  	u64 pos64;
>  
>  	if (check_shl_overflow(slba, nvmet_ns_blksize_shift(req->ns), &pos64) ||
> -	    pos64 > req->ns->size || len > req->ns->size - pos64)
> +	    pos64 > nvmet_ns_size(req->ns) ||
> +	    len > nvmet_ns_size(req->ns) - pos64)
>  		return false;
>  
>  	*pos = pos64;

[Severity: Medium]
Can calling nvmet_ns_size(req->ns) twice here underflow nvmet_ns_size(req->ns)
- pos64 and bypass the bounds check?

Because nvmet_ns_size() uses READ_ONCE(), the two calls perform two separate
loads of req->ns->size.  If a concurrent nvmet_file_ns_revalidate() shrinks
req->ns->size below pos64 between the two loads, the first check passes against
the old size while the unsigned 64-bit subtraction in the second check wraps
around near U64_MAX:

CPU0                                  CPU1
nvmet_file_check_lba_range()
  pos64 > nvmet_ns_size(req->ns)
    /* size1 >= pos64: false */
                                      nvmet_file_ns_revalidate()
                                        WRITE_ONCE(ns->size, size2)
                                        /* size2 < pos64 */
  len > nvmet_ns_size(req->ns) - pos64
    /* (u64)size2 - pos64 underflows */

An out-of-range write request then passes nvmet_file_check_lba_range() and can
extend the backing file past the namespace capacity instead of failing with
NVME_SC_CAP_EXCEEDED.  Reading nvmet_ns_size(req->ns) once into a local
variable and using it for both comparisons avoids this.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118073505.288910-1-nilay@linux.ibm.com?part=7


  reply	other threads:[~2026-11-18  7:50 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  7:34 [PATCH v2 00/22] nvmet: add context annotation for params in struct nvmet_ns Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 01/22] nvmet: add context annotation for nvmet_ns::bdev Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 02/22] nvmet: fix nvmet_ns::bdev access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 03/22] nvmet: add context annotation for nvmet_ns::file Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 04/22] nvmet: add context annotation for nvmet_ns::bdev_file Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 05/22] nvmet: add context annotation for nvmet_ns::readonly Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 06/22] nvmet: add context annotation for nvmet_ns::blksize_shift Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 07/22] nvmet: add context annotation for nvmet_ns::size Nilay Shroff
2026-11-18  7:50   ` sashiko-bot [this message]
2026-11-18  7:34 ` [PATCH v2 08/22] nvmet: add context annotation for nvmet_ns::nguid Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 09/22] nvmet: add context annotation for nvmet_ns::uuid Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 10/22] nvmet: fix nvmet_ns::uuid access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 11/22] nvmet: add context annotation for nvmet_ns::buffered_io Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 12/22] nvmet: fix nvmet_ns::buffered_io access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 13/22] nvmet: add context annotation for nvmet_ns::enabled Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 14/22] nvmet: fix nvmet_ns::enable access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 15/22] nvmet: add context annotation for nvmet_ns::device_path Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 16/22] nvmet: fix nvmet_ns::device_path access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 17/22] nvmet: add context annotation for PCI P2P parameters in struct nvmet_ns Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 18/22] nvmet: fix PCI P2P parameters access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:55   ` sashiko-bot
2026-11-18  7:35 ` [PATCH v2 19/22] nvmet: add context annotation for integrity params in struct nvmet_ns Nilay Shroff
2026-11-18  7:35 ` [PATCH v2 20/22] nvmet: add context annotation for nvmet_ns::csi Nilay Shroff
2026-11-18  7:35 ` [PATCH v2 21/22] nvmet: fix nvmet_ns::csi access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:35 ` [PATCH v2 22/22] nvmet: add context annotation for nvmet_ns::debugfs_dir Nilay Shroff

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-220364@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=nilay@linux.ibm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 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.