linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3 linux-next] udf: fix ioctl errors
@ 2017-01-24 20:48 Fabian Frederick
  2017-01-24 20:48 ` [PATCH 2/3 linux-next] udf: simplify udf_ioctl() Fabian Frederick
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Fabian Frederick @ 2017-01-24 20:48 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-fsdevel, linux-kernel, fabf

Currently, lsattr for instance in udf directory gives
"udf: Invalid argument While reading flags on ..."

This patch returns -ENOIOCTLCMD
when command is unknown to have more accurate message like this:
"Inappropriate ioctl for device While reading flags on ..."

As suggested by Jan Kara, if arg is NULL with a correct ioctl,
we return -VM_FAULT_SIGBUS to report error.

Signed-off-by: Fabian Frederick <fabf@skynet.be>
---
 fs/udf/file.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/udf/file.c b/fs/udf/file.c
index dbcb3a4a..d44b3cb 100644
--- a/fs/udf/file.c
+++ b/fs/udf/file.c
@@ -184,9 +184,10 @@ long udf_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		goto out;
 	}
 
-	if (!arg) {
+	if (!arg && ((cmd == UDF_GETVOLIDENT) || (cmd == UDF_GETEASIZE) ||
+		     (cmd == UDF_RELOCATE_BLOCKS) || (cmd == UDF_GETEABLOCK))) {
 		udf_debug("invalid argument to udf_ioctl\n");
-		result = -EINVAL;
+		result = -VM_FAULT_SIGBUS;
 		goto out;
 	}
 
@@ -220,6 +221,8 @@ long udf_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 				      UDF_I(inode)->i_ext.i_data,
 				      UDF_I(inode)->i_lenEAttr) ? -EFAULT : 0;
 		goto out;
+	default:
+		return -ENOIOCTLCMD;
 	}
 
 out:
-- 
2.9.3

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

* [PATCH 2/3 linux-next] udf: simplify udf_ioctl()
  2017-01-24 20:48 [PATCH 1/3 linux-next] udf: fix ioctl errors Fabian Frederick
@ 2017-01-24 20:48 ` Fabian Frederick
  2017-02-03 15:25   ` Jan Kara
  2017-01-24 20:48 ` [PATCH 3/3 linux-next] udf: remove else after return in udf_ioctl() Fabian Frederick
  2017-02-03 15:19 ` [PATCH 1/3 linux-next] udf: fix ioctl errors Jan Kara
  2 siblings, 1 reply; 5+ messages in thread
From: Fabian Frederick @ 2017-01-24 20:48 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-fsdevel, linux-kernel, fabf

"out" label was only returning error code.

Signed-off-by: Fabian Frederick <fabf@skynet.be>
---
 fs/udf/file.c | 39 +++++++++++++++------------------------
 1 file changed, 15 insertions(+), 24 deletions(-)

diff --git a/fs/udf/file.c b/fs/udf/file.c
index d44b3cb..00931fa 100644
--- a/fs/udf/file.c
+++ b/fs/udf/file.c
@@ -176,57 +176,48 @@ long udf_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
 	struct inode *inode = file_inode(filp);
 	long old_block, new_block;
-	int result = -EINVAL;
+	int result;
 
 	if (inode_permission(inode, MAY_READ) != 0) {
 		udf_debug("no permission to access inode %lu\n", inode->i_ino);
-		result = -EPERM;
-		goto out;
+		return -EPERM;
 	}
 
 	if (!arg && ((cmd == UDF_GETVOLIDENT) || (cmd == UDF_GETEASIZE) ||
 		     (cmd == UDF_RELOCATE_BLOCKS) || (cmd == UDF_GETEABLOCK))) {
 		udf_debug("invalid argument to udf_ioctl\n");
-		result = -VM_FAULT_SIGBUS;
-		goto out;
+		return -VM_FAULT_SIGBUS;
 	}
 
 	switch (cmd) {
 	case UDF_GETVOLIDENT:
 		if (copy_to_user((char __user *)arg,
 				 UDF_SB(inode->i_sb)->s_volume_ident, 32))
-			result = -EFAULT;
+			return -EFAULT;
 		else
-			result = 0;
-		goto out;
+			return 0;
 	case UDF_RELOCATE_BLOCKS:
-		if (!capable(CAP_SYS_ADMIN)) {
-			result = -EPERM;
-			goto out;
-		}
-		if (get_user(old_block, (long __user *)arg)) {
-			result = -EFAULT;
-			goto out;
-		}
+		if (!capable(CAP_SYS_ADMIN))
+			return -EPERM;
+
+		if (get_user(old_block, (long __user *)arg))
+			return -EFAULT;
+
 		result = udf_relocate_blocks(inode->i_sb,
 						old_block, &new_block);
 		if (result == 0)
 			result = put_user(new_block, (long __user *)arg);
-		goto out;
+
+		return result;
 	case UDF_GETEASIZE:
-		result = put_user(UDF_I(inode)->i_lenEAttr, (int __user *)arg);
-		goto out;
+		return put_user(UDF_I(inode)->i_lenEAttr, (int __user *)arg);
 	case UDF_GETEABLOCK:
-		result = copy_to_user((char __user *)arg,
+		return copy_to_user((char __user *)arg,
 				      UDF_I(inode)->i_ext.i_data,
 				      UDF_I(inode)->i_lenEAttr) ? -EFAULT : 0;
-		goto out;
 	default:
 		return -ENOIOCTLCMD;
 	}
-
-out:
-	return result;
 }
 
 static int udf_release_file(struct inode *inode, struct file *filp)
-- 
2.9.3

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

* [PATCH 3/3 linux-next] udf: remove else after return in udf_ioctl()
  2017-01-24 20:48 [PATCH 1/3 linux-next] udf: fix ioctl errors Fabian Frederick
  2017-01-24 20:48 ` [PATCH 2/3 linux-next] udf: simplify udf_ioctl() Fabian Frederick
