Skip to content

Commit 20dc66f

Browse files
nj-shettykeithbusch
authored andcommitted
nvme: prevent potential spectre v1 gadget
This patch fixes the smatch warning, "nvmet_ns_ana_grpid_store() warn: potential spectre issue 'nvmet_ana_group_enabled' [w] (local cap)" Prevent the contents of kernel memory from being leaked to user space via speculative execution by using array_index_nospec. Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent 29ac4b2 commit 20dc66f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/nvme/target/configfs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/nvme-keyring.h>
1919
#include <crypto/hash.h>
2020
#include <crypto/kpp.h>
21+
#include <linux/nospec.h>
2122

2223
#include "nvmet.h"
2324

@@ -621,6 +622,7 @@ static ssize_t nvmet_ns_ana_grpid_store(struct config_item *item,
621622

622623
down_write(&nvmet_ana_sem);
623624
oldgrpid = ns->anagrpid;
625+
newgrpid = array_index_nospec(newgrpid, NVMET_MAX_ANAGRPS);
624626
nvmet_ana_group_enabled[newgrpid]++;
625627
ns->anagrpid = newgrpid;
626628
nvmet_ana_group_enabled[oldgrpid]--;
@@ -1812,6 +1814,7 @@ static struct config_group *nvmet_ana_groups_make_group(
18121814
grp->grpid = grpid;
18131815

18141816
down_write(&nvmet_ana_sem);
1817+
grpid = array_index_nospec(grpid, NVMET_MAX_ANAGRPS);
18151818
nvmet_ana_group_enabled[grpid]++;
18161819
up_write(&nvmet_ana_sem);
18171820

0 commit comments

Comments
 (0)