[PATCH] nvmet: clamp the last ANA group index against the real array size
Nilay Shroff
nilay at linux.ibm.com
Fri Nov 13 02:19:41 PST 2026
On 11/6/26 12:10 PM, 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 at vger.kernel.org
> Signed-off-by: Yuehong Wu<wuyuehong at cmss.chinamobile.com>
Looks good to me:
Reviewed-by: Nilay Shroff <nilay at linux.ibm.com>
More information about the Linux-nvme
mailing list