public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Kanchan Joshi <joshi.k@samsung.com>
Cc: hch@lst.de, kbusch@kernel.org, sagi@grimberg.me, axboe@kernel.dk,
	linux-nvme@lists.infradead.org, gost.dev@samsung.com
Subject: Re: [PATCH for-next 2/2] nvme: Make CAP_SYS_ADMIN fine-granular
Date: Tue, 27 Sep 2022 09:32:50 +0200	[thread overview]
Message-ID: <20220927073250.GB16831@lst.de> (raw)
In-Reply-To: <20220926145430.81658-3-joshi.k@samsung.com>

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@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?



  parent reply	other threads:[~2022-09-27  7:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20220926150436epcas5p4fd7f1945793cded05910da5c5094805e@epcas5p4.samsung.com>
2022-09-26 14:54 ` [PATCH for-next 0/2] Fine-granular CAP_SYS_ADMIN Kanchan Joshi
2022-09-26 14:54   ` [PATCH for-next 1/2] nvme: add the permission-policy for command control Kanchan Joshi
2022-09-26 22:25     ` Chaitanya Kulkarni
2022-09-27  7:31     ` Christoph Hellwig
2022-09-26 14:54   ` [PATCH for-next 2/2] nvme: Make CAP_SYS_ADMIN fine-granular Kanchan Joshi
2022-09-26 22:30     ` Chaitanya Kulkarni
2022-09-27 17:06       ` Kanchan Joshi
2022-09-27  7:32     ` Christoph Hellwig [this message]
2022-09-27 17:50       ` Kanchan Joshi

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=20220927073250.GB16831@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=gost.dev@samsung.com \
    --cc=joshi.k@samsung.com \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --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