Skip to contentSkip to conversation

libfs: fix negative value support in simple_attr_write()

PATCH In review Eliav Farber 4 participants 8 messages Sep 18, 2022 – Sep 23, 2022 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libfs: fix negative value support in simple_attr_write()

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()")
---
 fs/libfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/libfs.c +1 -1
index 31b0ddf01c31..3bccd75815db 100644
@@ -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);
Signature · 1 line
2.37.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Eliav Farber

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.

Quoted 4 lines

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.

Sorry for my lack of knowledge for the -1 usage.

Thanks.

Quoted 19 lines
---
 fs/libfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/libfs.c +1 -1
index 31b0ddf01c31..3bccd75815db 100644
@@ -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 lore raw
In reply to Eliav Farber
Quoted 9 lines · On Sun, 18 Sep 2022 13:50:36 +0000 Eliav Farber <[email protected]> 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.

Quoted 9 lines

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/[email protected]
addresses the same thing.

Should the final version of this fix be backported into -stable trees?

#3 lore raw
Quoted 17 lines · Andrew Morton
Quoted 15 lines · On Sun, 18 Sep 2022 13:50:36 +0000 Eliav Farber <[email protected]> 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.

Quoted 8 lines
Quoted 3 lines

This change basically reverts the mentioned commit, but uses kstrtoll() instead of simple_strtoll() which is obsolete.

https://lkml.kernel.org/r/[email protected]
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

#4 lore raw
In reply to Andrew Morton

________________________________________
Lähettäjä: Andrew Morton <[email protected]>
Lähetetty: tiistai 20. syyskuuta 2022 0.24
Vastaanottaja: Eliav Farber
Kopio: [email protected]; [email protected]; [email protected]; [email protected]; Shevchenko, Andriy; [email protected]; [email protected]; Akinobu Mita
Aihe: Re: [PATCH] libfs: fix negative value support in simple_attr_write()

Quoted 9 lines · On Sun, 18 Sep 2022 13:50:36 +0000 Eliav Farber <[email protected]> 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.

Quoted 9 lines

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/[email protected]
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.

#5 lore raw
In reply to Andrew Morton
Quoted 17 lines · Andrew Morton
Quoted 15 lines · On Sun, 18 Sep 2022 13:50:36 +0000 Eliav Farber <[email protected]> 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.

Quoted 8 lines
Quoted 3 lines

This change basically reverts the mentioned commit, but uses kstrtoll() instead of simple_strtoll() which is obsolete.

https://lkml.kernel.org/r/[email protected]
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?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Andrew Morton

On Sun, 18 Sep 2022 13:50:36 +0000 Eliav Farber <[email protected]> wrote:

...

Quoted 6 lines
Quoted 3 lines

https://lkml.kernel.org/r/[email protected]

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.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on v1 1/1
#7 lore raw
In reply to Eliav Farber
Quoted 9 lines · Eliav Farber

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.

Quoted 8 lines

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.

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

Quoted 22 lines
Fixes 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()")
---
 fs/libfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/libfs.c +1 -1
index 31b0ddf01c31..3bccd75815db 100644
@@ -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);
Signature · 1 line
2.37.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko