mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Yuehong Wu <wuyuehong@cmss.chinamobile.com>,
	linux-nvme@lists.infradead.org
Cc: Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
	Chaitanya Kulkarni <kch@nvidia.com>,
	Keith Busch <kbusch@kernel.org>,
	Maurizio Lombardi <mlombard@redhat.com>,
	Mohamed Khalfella <mkhalfella@purestorage.com>,
	Nitesh Shetty <nj.shetty@samsung.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	Aurelien Aptel <aaptel@nvidia.com>,
	Nilay Shroff <nilay@linux.ibm.com>,
	Jesse Taube <jtaubepe@redhat.com>,
	Rongzheng Wang <testwrzwrz@gmail.com>,
	Kees Cook <kees@kernel.org>, Rosen Penev <rosenp@gmail.com>,
	Guixin Liu <kanie@linux.alibaba.com>,
	Qing Zhang <diasyzhang@tencent.com>,
	Eric Biggers <ebiggers@kernel.org>,
	Julian Sun <sunjunchao@bytedance.com>,
	Yu Zhang <yuz08559@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] nvmet: clamp the last ANA group index against the real array size
Date: Fri, 13 Nov 2026 11:25:53 +0100	[thread overview]
Message-ID: <aead1f29-eb58-4e44-b4f6-a8dfa7d7c193@suse.de> (raw)
In-Reply-To: <20261106-nvmet-ana-grpid-1-yuehongwu@cmss.chinamobile.com>

On 11/6/26 7:40 AM, Yuehong Wu wrote:
> NVMET_MAX_ANAGRPS is the highest valid ANA group id, not the size of
> nvmet_ana_group_enabled[]: the array has NVMET_MAX_ANAGRPS + 1 entries
> and the controller advertises anagrpmax == NVMET_MAX_ANAGRPS.  Both
> array_index_nospec() calls however pass NVMET_MAX_ANAGRPS as the size,
> so for the last group the mask is 0 and the index quietly becomes 0:
> 
>   - nvmet_ana_groups_make_group() increments enabled[0] while the group
>     keeps grpid == 128, so the later nvmet_ana_group_release() decrements
>     enabled[128], which underflows to 0xffffffff.  The ANA log page then
>     reports group 128 as inaccessible forever even though the configfs
>     group no longer exists, and the increment on enabled[0] is never
>     undone.
> 
>   - nvmet_ns_ana_grpid_store() accepts 128, stores 0 in ns->anagrpid and
>     returns success, so the namespace silently stays in the default ANA
>     group instead of the one the user asked for.
> 
> Both failures are silent, and they change what the target reports in its
> ANA log page, which is what a host uses to select paths.
> 
> Pass the real array size in both calls, so the masking is kept but the
> last group is no longer folded onto index 0.
> 
> Fixes: 20dc66f2d76b ("nvme: prevent potential spectre v1 gadget")
> Cc: stable@vger.kernel.org
> Signed-off-by: Yuehong Wu <wuyuehong@cmss.chinamobile.com>
> ---
> Verified with nvme-loop in QEMU/KVM on 7.3.0-next-20261027, with two
> kernels built from the same tree and differing only in these two lines
> (no instrumentation):
> 
>   - before the patch, a group created as ports/1/ana_groups/128 is absent
>     from the ANA log page (ngrps=1) even though configfs accepted it, and
>     it is reported as expected afterwards (ngrps=2, group 128 optimized);
>   - 128 written to a namespace ana_grpid reads back as 0 before the patch
>     and as 128 after it, and the namespace is accounted to group 128;
>   - removing the group again adds a phantom group 128 (state inaccessible,
>     0 namespaces) to the ANA log page before the patch, and leaves no
>     trace after it, even when creating and removing it repeatedly.
> 
>   drivers/nvme/target/configfs.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
> index 8aea64d..48d3f68 100644
> --- a/drivers/nvme/target/configfs.c
> +++ b/drivers/nvme/target/configfs.c
> @@ -701,7 +701,7 @@ static ssize_t nvmet_ns_ana_grpid_store(struct config_item *item,
>   
>   	down_write(&nvmet_ana_sem);
>   	oldgrpid = ns->anagrpid;
> -	newgrpid = array_index_nospec(newgrpid, NVMET_MAX_ANAGRPS);
> +	newgrpid = array_index_nospec(newgrpid, NVMET_MAX_ANAGRPS + 1);
>   	nvmet_ana_group_enabled[newgrpid]++;
>   	ns->anagrpid = newgrpid;
>   	nvmet_ana_group_enabled[oldgrpid]--;
> @@ -2074,7 +2074,7 @@ static struct config_group *nvmet_ana_groups_make_group(
>   	grp->grpid = grpid;
>   
>   	down_write(&nvmet_ana_sem);
> -	grpid = array_index_nospec(grpid, NVMET_MAX_ANAGRPS);
> +	grpid = array_index_nospec(grpid, NVMET_MAX_ANAGRPS + 1);
>   	nvmet_ana_group_enabled[grpid]++;
>   	up_write(&nvmet_ana_sem);
>   
Reviewed-by: Hannes Reinecke <hare@kernel.org>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                  Kernel Storage Architect
hare@suse.de                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich

      parent reply	other threads:[~2026-11-13 10:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06  6:40 Yuehong Wu
2026-11-06  7:03 ` Yuehong Wu
2026-11-06 13:47   ` Andrew Stellman
2026-11-12 21:21 ` Christoph Hellwig
2026-11-13 10:19 ` Nilay Shroff
2026-11-13 10:25 ` Hannes Reinecke [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=aead1f29-eb58-4e44-b4f6-a8dfa7d7c193@suse.de \
    --to=hare@suse.de \
    --cc=aaptel@nvidia.com \
    --cc=diasyzhang@tencent.com \
    --cc=ebiggers@kernel.org \
    --cc=hch@lst.de \
    --cc=jtaubepe@redhat.com \
    --cc=kanie@linux.alibaba.com \
    --cc=kbusch@kernel.org \
    --cc=kch@nvidia.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=mkhalfella@purestorage.com \
    --cc=mlombard@redhat.com \
    --cc=nilay@linux.ibm.com \
    --cc=nj.shetty@samsung.com \
    --cc=rdunlap@infradead.org \
    --cc=rosenp@gmail.com \
    --cc=sagi@grimberg.me \
    --cc=sunjunchao@bytedance.com \
    --cc=testwrzwrz@gmail.com \
    --cc=wuyuehong@cmss.chinamobile.com \
    --cc=yuz08559@gmail.com \
    /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

all inboxes | Powered by JetHome®