* [PATCH] libfs: fix negative value support in simple_attr_write()
@ 2022-09-18 13:50 Eliav Farber
2022-09-19 8:28 ` Yicong Yang
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Eliav Farber @ 2022-09-18 13:50 UTC (permalink / raw)
To: viro, akpm, yangyicong, linux-fsdevel, linux-kernel
Cc: andriy.shevchenko, farbere, hhhawa, jonnyc
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.
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] libfs: fix negative value support in simple_attr_write()
2022-09-18 13:50 [PATCH] libfs: fix negative value support in simple_attr_write() Eliav Farber
@ 2022-09-19 8:28 ` Yicong Yang
2022-09-19 21:24 ` Andrew Morton
2022-09-23 16:59 ` Andy Shevchenko
2 siblings, 0 replies; 8+ messages in thread
From: Yicong Yang @ 2022-09-19 8:28 UTC (permalink / raw)
To: Eliav Farber
Cc: andriy.shevchenko, hhhawa, jonnyc, linux-fsdevel, viro, akpm,
yangyicong, linux-kernel
On 2022/9/18 21:50, 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.
>
> Fixes: 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()")
Thanks for fixing this.
Reviewed-by: Yicong Yang <yangyicong@hisilicon.com>
Sorry for my lack of knowledge for the -1 usage.
Thanks.
> 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);
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] libfs: fix negative value support in simple_attr_write()
2022-09-18 13:50 [PATCH] libfs: fix negative value support in simple_attr_write() Eliav Farber
2022-09-19 8:28 ` Yicong Yang
@ 2022-09-19 21:24 ` Andrew Morton
2022-09-20 8:27 ` Farber, Eliav
` (2 more replies)
2022-09-23 16:59 ` Andy Shevchenko
2 siblings, 3 replies; 8+ messages in thread
From: Andrew Morton @ 2022-09-19 21:24 UTC (permalink / raw)
To: Eliav Farber
Cc: viro, yangyicong, linux-fsdevel, linux-kernel, andriy.shevchenko,
hhhawa, jonnyc, Akinobu Mita
On Sun, 18 Sep 2022 13:50:36 +0000 Eliav Farber <farbere@amazon.com> 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.
>
https://lkml.kernel.org/r/20220919172418.45257-1-akinobu.mita@gmail.com
addresses the same thing.
Should the final version of this fix be backported into -stable trees?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] libfs: fix negative value support in simple_attr_write()
2022-09-19 21:24 ` Andrew Morton
@ 2022-09-20 8:27 ` Farber, Eliav
2022-09-20 12:48 ` VS: " Shevchenko, Andriy
2022-09-21 14:39 ` Andy Shevchenko
2 siblings, 0 replies; 8+ messages in thread
From: Farber, Eliav @ 2022-09-20 8:27 UTC (permalink / raw)
To: Andrew Morton
Cc: viro, yangyicong, linux-fsdevel, linux-kernel, andriy.shevchenko,
hhhawa, jonnyc, Akinobu Mita, Farber, Eliav
On 9/20/2022 12:24 AM, Andrew Morton wrote:
> On Sun, 18 Sep 2022 13:50:36 +0000 Eliav Farber <farbere@amazon.com>
> 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.
>>
>
> https://lkml.kernel.org/r/20220919172418.45257-1-akinobu.mita@gmail.com
> addresses the same thing.
>
> Should the final version of this fix be backported into -stable trees?
I think that my patch can be dropped in favor of Akinobu's patch.
--
Regards, Eliav
^ permalink raw reply [flat|nested] 8+ messages in thread
* VS: [PATCH] libfs: fix negative value support in simple_attr_write()
2022-09-19 21:24 ` Andrew Morton
2022-09-20 8:27 ` Farber, Eliav
@ 2022-09-20 12:48 ` Shevchenko, Andriy
2022-09-21 14:39 ` Andy Shevchenko
2 siblings, 0 replies; 8+ messages in thread
From: Shevchenko, Andriy @ 2022-09-20 12:48 UTC (permalink / raw)
To: Andrew Morton, Eliav Farber
Cc: viro@zeniv.linux.org.uk, yangyicong@hisilicon.com,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
hhhawa@amazon.com, jonnyc@amazon.com, Akinobu Mita
________________________________________
Lähettäjä: Andrew Morton <akpm@linux-foundation.org>
Lähetetty: tiistai 20. syyskuuta 2022 0.24
Vastaanottaja: Eliav Farber
Kopio: viro@zeniv.linux.org.uk; yangyicong@hisilicon.com; linux-fsdevel@vger.kernel.org; linux-kernel@vger.kernel.org; Shevchenko, Andriy; hhhawa@amazon.com; jonnyc@amazon.com; Akinobu Mita
Aihe: Re: [PATCH] libfs: fix negative value support in simple_attr_write()
On Sun, 18 Sep 2022 13:50:36 +0000 Eliav Farber <farbere@amazon.com> 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.
>
https://lkml.kernel.org/r/20220919172418.45257-1-akinobu.mita@gmail.com
addresses the same thing.
Should the final version of this fix be backported into -stable trees?
Oh, this rises the question, why the heck we even have the format parameter to those macros? Seems to me like a (hackish) workaround against the known issue which was introduced by the previously mentioned change.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] libfs: fix negative value support in simple_attr_write()
2022-09-19 21:24 ` Andrew Morton
2022-09-20 8:27 ` Farber, Eliav
2022-09-20 12:48 ` VS: " Shevchenko, Andriy
@ 2022-09-21 14:39 ` Andy Shevchenko
2022-09-21 14:40 ` Andy Shevchenko
2 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2022-09-21 14:39 UTC (permalink / raw)
To: Andrew Morton
Cc: Eliav Farber, viro, yangyicong, linux-fsdevel, linux-kernel,
hhhawa, jonnyc, Akinobu Mita
On Mon, Sep 19, 2022 at 02:24:13PM -0700, Andrew Morton wrote:
> On Sun, 18 Sep 2022 13:50:36 +0000 Eliav Farber <farbere@amazon.com> 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.
> >
>
> https://lkml.kernel.org/r/20220919172418.45257-1-akinobu.mita@gmail.com
> addresses the same thing.
>
> Should the final version of this fix be backported into -stable trees?
But it questioning the formatting string as a parameter. Why do we need that
in the first place then?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] libfs: fix negative value support in simple_attr_write()
2022-09-21 14:39 ` Andy Shevchenko
@ 2022-09-21 14:40 ` Andy Shevchenko
0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2022-09-21 14:40 UTC (permalink / raw)
To: Andrew Morton
Cc: Eliav Farber, viro, yangyicong, linux-fsdevel, linux-kernel,
hhhawa, jonnyc, Akinobu Mita
On Wed, Sep 21, 2022 at 05:39:09PM +0300, Andy Shevchenko wrote:
> On Mon, Sep 19, 2022 at 02:24:13PM -0700, Andrew Morton wrote:
> > On Sun, 18 Sep 2022 13:50:36 +0000 Eliav Farber <farbere@amazon.com> wrote:
...
> > https://lkml.kernel.org/r/20220919172418.45257-1-akinobu.mita@gmail.com
> > Should the final version of this fix be backported into -stable trees?
>
> But it questioning the formatting string as a parameter. Why do we need that
> in the first place then?
Sorry if above is the similar to something I have sent earlier, I had had an
issue with my IMAP and SMTP servers access.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] libfs: fix negative value support in simple_attr_write()
2022-09-18 13:50 [PATCH] libfs: fix negative value support in simple_attr_write() Eliav Farber
2022-09-19 8:28 ` Yicong Yang
2022-09-19 21:24 ` Andrew Morton
@ 2022-09-23 16:59 ` Andy Shevchenko
2 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2022-09-23 16:59 UTC (permalink / raw)
To: Eliav Farber
Cc: viro, akpm, yangyicong, linux-fsdevel, linux-kernel, hhhawa,
jonnyc
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
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-09-23 16:59 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-18 13:50 [PATCH] libfs: fix negative value support in simple_attr_write() Eliav Farber
2022-09-19 8:28 ` Yicong Yang
2022-09-19 21:24 ` Andrew Morton
2022-09-20 8:27 ` Farber, Eliav
2022-09-20 12:48 ` VS: " Shevchenko, Andriy
2022-09-21 14:39 ` Andy Shevchenko
2022-09-21 14:40 ` Andy Shevchenko
2022-09-23 16:59 ` Andy Shevchenko
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).