From e583e4a6dc22aebd7f929cbdfe4e382625d81a0d Mon Sep 17 00:00:00 2001 From: Debarshi Dutta Date: Tue, 22 Nov 2022 12:36:32 +0530 Subject: [PATCH] gpu: nvgpu: add adequate checks for control-fifo node. Add additional checks to prevent users without both READ/WRITE permissions from opening the control-fifo device node. Jira NVGPU-8619 Signed-off-by: Debarshi Dutta Change-Id: Ie0be0f578c154b45547d5d150ddabaa5936bda80 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2813816 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-cert Reviewed-by: Prateek Sethi Reviewed-by: Vaibhav Kachore GVS: Gerrit_Virtual_Submit Tested-by: Prateek Sethi --- drivers/gpu/nvgpu/os/linux/ioctl_nvs.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/gpu/nvgpu/os/linux/ioctl_nvs.c b/drivers/gpu/nvgpu/os/linux/ioctl_nvs.c index 1c2d20087..54e60d95f 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_nvs.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_nvs.c @@ -612,10 +612,16 @@ int nvgpu_nvs_ctrl_fifo_ops_open(struct inode *inode, struct file *filp) int err = 0; struct nvgpu_nvs_domain_ctrl_fifo_user_linux *linux_user; bool writable = filp->f_mode & FMODE_WRITE; + bool readable = filp->f_mode & FMODE_READ; cdev = container_of(inode->i_cdev, struct nvgpu_cdev, cdev); g = nvgpu_get_gk20a_from_cdev(cdev); + if (!writable && !readable) { + nvgpu_err(g, "User doesn't have adequate permission to open this device"); + return -EOPNOTSUPP; + } + err = gk20a_busy(g); if (err != 0) { nvgpu_err(g, "Unable to power on the device");