From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@kernel.dk>,
Sagi Grimberg <sagi@grimberg.me>, Christoph Hellwig <hch@lst.de>,
Sasha Levin <sashal@kernel.org>,
linux-nvme@lists.infradead.org
Subject: [PATCH AUTOSEL 6.6 32/47] nvme-ioctl: move capable() admin check to the end
Date: Mon, 11 Dec 2023 08:50:33 -0500 [thread overview]
Message-ID: <20231211135147.380223-32-sashal@kernel.org> (raw)
In-Reply-To: <20231211135147.380223-1-sashal@kernel.org>
From: Keith Busch <kbusch@kernel.org>
[ Upstream commit 7be866b1cf0bf1dfa74480fe8097daeceda68622 ]
This can be an expensive call on some kernel configs. Move it to the end
after checking the cheaper ways to determine if the command is allowed.
Reviewed-by: Jens Axboe <axboe@kernel.dk>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/nvme/host/ioctl.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
index 529b9954d2b8c..4939ed35638f1 100644
--- a/drivers/nvme/host/ioctl.c
+++ b/drivers/nvme/host/ioctl.c
@@ -18,15 +18,12 @@ static bool nvme_cmd_allowed(struct nvme_ns *ns, struct nvme_command *c,
{
u32 effects;
- if (capable(CAP_SYS_ADMIN))
- return true;
-
/*
* Do not allow unprivileged passthrough on partitions, as that allows an
* escape from the containment of the partition.
*/
if (flags & NVME_IOCTL_PARTITION)
- return false;
+ goto admin;
/*
* Do not allow unprivileged processes to send vendor specific or fabrics
@@ -34,7 +31,7 @@ static bool nvme_cmd_allowed(struct nvme_ns *ns, struct nvme_command *c,
*/
if (c->common.opcode >= nvme_cmd_vendor_start ||
c->common.opcode == nvme_fabrics_command)
- return false;
+ goto admin;
/*
* Do not allow unprivileged passthrough of admin commands except
@@ -53,7 +50,7 @@ static bool nvme_cmd_allowed(struct nvme_ns *ns, struct nvme_command *c,
return true;
}
}
- return false;
+ goto admin;
}
/*
@@ -63,7 +60,7 @@ static bool nvme_cmd_allowed(struct nvme_ns *ns, struct nvme_command *c,
*/
effects = nvme_command_effects(ns->ctrl, ns, c->common.opcode);
if (!(effects & NVME_CMD_EFFECTS_CSUPP))
- return false;
+ goto admin;
/*
* Don't allow passthrough for command that have intrusive (or unknown)
@@ -72,16 +69,20 @@ static bool nvme_cmd_allowed(struct nvme_ns *ns, struct nvme_command *c,
if (effects & ~(NVME_CMD_EFFECTS_CSUPP | NVME_CMD_EFFECTS_LBCC |
NVME_CMD_EFFECTS_UUID_SEL |
NVME_CMD_EFFECTS_SCOPE_MASK))
- return false;
+ goto admin;
/*
* Only allow I/O commands that transfer data to the controller or that
* change the logical block contents if the file descriptor is open for
* writing.
*/
- if (nvme_is_write(c) || (effects & NVME_CMD_EFFECTS_LBCC))
- return open_for_write;
+ if ((nvme_is_write(c) || (effects & NVME_CMD_EFFECTS_LBCC)) &&
+ !open_for_write)
+ goto admin;
+
return true;
+admin:
+ return capable(CAP_SYS_ADMIN);
}
/*
--
2.42.0
next prev parent reply other threads:[~2023-12-11 13:54 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-11 13:50 [PATCH AUTOSEL 6.6 01/47] hwtracing: hisi_ptt: Handle the interrupt in hardirq context Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 02/47] hwtracing: hisi_ptt: Don't try to attach a task Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 03/47] ASoC: amd: yc: Add HP 255 G10 into quirk table Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 04/47] ASoC: wm8974: Correct boost mixer inputs Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 05/47] arm64: dts: rockchip: fix rk356x pcie msg interrupt name Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 06/47] ASoC: Intel: Skylake: Fix mem leak in few functions Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 07/47] ASoC: nau8822: Fix incorrect type in assignment and cast to restricted __be16 Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 08/47] ASoC: SOF: topology: Fix mem leak in sof_dai_load() Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 09/47] ASoC: Intel: Skylake: mem leak in skl register function Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 10/47] ASoC: cs43130: Fix the position of const qualifier Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 11/47] ASoC: cs43130: Fix incorrect frame delay configuration Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 12/47] ASoC: fsl_xcvr: Enable 2 * TX bit clock for spdif only case Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 13/47] ASoC: rt5650: add mutex to avoid the jack detection failure Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 14/47] ASoC: SOF: mediatek: mt8186: Add Google Steelix topology compatible Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 15/47] ASoC: fsl_xcvr: refine the requested phy clock frequency Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 16/47] ASoC: Intel: skl_hda_dsp_generic: Drop HDMI routes when HDMI is not available Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 17/47] ASoC: SOF: ipc4-topology: Add core_mask in struct snd_sof_pipeline Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 18/47] ASoC: SOF: sof-audio: Modify logic for enabling/disabling topology cores Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 19/47] nouveau/tu102: flush all pdbs on vmm flush Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 20/47] ASoC: amd: yc: Add DMI entry to support System76 Pangolin 13 Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 21/47] ASoC: hdac_hda: Conditionally register dais for HDMI and Analog Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 22/47] ASoC: SOF: ipc4-topology: Correct data structures for the SRC module Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 23/47] ASoC: SOF: ipc4-topology: Correct data structures for the GAIN module Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 24/47] pds_vdpa: fix up format-truncation complaint Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 25/47] pds_vdpa: clear config callback when status goes to 0 Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 26/47] pds_vdpa: set features order Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 27/47] net/tg3: fix race condition in tg3_reset_task() Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 28/47] ASoC: da7219: Support low DC impedance headset Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 29/47] ASoC: ops: add correct range check for limiting volume Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 30/47] nvme: introduce helper function to get ctrl state Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 31/47] nvme: ensure reset state check ordering Sasha Levin
2023-12-11 13:50 ` Sasha Levin [this message]
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 33/47] nvme: prevent potential spectre v1 gadget Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 34/47] nvme: fix deadlock between reset and scan Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 35/47] arm64: dts: rockchip: Fix PCI node addresses on rk3399-gru Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 36/47] mips/smp: Call rcutree_report_cpu_starting() earlier Sasha Levin
2023-12-12 1:45 ` Huacai Chen
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 37/47] r8152: add vendor/device ID pair for ASUS USB-C2500 Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 38/47] drm/amd/display: Use channel_width = 2 for vram table 3.0 Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 39/47] drm/amd/display: Add monitor patch for specific eDP Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 40/47] drm/amdgpu: Add NULL checks for function pointers Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 41/47] drm/exynos: fix a potential error pointer dereference Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 42/47] drm/exynos: fix a wrong error checking Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 43/47] ALSA: pcmtest: stop timer before buffer is released Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 44/47] hwmon: (corsair-psu) Fix probe when built-in Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 45/47] LoongArch: Apply dynamic relocations for LLD Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 46/47] LoongArch: Set unwind stack type to unknown rather than set error flag Sasha Levin
2023-12-11 13:50 ` [PATCH AUTOSEL 6.6 47/47] LoongArch: Preserve syscall nr across execve() Sasha Levin
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=20231211135147.380223-32-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
--cc=stable@vger.kernel.org \
/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