From: Nitesh Shetty <nj.shetty@samsung.com>
To: Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@kernel.dk>,
Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
James Smart <james.smart@broadcom.com>,
Chaitanya Kulkarni <kch@nvidia.com>
Cc: error27@gmail.com, gost.dev@samsung.com, nitheshshetty@gmail.com,
Nitesh Shetty <nj.shetty@samsung.com>,
linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] nvme: prevent potential spectre v1 gadget
Date: Tue, 28 Nov 2023 17:59:57 +0530 [thread overview]
Message-ID: <20231128122958.2235-2-nj.shetty@samsung.com> (raw)
In-Reply-To: <20231128122958.2235-1-nj.shetty@samsung.com>
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>
---
drivers/nvme/target/configfs.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index e307a044b1a1..d937fe05129e 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -18,6 +18,7 @@
#include <linux/nvme-keyring.h>
#include <crypto/hash.h>
#include <crypto/kpp.h>
+#include <linux/nospec.h>
#include "nvmet.h"
@@ -621,6 +622,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);
nvmet_ana_group_enabled[newgrpid]++;
ns->anagrpid = newgrpid;
nvmet_ana_group_enabled[oldgrpid]--;
@@ -1812,6 +1814,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);
nvmet_ana_group_enabled[grpid]++;
up_write(&nvmet_ana_sem);
--
2.35.1.500.gb896f729e2
next prev parent reply other threads:[~2023-11-29 3:03 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20231128123622epcas5p4940679fbbafdf0da802deea3e531f850@epcas5p4.samsung.com>
2023-11-28 12:29 ` [PATCH 1/2] nvme: Update type from size_t to u16 for opts->queue_size Nitesh Shetty
[not found] ` <CGME20231128123634epcas5p201af168ff4ef4a8a129e5448bccca1a6@epcas5p2.samsung.com>
2023-11-28 12:29 ` Nitesh Shetty [this message]
2023-11-29 9:20 ` [PATCH 2/2] nvme: prevent potential spectre v1 gadget Sagi Grimberg
2023-11-29 9:27 ` Dan Carpenter
2023-11-29 15:54 ` Nitesh Shetty
2023-12-04 7:42 ` Christoph Hellwig
2023-12-04 16:40 ` Keith Busch
2023-11-29 9:22 ` [PATCH 1/2] nvme: Update type from size_t to u16 for opts->queue_size Sagi Grimberg
2023-11-29 9:26 ` Dan Carpenter
2023-11-29 10:48 ` Nitesh Shetty
2023-11-30 7:07 ` Dan Carpenter
2023-11-30 9:57 ` Nitesh Shetty
2023-11-29 12:15 ` Dan Carpenter
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=20231128122958.2235-2-nj.shetty@samsung.com \
--to=nj.shetty@samsung.com \
--cc=axboe@kernel.dk \
--cc=error27@gmail.com \
--cc=gost.dev@samsung.com \
--cc=hch@lst.de \
--cc=james.smart@broadcom.com \
--cc=kbusch@kernel.org \
--cc=kch@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=nitheshshetty@gmail.com \
--cc=sagi@grimberg.me \
/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®