mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-07 19:30:30 +09:00
nvme: prevent potential spectre v1 gadget
[ Upstream commit 20dc66f2d76b4a410df14e4675e373b718babc34 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
df2bd52354
commit
ce97686124
@@ -16,6 +16,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <crypto/hash.h>
|
#include <crypto/hash.h>
|
||||||
#include <crypto/kpp.h>
|
#include <crypto/kpp.h>
|
||||||
|
#include <linux/nospec.h>
|
||||||
|
|
||||||
#include "nvmet.h"
|
#include "nvmet.h"
|
||||||
|
|
||||||
@@ -508,6 +509,7 @@ static ssize_t nvmet_ns_ana_grpid_store(struct config_item *item,
|
|||||||
|
|
||||||
down_write(&nvmet_ana_sem);
|
down_write(&nvmet_ana_sem);
|
||||||
oldgrpid = ns->anagrpid;
|
oldgrpid = ns->anagrpid;
|
||||||
|
newgrpid = array_index_nospec(newgrpid, NVMET_MAX_ANAGRPS);
|
||||||
nvmet_ana_group_enabled[newgrpid]++;
|
nvmet_ana_group_enabled[newgrpid]++;
|
||||||
ns->anagrpid = newgrpid;
|
ns->anagrpid = newgrpid;
|
||||||
nvmet_ana_group_enabled[oldgrpid]--;
|
nvmet_ana_group_enabled[oldgrpid]--;
|
||||||
@@ -1580,6 +1582,7 @@ static struct config_group *nvmet_ana_groups_make_group(
|
|||||||
grp->grpid = grpid;
|
grp->grpid = grpid;
|
||||||
|
|
||||||
down_write(&nvmet_ana_sem);
|
down_write(&nvmet_ana_sem);
|
||||||
|
grpid = array_index_nospec(grpid, NVMET_MAX_ANAGRPS);
|
||||||
nvmet_ana_group_enabled[grpid]++;
|
nvmet_ana_group_enabled[grpid]++;
|
||||||
up_write(&nvmet_ana_sem);
|
up_write(&nvmet_ana_sem);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user