@ 2017-01-24 20:48 ` Fabian Frederick
  2017-02-03 15:19 ` [PATCH 1/3 linux-next] udf: fix ioctl errors Jan Kara
  2 siblings, 0 replies; 5+ messages in thread
From: Fabian Frederick @ 2017-01-24 20:48 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-fsdevel, linux-kernel, fabf

else after return is not needed.

Signed-off-by: Fabian Frederick <fabf@skynet.be>
---
 fs/udf/file.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/udf/file.c b/fs/udf/file.c
index 00931fa..a1fec1b 100644
--- a/fs/udf/file.c
+++ b/fs/udf/file.c
@@ -194,8 +194,7 @@ long udf_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		if (copy_to_user((char __user *)arg,
 				 UDF_SB(inode->i_sb)->s_volume_ident, 32))
 			return -EFAULT;
-		else
-			return 0;
+		return 0;
 	case UDF_RELOCATE_BLOCKS:
 		if (!capable(CAP_SYS_ADMIN))
 			return -EPERM;
-- 
2.9.3

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

* Re: [PATCH 1/3 linux-next] udf: fix ioctl errors
  2017-01-24 20:48 [PATCH 1/3 linux-next] udf: fix ioctl errors Fabian Frederick
  2017-01-24 20:48 ` [PATCH 2/3 linux-next] udf: simplify udf_ioctl() Fabian Frederick
  2017-01-24 20:48 ` [PATCH 3/3 linux-next] udf: remove else after return in udf_ioctl() Fabian Frederick
@ 2017-02-03 15:19 ` Jan Kara
  2 siblings, 0 replies; 5+ messages in thread
From: Jan Kara @ 2017-02-03 15:19 UTC (permalink / raw)
  To: Fabian Frederick; +Cc: Jan Kara, linux-fsdevel, linux-kernel

On Tue 24-01-17 21:48:34, Fabian Frederick wrote:
> Currently, lsattr for instance in udf directory gives
> "udf: Invalid argument While reading flags on ..."
> 
> This patch returns -ENOIOCTLCMD
> when command is unknown to have more accurate message like this:
> "Inappropriate ioctl for device While reading flags on ..."
> 
> As suggested by Jan Kara, if arg is NULL with a correct ioctl,
> we return -VM_FAULT_SIGBUS to report error.

You cannot return -VM_FAULT_SIGBUS from ioctl handler! Just look how it is
defined - it is an internal error code to the fault handling and in this
case would just get passed as is to userspace. Which suggests you didn't
test this check... Anyway, I've taken the patch and just removed the change
of the error code. Thanks.

								Honza

> 
> Signed-off-by: Fabian Frederick <fabf@skynet.be>
> ---
>  fs/udf/file.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/udf/file.c b/fs/udf/file.c
> index dbcb3a4a..d44b3cb 100644
> --- a/fs/udf/file.c
> +++ b/fs/udf/file.c
> @@ -184,9 +184,10 @@ long udf_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>  		goto out;
>  	}
>  
> -	if (!arg) {
> +	if (!arg && ((cmd == UDF_GETVOLIDENT) || (cmd == UDF_GETEASIZE) ||
> +		     (cmd == UDF_RELOCATE_BLOCKS) || (cmd == UDF_GETEABLOCK))) {
>  		udf_debug("invalid argument to udf_ioctl\n");
> -		result = -EINVAL;
> +		result = -VM_FAULT_SIGBUS;
>  		goto out;
>  	}
>  
> @@ -220,6 +221,8 @@ long udf_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>  				      UDF_I(inode)->i_ext.i_data,
>  				      UDF_I(inode)->i_lenEAttr) ? -EFAULT : 0;
>  		goto out;
> +	default:
> +		return -ENOIOCTLCMD;
>  	}
>  
>  out:
> -- 
> 2.9.3
> 
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* Re: [PATCH 2/3 linux-next] udf: simplify udf_ioctl()
  2017-01-24 20:48 ` [PATCH 2/3 linux-next] udf: simplify udf_ioctl() Fabian Frederick
