From: Jeff Liu <jeff.liu@oracle.com>
To: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>,
Dave Chinner <david@fromorbit.com>
Cc: linux-kernel@vger.kernel.org, xfs@oss.sgi.com
Subject: Re: [PATCH] xfs: Fix wrong error codes being returned
Date: Mon, 21 Apr 2014 20:46:39 +0800 [thread overview]
Message-ID: <5355132F.4070303@oracle.com> (raw)
In-Reply-To: <1398074687-26548-1-git-send-email-tuomas.tynkkynen@iki.fi>
Hi Tuomas,
On 04/21 2014 18:04 PM, Tuomas Tynkkynen wrote:
> xfs_{compat_,}attrmulti_by_handle could return an errno with incorrect
> sign in some cases. While at it, make sure ENOMEM is returned instead of
> E2BIG if kmalloc fails.
>
> Signed-off-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
> ---
> Compile tested only. For the ERANGE case, I also wonder if it should
> be assigning to ops[i].am_error instead of error, and/or have a break.
If I understand right, ops[i].am_error is used to save the internal operation result,
i.e, xfs_attrmult_attr_get{set}... but error is used for the ioctl call results.
Therefore, assign ERANGE to error is compatible with the VFS set{get}xattr syscalls in
case of "if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)".
It seems that we don't need to have a break in this case because xfs_attrmulti_by_handle()
is used to process multiple attrs. Hence if a given attrname in ops array is invalid,
the am_error will indicate that with ENOATTR or EFAULT...but it should proceed to loop
through the left array members.
Also, looks there is another minor issue at xfs_attrmulti_attr_set(), we should return
-PTR_ERR(kbuf) if call memdup_user() failed.
>
> fs/xfs/xfs_ioctl.c | 5 +++--
> fs/xfs/xfs_ioctl32.c | 5 +++--
> 2 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index 0b18776..2d8f4fd 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -543,10 +543,11 @@ xfs_attrmulti_by_handle(
>
> ops = memdup_user(am_hreq.ops, size);
> if (IS_ERR(ops)) {
> - error = PTR_ERR(ops);
> + error = -PTR_ERR(ops);
> goto out_dput;
> }
>
> + error = ENOMEM;
> attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL);
> if (!attr_name)
> goto out_kfree_ops;
> @@ -556,7 +557,7 @@ xfs_attrmulti_by_handle(
> ops[i].am_error = strncpy_from_user((char *)attr_name,
> ops[i].am_attrname, MAXNAMELEN);
> if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)
> - error = -ERANGE;
> + error = ERANGE;
> if (ops[i].am_error < 0)
> break;
>
> diff --git a/fs/xfs/xfs_ioctl32.c b/fs/xfs/xfs_ioctl32.c
> index a7992f8..944d5ba 100644
> --- a/fs/xfs/xfs_ioctl32.c
> +++ b/fs/xfs/xfs_ioctl32.c
> @@ -424,10 +424,11 @@ xfs_compat_attrmulti_by_handle(
>
> ops = memdup_user(compat_ptr(am_hreq.ops), size);
> if (IS_ERR(ops)) {
> - error = PTR_ERR(ops);
> + error = -PTR_ERR(ops);
> goto out_dput;
> }
>
> + error = ENOMEM;
> attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL);
> if (!attr_name)
> goto out_kfree_ops;
> @@ -438,7 +439,7 @@ xfs_compat_attrmulti_by_handle(
> compat_ptr(ops[i].am_attrname),
> MAXNAMELEN);
> if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)
> - error = -ERANGE;
> + error = ERANGE;
> if (ops[i].am_error < 0)
> break;
>
Thanks,
-Jeff
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
WARNING: multiple messages have this Message-ID (diff)
From: Jeff Liu <jeff.liu@oracle.com>
To: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>,
Dave Chinner <david@fromorbit.com>
Cc: linux-kernel@vger.kernel.org, xfs@oss.sgi.com
Subject: Re: [PATCH] xfs: Fix wrong error codes being returned
Date: Mon, 21 Apr 2014 20:46:39 +0800 [thread overview]
Message-ID: <5355132F.4070303@oracle.com> (raw)
In-Reply-To: <1398074687-26548-1-git-send-email-tuomas.tynkkynen@iki.fi>
Hi Tuomas,
On 04/21 2014 18:04 PM, Tuomas Tynkkynen wrote:
> xfs_{compat_,}attrmulti_by_handle could return an errno with incorrect
> sign in some cases. While at it, make sure ENOMEM is returned instead of
> E2BIG if kmalloc fails.
>
> Signed-off-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
> ---
> Compile tested only. For the ERANGE case, I also wonder if it should
> be assigning to ops[i].am_error instead of error, and/or have a break.
If I understand right, ops[i].am_error is used to save the internal operation result,
i.e, xfs_attrmult_attr_get{set}... but error is used for the ioctl call results.
Therefore, assign ERANGE to error is compatible with the VFS set{get}xattr syscalls in
case of "if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)".
It seems that we don't need to have a break in this case because xfs_attrmulti_by_handle()
is used to process multiple attrs. Hence if a given attrname in ops array is invalid,
the am_error will indicate that with ENOATTR or EFAULT...but it should proceed to loop
through the left array members.
Also, looks there is another minor issue at xfs_attrmulti_attr_set(), we should return
-PTR_ERR(kbuf) if call memdup_user() failed.
>
> fs/xfs/xfs_ioctl.c | 5 +++--
> fs/xfs/xfs_ioctl32.c | 5 +++--
> 2 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index 0b18776..2d8f4fd 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -543,10 +543,11 @@ xfs_attrmulti_by_handle(
>
> ops = memdup_user(am_hreq.ops, size);
> if (IS_ERR(ops)) {
> - error = PTR_ERR(ops);
> + error = -PTR_ERR(ops);
> goto out_dput;
> }
>
> + error = ENOMEM;
> attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL);
> if (!attr_name)
> goto out_kfree_ops;
> @@ -556,7 +557,7 @@ xfs_attrmulti_by_handle(
> ops[i].am_error = strncpy_from_user((char *)attr_name,
> ops[i].am_attrname, MAXNAMELEN);
> if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)
> - error = -ERANGE;
> + error = ERANGE;
> if (ops[i].am_error < 0)
> break;
>
> diff --git a/fs/xfs/xfs_ioctl32.c b/fs/xfs/xfs_ioctl32.c
> index a7992f8..944d5ba 100644
> --- a/fs/xfs/xfs_ioctl32.c
> +++ b/fs/xfs/xfs_ioctl32.c
> @@ -424,10 +424,11 @@ xfs_compat_attrmulti_by_handle(
>
> ops = memdup_user(compat_ptr(am_hreq.ops), size);
> if (IS_ERR(ops)) {
> - error = PTR_ERR(ops);
> + error = -PTR_ERR(ops);
> goto out_dput;
> }
>
> + error = ENOMEM;
> attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL);
> if (!attr_name)
> goto out_kfree_ops;
> @@ -438,7 +439,7 @@ xfs_compat_attrmulti_by_handle(
> compat_ptr(ops[i].am_attrname),
> MAXNAMELEN);
> if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)
> - error = -ERANGE;
> + error = ERANGE;
> if (ops[i].am_error < 0)
> break;
>
Thanks,
-Jeff
next prev parent reply other threads:[~2014-04-21 12:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-21 10:04 [PATCH] xfs: Fix wrong error codes being returned Tuomas Tynkkynen
2014-04-21 10:04 ` Tuomas Tynkkynen
2014-04-21 12:46 ` Jeff Liu [this message]
2014-04-21 12:46 ` Jeff Liu
2014-04-21 13:09 ` Brian Foster
2014-04-21 13:09 ` Brian Foster
2014-04-21 14:01 ` Jeff Liu
2014-04-21 14:01 ` Jeff Liu
2014-04-21 14:36 ` Brian Foster
2014-04-21 14:36 ` Brian Foster
2014-04-22 8:17 ` Jeff Liu
2014-04-22 8:17 ` Jeff Liu
2014-04-21 13:01 ` Brian Foster
2014-04-21 13:01 ` Brian Foster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5355132F.4070303@oracle.com \
--to=jeff.liu@oracle.com \
--cc=david@fromorbit.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tuomas.tynkkynen@iki.fi \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.