summaryrefslogtreecommitdiffstats
path: root/drivers/staging/gasket/gasket_ioctl.c
diff options
context:
space:
mode:
authorTodd Poynor <toddpoynor@google.com>2018-07-19 20:49:16 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-07-21 08:50:35 +0200
commited74277bd80a47ec552ccf3581583421c3a4df5d (patch)
treec9e4eb90d95b4e1d08fcc7e092884ac006ec9dc5 /drivers/staging/gasket/gasket_ioctl.c
parent563f3bb51f59e288879c099b2e8ee1496b7c3234 (diff)
staging: gasket: always allow root open for write
Always allow root to open device for writing. Drop special-casing of ioctl permissions for root vs. owner. Convert to bool types as appropriate. Reported-by: Dmitry Torokhov <dtor@chromium.org> Signed-off-by: Zhongze Hu <frankhu@chromium.org> Signed-off-by: Todd Poynor <toddpoynor@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/gasket/gasket_ioctl.c')
-rw-r--r--drivers/staging/gasket/gasket_ioctl.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/drivers/staging/gasket/gasket_ioctl.c b/drivers/staging/gasket/gasket_ioctl.c
index d0142ed048a6..8fd44979fe71 100644
--- a/drivers/staging/gasket/gasket_ioctl.c
+++ b/drivers/staging/gasket/gasket_ioctl.c
@@ -22,7 +22,7 @@
#define trace_gasket_ioctl_config_coherent_allocator(x, ...)
#endif
-static uint gasket_ioctl_check_permissions(struct file *filp, uint cmd);
+static bool gasket_ioctl_check_permissions(struct file *filp, uint cmd);
static int gasket_set_event_fd(struct gasket_dev *dev, ulong arg);
static int gasket_read_page_table_size(
struct gasket_dev *gasket_dev, ulong arg);
@@ -167,12 +167,13 @@ long gasket_is_supported_ioctl(uint cmd)
* @filp: File structure pointer describing this node usage session.
* @cmd: ioctl number to handle.
*
- * Standard permissions checker.
+ * Check permissions for Gasket ioctls.
+ * Returns true if the file opener may execute this ioctl, or false otherwise.
*/
-static uint gasket_ioctl_check_permissions(struct file *filp, uint cmd)
+static bool gasket_ioctl_check_permissions(struct file *filp, uint cmd)
{
- uint alive, root, device_owner;
- fmode_t read, write;
+ bool alive;
+ bool read, write;
struct gasket_dev *gasket_dev = (struct gasket_dev *)filp->private_data;
alive = (gasket_dev->status == GASKET_STATUS_ALIVE);
@@ -183,36 +184,33 @@ static uint gasket_ioctl_check_permissions(struct file *filp, uint cmd)
alive, gasket_dev->status);
}
- root = capable(CAP_SYS_ADMIN);
- read = filp->f_mode & FMODE_READ;
- write = filp->f_mode & FMODE_WRITE;
- device_owner = (gasket_dev->dev_info.ownership.is_owned &&
- current->tgid == gasket_dev->dev_info.ownership.owner);
+ read = !!(filp->f_mode & FMODE_READ);
+ write = !!(filp->f_mode & FMODE_WRITE);
switch (cmd) {
case GASKET_IOCTL_RESET:
case GASKET_IOCTL_CLEAR_INTERRUPT_COUNTS:
- return root || (write && device_owner);
+ return write;
case GASKET_IOCTL_PAGE_TABLE_SIZE:
case GASKET_IOCTL_SIMPLE_PAGE_TABLE_SIZE:
case GASKET_IOCTL_NUMBER_PAGE_TABLES:
- return root || read;
+ return read;
case GASKET_IOCTL_PARTITION_PAGE_TABLE:
case GASKET_IOCTL_CONFIG_COHERENT_ALLOCATOR:
- return alive && (root || (write && device_owner));
+ return alive && write;
case GASKET_IOCTL_MAP_BUFFER:
case GASKET_IOCTL_UNMAP_BUFFER:
- return alive && (root || (write && device_owner));
+ return alive && write;
case GASKET_IOCTL_CLEAR_EVENTFD:
case GASKET_IOCTL_SET_EVENTFD:
- return alive && (root || (write && device_owner));
+ return alive && write;
}
- return 0; /* unknown permissions */
+ return false; /* unknown permissions */
}
/*