Skip to contentSkip to conversation

libfs: fix simple_attr_write on 32bit machine

PATCH In review Akinobu Mita 3 participants 4 messages Jul 9, 2011 – Aug 23, 2011 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libfs: fix simple_attr_write on 32bit machine

Assume that /sys/kernel/debug/dummy64 is debugfs file created by debugfs_create_x64().

	# cd /sys/kernel/debug
	# echo 0x1234567812345678 > dummy64
	# cat dummy64
	0x0000000012345678
	# echo 0x80000000 > dummy64
	# cat dummy64
	0xffffffff80000000

The value more than INT_MAX cannot be written to the debugfs file created by debugfs_create_u64 or debugfs_create_x64 on 32bit machine. Because simple_attr_write() uses simple_strtol() for the conversion.

To fix this, use simple_strtoll() instead.

Cc Greg Kroah-Hartman <[email protected]>
---
 fs/libfs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/libfs.c +1 -1
index c88eab5..275ca474 100644
@@ -822,7 +822,7 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf,
 		goto out;
 
 	attr->set_buf[size] = '\0';
-	val = simple_strtol(attr->set_buf, NULL, 0);
+	val = simple_strtoll(attr->set_buf, NULL, 0);
 	ret = attr->set(attr->data, val);
 	if (ret == 0)
 		ret = len; /* on success, claim we got the whole input */
Signature · 1 line
1.7.4.4
#1 lore raw
Quoted 29 lines · On Sat, 9 Jul 2011 14:00:26 +0900 Akinobu Mita <[email protected]> wrote:

Assume that /sys/kernel/debug/dummy64 is debugfs file created by debugfs_create_x64().

	# cd /sys/kernel/debug
	# echo 0x1234567812345678 > dummy64
	# cat dummy64
	0x0000000012345678
	# echo 0x80000000 > dummy64
	# cat dummy64
	0xffffffff80000000

The value more than INT_MAX cannot be written to the debugfs file created by debugfs_create_u64 or debugfs_create_x64 on 32bit machine. Because simple_attr_write() uses simple_strtol() for the conversion.

To fix this, use simple_strtoll() instead.

Cc Greg Kroah-Hartman <[email protected]>
---
 fs/libfs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/libfs.c +0 -0
index c88eab5..275ca474 100644

fs/libfs.c ssize_t simple_attr_write(struct file *file, const char __user *buf, · line 828

Quoted 8 lines
fs/libfs.c +1 -1
@@ -822,7 +822,7 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf,
 		goto out;
 
 	attr->set_buf[size] = '\0';
-	val = simple_strtol(attr->set_buf, NULL, 0);
+	val = simple_strtoll(attr->set_buf, NULL, 0);
 	ret = attr->set(attr->data, val);
 	if (ret == 0)
 		ret = len; /* on success, claim we got the whole input */

It should strictly be simple_strtoull(), but I guess that doesn't change anything.

And it should always have been strict_*(), now known as kstrto*(). But that interface fix is non-back-compatible so it's too late to fix it.

#2 lore raw
In reply to Akinobu Mita
Quoted 12 lines · Akinobu Mita

Assume that /sys/kernel/debug/dummy64 is debugfs file created by debugfs_create_x64().

	# cd /sys/kernel/debug
	# echo 0x1234567812345678 > dummy64
	# cat dummy64
	0x0000000012345678
	# echo 0x80000000 > dummy64
	# cat dummy64
	0xffffffff80000000
Quoted 8 lines

The value more than INT_MAX cannot be written to the debugfs file created by debugfs_create_u64 or debugfs_create_x64 on 32bit machine. Because simple_attr_write() uses simple_strtol() for the conversion.

To fix this, use simple_strtoll() instead.

Cc Greg Kroah-Hartman <[email protected]>

Do we have any debugfs files that need this change in the tree now for 3.1 or newer?

thanks,

greg k-h

#3 lore raw

2011/8/23 Greg KH <[email protected]>:

Quoted 17 lines · Akinobu Mita
Quoted 16 lines

Assume that /sys/kernel/debug/dummy64 is debugfs file created by debugfs_create_x64().

      # cd /sys/kernel/debug
      # echo 0x1234567812345678 > dummy64
      # cat dummy64
      0x0000000012345678
      # echo 0x80000000 > dummy64
      # cat dummy64
      0xffffffff80000000

The value more than INT_MAX cannot be written to the debugfs file created by debugfs_create_u64 or debugfs_create_x64 on 32bit machine. Because simple_attr_write() uses simple_strtol() for the conversion.

Quoted 7 lines
Quoted 4 lines

To fix this, use simple_strtoll() instead.

Cc Greg Kroah-Hartman <[email protected]>

Do we have any debugfs files that need this change in the tree now for 3.1 or newer?

This patch has already been merged into 3.0. Some files are created debugfs_create_[ux]64 with write permission and affected by this bug.

hwpoison/corrupt-filter-flags-mask
hwpoison/corrupt-filter-flags-value
hwpoison/corrupt-filter-memcg
apei/einj/param1
apei/einj/param2