All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lightnvm: centralize permission check for lightnvm ioctl
@ 2018-02-26 12:11 Johannes Thumshirn
  2018-02-26 12:59 ` Matias Bjørling
  0 siblings, 1 reply; 2+ messages in thread
From: Johannes Thumshirn @ 2018-02-26 12:11 UTC (permalink / raw)
  To: Matias Bjørling
  Cc: Javier González, Hans Holmberg,
	Linux Block Layer Mailinglist, Johannes Thumshirn

Currently all functions for handling the lightnvm core ioctl commands
do a check for CAP_SYS_ADMIN.

Change this to fail early in nvm_ctl_ioctl(), so we don't have to
duplicate the permission checks all over.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 drivers/lightnvm/core.c | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index dcc9e621e651..74d0bda94c11 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -1040,9 +1040,6 @@ static long nvm_ioctl_info(struct file *file, void __user *arg)
 	struct nvm_tgt_type *tt;
 	int tgt_iter = 0;
 
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
-
 	info = memdup_user(arg, sizeof(struct nvm_ioctl_info));
 	if (IS_ERR(info))
 		return -EFAULT;
@@ -1081,9 +1078,6 @@ static long nvm_ioctl_get_devices(struct file *file, void __user *arg)
 	struct nvm_dev *dev;
 	int i = 0;
 
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
-
 	devices = kzalloc(sizeof(struct nvm_ioctl_get_devices), GFP_KERNEL);
 	if (!devices)
 		return -ENOMEM;
@@ -1124,9 +1118,6 @@ static long nvm_ioctl_dev_create(struct file *file, void __user *arg)
 {
 	struct nvm_ioctl_create create;
 
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
-
 	if (copy_from_user(&create, arg, sizeof(struct nvm_ioctl_create)))
 		return -EFAULT;
 
@@ -1162,9 +1153,6 @@ static long nvm_ioctl_dev_remove(struct file *file, void __user *arg)
 	struct nvm_dev *dev;
 	int ret = 0;
 
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
-
 	if (copy_from_user(&remove, arg, sizeof(struct nvm_ioctl_remove)))
 		return -EFAULT;
 
@@ -1189,9 +1177,6 @@ static long nvm_ioctl_dev_init(struct file *file, void __user *arg)
 {
 	struct nvm_ioctl_dev_init init;
 
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
-
 	if (copy_from_user(&init, arg, sizeof(struct nvm_ioctl_dev_init)))
 		return -EFAULT;
 
@@ -1208,9 +1193,6 @@ static long nvm_ioctl_dev_factory(struct file *file, void __user *arg)
 {
 	struct nvm_ioctl_dev_factory fact;
 
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
-
 	if (copy_from_user(&fact, arg, sizeof(struct nvm_ioctl_dev_factory)))
 		return -EFAULT;
 
@@ -1226,6 +1208,9 @@ static long nvm_ctl_ioctl(struct file *file, uint cmd, unsigned long arg)
 {
 	void __user *argp = (void __user *)arg;
 
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
 	switch (cmd) {
 	case NVM_INFO:
 		return nvm_ioctl_info(file, argp);
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] lightnvm: centralize permission check for lightnvm ioctl
  2018-02-26 12:11 [PATCH] lightnvm: centralize permission check for lightnvm ioctl Johannes Thumshirn
@ 2018-02-26 12:59 ` Matias Bjørling
  0 siblings, 0 replies; 2+ messages in thread
From: Matias Bjørling @ 2018-02-26 12:59 UTC (permalink / raw)
  To: Johannes Thumshirn, Matias Bjørling
  Cc: Javier González, Hans Holmberg, Linux Block Layer Mailinglist

On 02/26/2018 01:11 PM, Johannes Thumshirn wrote:
> Currently all functions for handling the lightnvm core ioctl commands
> do a check for CAP_SYS_ADMIN.
> 
> Change this to fail early in nvm_ctl_ioctl(), so we don't have to
> duplicate the permission checks all over.
> 
> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
> ---
>   drivers/lightnvm/core.c | 21 +++------------------
>   1 file changed, 3 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
> index dcc9e621e651..74d0bda94c11 100644
> --- a/drivers/lightnvm/core.c
> +++ b/drivers/lightnvm/core.c
> @@ -1040,9 +1040,6 @@ static long nvm_ioctl_info(struct file *file, void __user *arg)
>   	struct nvm_tgt_type *tt;
>   	int tgt_iter = 0;
>   
> -	if (!capable(CAP_SYS_ADMIN))
> -		return -EPERM;
> -
>   	info = memdup_user(arg, sizeof(struct nvm_ioctl_info));
>   	if (IS_ERR(info))
>   		return -EFAULT;
> @@ -1081,9 +1078,6 @@ static long nvm_ioctl_get_devices(struct file *file, void __user *arg)
>   	struct nvm_dev *dev;
>   	int i = 0;
>   
> -	if (!capable(CAP_SYS_ADMIN))
> -		return -EPERM;
> -
>   	devices = kzalloc(sizeof(struct nvm_ioctl_get_devices), GFP_KERNEL);
>   	if (!devices)
>   		return -ENOMEM;
> @@ -1124,9 +1118,6 @@ static long nvm_ioctl_dev_create(struct file *file, void __user *arg)
>   {
>   	struct nvm_ioctl_create create;
>   
> -	if (!capable(CAP_SYS_ADMIN))
> -		return -EPERM;
> -
>   	if (copy_from_user(&create, arg, sizeof(struct nvm_ioctl_create)))
>   		return -EFAULT;
>   
> @@ -1162,9 +1153,6 @@ static long nvm_ioctl_dev_remove(struct file *file, void __user *arg)
>   	struct nvm_dev *dev;
>   	int ret = 0;
>   
> -	if (!capable(CAP_SYS_ADMIN))
> -		return -EPERM;
> -
>   	if (copy_from_user(&remove, arg, sizeof(struct nvm_ioctl_remove)))
>   		return -EFAULT;
>   
> @@ -1189,9 +1177,6 @@ static long nvm_ioctl_dev_init(struct file *file, void __user *arg)
>   {
>   	struct nvm_ioctl_dev_init init;
>   
> -	if (!capable(CAP_SYS_ADMIN))
> -		return -EPERM;
> -
>   	if (copy_from_user(&init, arg, sizeof(struct nvm_ioctl_dev_init)))
>   		return -EFAULT;
>   
> @@ -1208,9 +1193,6 @@ static long nvm_ioctl_dev_factory(struct file *file, void __user *arg)
>   {
>   	struct nvm_ioctl_dev_factory fact;
>   
> -	if (!capable(CAP_SYS_ADMIN))
> -		return -EPERM;
> -
>   	if (copy_from_user(&fact, arg, sizeof(struct nvm_ioctl_dev_factory)))
>   		return -EFAULT;
>   
> @@ -1226,6 +1208,9 @@ static long nvm_ctl_ioctl(struct file *file, uint cmd, unsigned long arg)
>   {
>   	void __user *argp = (void __user *)arg;
>   
> +	if (!capable(CAP_SYS_ADMIN))
> +		return -EPERM;
> +
>   	switch (cmd) {
>   	case NVM_INFO:
>   		return nvm_ioctl_info(file, argp);
> 

Thanks Johannes. Applied.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-02-26 12:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-26 12:11 [PATCH] lightnvm: centralize permission check for lightnvm ioctl Johannes Thumshirn
2018-02-26 12:59 ` Matias Bjørling

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.