@ 2017-02-03 15:25   ` Jan Kara
  0 siblings, 0 replies; 5+ messages in thread
From: Jan Kara @ 2017-02-03 15:25 UTC (permalink / raw)
  To: Fabian Frederick; +Cc: Jan Kara, linux-fsdevel, linux-kernel

On Tue 24-01-17 21:48:35, Fabian Frederick wrote:
> "out" label was only returning error code.
> 
> Signed-off-by: Fabian Frederick <fabf@skynet.be>

Thanks. I've taken this patch and squashed patch 3 into this one.

								Honza

> ---
>  fs/udf/file.c | 39 +++++++++++++++------------------------
>  1 file changed, 15 insertions(+), 24 deletions(-)
> 
> diff --git a/fs/udf/file.c b/fs/udf/file.c
> index d44b3cb..00931fa 100644
> --- a/fs/udf/file.c
> +++ b/fs/udf/file.c
> @@ -176,57 +176,48 @@ long udf_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>  {
>  	struct inode *inode = file_inode(filp);
>  	long old_block, new_block;
> -	int result = -EINVAL;
> +	int result;
>  
>  	if (inode_permission(inode, MAY_READ) != 0) {
>  		udf_debug("no permission to access inode %lu\n", inode->i_ino);
> -		result = -EPERM;
> -		goto out;
> +		return -EPERM;
>  	}
>  
>  	if (!arg && ((cmd == UDF_GETVOLIDENT) || (cmd == UDF_GETEASIZE) ||
>  		     (cmd == UDF_RELOCATE_BLOCKS) || (cmd == UDF_GETEABLOCK))) {
>  		udf_debug("invalid argument to udf_ioctl\n");
> -		result = -VM_FAULT_SIGBUS;
> -		goto out;
> +		return -VM_FAULT_SIGBUS;
>  	}
>  
>  	switch (cmd) {
>  	case UDF_GETVOLIDENT:
>  		if (copy_to_user((char __user *)arg,
>  				 UDF_SB(inode->i_sb)->s_volume_ident, 32))
> -			result = -EFAULT;
> +			return -EFAULT;
>  		else
> -			result = 0;
> -		goto out;
> +			return 0;
>  	case UDF_RELOCATE_BLOCKS:
> -		if (!capable(CAP_SYS_ADMIN)) {
> -			result = -EPERM;
> -			goto out;
> -		}
> -		if (get_user(old_block, (long __user *)arg)) {
> -			result = -EFAULT;
> -			goto out;
> -		}
> +		if (!capable(CAP_SYS_ADMIN))
> +			return -EPERM;
> +
> +		if (get_user(old_block, (long __user *)arg))
> +			return -EFAULT;
> +
>  		result = udf_relocate_blocks(inode->i_sb,
>  						old_block, &new_block);
>  		if (result == 0)
>  			result = put_user(new_block, (long __user *)arg);
> -		goto out;
> +
> +		return result;
>  	case UDF_GETEASIZE:
> -		result = put_user(UDF_I(inode)->i_lenEAttr, (int __user *)arg);
> -		goto out;
> +		return put_user(UDF_I(inode)->i_lenEAttr, (int __user *)arg);
>  	case UDF_GETEABLOCK:
> -		result = copy_to_user((char __user *)arg,
> +		return copy_to_user((char __user *)arg,
>  				      UDF_I(inode)->i_ext.i_data,
>  				      UDF_I(inode)->i_lenEAttr) ? -EFAULT : 0;
> -		goto out;
>  	default:
>  		return -ENOIOCTLCMD;
>  	}
> -
> -out:
> -	return result;
>  }
>  
>  static int udf_release_file(struct inode *inode, struct file *filp)
> -- 
> 2.9.3
> 
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

end of thread, other threads:[~2017-02-03 15:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-24 20:48 [PATCH 1/3 linux-next] udf: fix ioctl errors Fabian Frederick
2017-01-24 20:48 ` [PATCH 2/3 linux-next] udf: simplify udf_ioctl() Fabian Frederick
2017-02-03 15:25   ` Jan Kara
2017-01-24 20:48 ` [PATCH 3/3 linux-next] udf: remove else after return in udf_ioctl() Fabian Frederick
2017-02-03 15:19 ` [PATCH 1/3 linux-next] udf: fix ioctl errors Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).