[RFC 1/2] nvme: add whitelisting infrastructure
Jens Axboe
axboe at kernel.dk
Fri Sep 9 09:55:45 PDT 2022
On 9/9/22 10:33 AM, Kanchan Joshi wrote:
> If CAP_SYS_ADMIN is present, nothing else is checked, as before.
> If CAP_SYS_ADMIN is not present, take the decision based on
> - type of nvme command (io or admin)
> - nature of nvme-command (write or read)
> - mode with which file was opened (read-only, read-write etc.)
>
> io-commands that write/read are allowed only if matching file mode is
> present.
> for admin-commands, few read-only admin command are allowed and that too
> when mode matches.
>
> Signed-off-by: Kanchan Joshi <joshi.k at samsung.com>
> ---
> drivers/nvme/host/ioctl.c | 36 ++++++++++++++++++++++++++++++++++++
> 1 file changed, 36 insertions(+)
>
> diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
> index 548aca8b5b9f..0d99135a1745 100644
> --- a/drivers/nvme/host/ioctl.c
> +++ b/drivers/nvme/host/ioctl.c
> @@ -20,6 +20,42 @@ static void __user *nvme_to_user_ptr(uintptr_t ptrval)
> return (void __user *)ptrval;
> }
>
> +bool nvme_io_cmd_allowed(u8 opcode, fmode_t mode)
> +{
> + /* allow write/read based on what was allowed for open */
> + /* TBD: try to use nvme_is_write() here */
> + if (opcode & 1)
> + return (mode & FMODE_WRITE);
> + else
> + return (mode & FMODE_READ);
> +}
The read/write distinction doesn't make a lot of sense to me. You've
already been able to open the device at this point. It would only make
sense to limit some things based on FMODE_WRITE imho, not FMODE_READ.
--
Jens Axboe
More information about the Linux-nvme
mailing list