[PATCH for-next 2/2] nvme: Make CAP_SYS_ADMIN fine-granular
Kanchan Joshi
joshi.k at samsung.com
Tue Sep 27 10:50:40 PDT 2022
On Tue, Sep 27, 2022 at 09:32:50AM +0200, Christoph Hellwig wrote:
>On Mon, Sep 26, 2022 at 08:24:30PM +0530, Kanchan Joshi wrote:
>> Change all the callers of CAP_SYS_ADMIN to go through nvme_cmd_allowed
>> for any decision making.
>> Since file open mode is taken into consideration for any
>> approval/denial, change at various places to keep file-mode information
>> handy.
>>
>> Signed-off-by: Kanchan Joshi <joshi.k at samsung.com>
>> ---
>> drivers/nvme/host/ioctl.c | 70 +++++++++++++++++++++------------------
>> 1 file changed, 38 insertions(+), 32 deletions(-)
>>
>> diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
>> index 6ca6477dd899..4e53a01e702d 100644
>> --- a/drivers/nvme/host/ioctl.c
>> +++ b/drivers/nvme/host/ioctl.c
>> @@ -259,7 +259,7 @@ static bool nvme_validate_passthru_nsid(struct nvme_ctrl *ctrl,
>> }
>>
>> static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
>> - struct nvme_passthru_cmd __user *ucmd)
>> + struct nvme_passthru_cmd __user *ucmd, fmode_t mode)
>> {
>> struct nvme_passthru_cmd cmd;
>> struct nvme_command c;
>> @@ -267,10 +267,10 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
>> u64 result;
>> int status;
>>
>> - if (!capable(CAP_SYS_ADMIN))
>> - return -EACCES;
>> if (copy_from_user(&cmd, ucmd, sizeof(cmd)))
>> return -EFAULT;
>> + if (!nvme_cmd_allowed(ns, cmd.opcode, mode))
>> + return -EACCES;
>
>Btw, what speaks against moving this check a little bit later,
>so that we can pass the nvme_command to nvme_cmd_allowed, and thus
>can simply use nvme_is_write?
Moving down is good to me. Just after we have put the opcode into
nvme_command. Will do that in v2.
More information about the Linux-nvme
mailing list