Re: [PATCH] nvmet: clamp the last ANA group index against the real array size
From: Nilay Shroff
Date: Fri Nov 13 2026 - 08:28:39 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Yuehong Wu<wuyuehong@xxxxxxxxxxxxxxxxxxxx>
Looks good to me:
Reviewed-by: Nilay Shroff <nilay@xxxxxxxxxxxxx>