lkml.org 
[lkml]   [2022]   [Sep]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH] libfs: fix negative value support in simple_attr_write()
On Sun, Sep 18, 2022 at 01:50:36PM +0000, Eliav Farber wrote:
> After commit 488dac0c9237 ("libfs: fix error cast of negative value in
> simple_attr_write()"), a user trying set a negative value will get a
> '-EINVAL' error, because simple_attr_write() was modified to use
> kstrtoull() which can handle only unsigned values, instead of
> simple_strtoll().
>
> This breaks all the places using DEFINE_DEBUGFS_ATTRIBUTE() with format
> of a signed integer.
>
> The u64 value which attr->set() receives is not an issue for negative
> numbers.
> The %lld and %llu in any case are for 64-bit value. Representing it as
> unsigned simplifies the generic code, but it doesn't mean we can't keep
> their signed value if we know that.
>
> This change basically reverts the mentioned commit, but uses kstrtoll()
> instead of simple_strtoll() which is obsolete.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

and I prefer this one over spreading more macros with redundant formatting
parameter.

> Fixes: 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()")
> Signed-off-by: Eliav Farber <farbere@amazon.com>
> ---
> fs/libfs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/libfs.c b/fs/libfs.c
> index 31b0ddf01c31..3bccd75815db 100644
> --- a/fs/libfs.c
> +++ b/fs/libfs.c
> @@ -1016,7 +1016,7 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf,
> goto out;
>
> attr->set_buf[size] = '\0';
> - ret = kstrtoull(attr->set_buf, 0, &val);
> + ret = kstrtoll(attr->set_buf, 0, &val);
> if (ret)
> goto out;
> ret = attr->set(attr->data, val);
> --
> 2.37.1
>

--
With Best Regards,
Andy Shevchenko


\
 
 \ /
  Last update: 2022-09-23 19:00    [W:0.120 / U:0.280 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site