From 678063aa1425c5fee2dc993e6cd635f549601f8b Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: May 24 2023 15:05:33 +0000 Subject: libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value (git-fixes). --- diff --git a/patches.suse/libfs-add-DEFINE_SIMPLE_ATTRIBUTE_SIGNED-for-signed-.patch b/patches.suse/libfs-add-DEFINE_SIMPLE_ATTRIBUTE_SIGNED-for-signed-.patch new file mode 100644 index 0000000..92c063c --- /dev/null +++ b/patches.suse/libfs-add-DEFINE_SIMPLE_ATTRIBUTE_SIGNED-for-signed-.patch @@ -0,0 +1,133 @@ +From 2e41f274f9aa71cdcc69dc1f26a3f9304a651804 Mon Sep 17 00:00:00 2001 +From: Akinobu Mita +Date: Tue, 20 Sep 2022 02:24:16 +0900 +Subject: [PATCH] libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value +Git-commit: 2e41f274f9aa71cdcc69dc1f26a3f9304a651804 +Patch-mainline: v6.2-rc1 +References: git-fixes + +Patch series "fix error when writing negative value to simple attribute +files". + +The simple attribute files do not accept a negative value since the commit +488dac0c9237 ("libfs: fix error cast of negative value in +simple_attr_write()"), but some attribute files want to accept a negative +value. + + +This patch (of 3): + +The simple attribute files do not accept a negative value since the commit +488dac0c9237 ("libfs: fix error cast of negative value in +simple_attr_write()"), so we have to use a 64-bit value to write a +negative value. + +This adds DEFINE_SIMPLE_ATTRIBUTE_SIGNED for a signed value. + +Link: https://lkml.kernel.org/r/20220919172418.45257-1-akinobu.mita@gmail.com +Link: https://lkml.kernel.org/r/20220919172418.45257-2-akinobu.mita@gmail.com +Fixes: 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()") +Signed-off-by: Akinobu Mita +Reported-by: Zhao Gongyi +Reviewed-by: David Hildenbrand +Reviewed-by: Greg Kroah-Hartman +Cc: Alexander Viro +Cc: Jonathan Corbet +Cc: Oscar Salvador +Cc: Rafael J. Wysocki +Cc: Shuah Khan +Cc: Wei Yongjun +Cc: Yicong Yang +Signed-off-by: Andrew Morton +Acked-by: Takashi Iwai + +--- + fs/libfs.c | 22 +++++++++++++++++++--- + include/linux/fs.h | 12 ++++++++++-- + 2 files changed, 29 insertions(+), 5 deletions(-) + +--- a/fs/libfs.c ++++ b/fs/libfs.c +@@ -967,8 +967,8 @@ out: + EXPORT_SYMBOL_GPL(simple_attr_read); + + /* interpret the buffer as a number to call the set function with */ +-ssize_t simple_attr_write(struct file *file, const char __user *buf, +- size_t len, loff_t *ppos) ++static ssize_t simple_attr_write_xsigned(struct file *file, const char __user *buf, ++ size_t len, loff_t *ppos, bool is_signed) + { + struct simple_attr *attr; + unsigned long long val; +@@ -989,7 +989,10 @@ ssize_t simple_attr_write(struct file *f + goto out; + + attr->set_buf[size] = '\0'; +- ret = kstrtoull(attr->set_buf, 0, &val); ++ if (is_signed) ++ ret = kstrtoll(attr->set_buf, 0, &val); ++ else ++ ret = kstrtoull(attr->set_buf, 0, &val); + if (ret) + goto out; + ret = attr->set(attr->data, val); +@@ -999,8 +1002,21 @@ out: + mutex_unlock(&attr->mutex); + return ret; + } ++ ++ssize_t simple_attr_write(struct file *file, const char __user *buf, ++ size_t len, loff_t *ppos) ++{ ++ return simple_attr_write_xsigned(file, buf, len, ppos, false); ++} + EXPORT_SYMBOL_GPL(simple_attr_write); + ++ssize_t simple_attr_write_signed(struct file *file, const char __user *buf, ++ size_t len, loff_t *ppos) ++{ ++ return simple_attr_write_xsigned(file, buf, len, ppos, true); ++} ++EXPORT_SYMBOL_GPL(simple_attr_write_signed); ++ + /** + * generic_fh_to_dentry - generic helper for the fh_to_dentry export operation + * @sb: filesystem to do the file handle conversion on +--- a/include/linux/fs.h ++++ b/include/linux/fs.h +@@ -3631,7 +3631,7 @@ void simple_transaction_set(struct file + * All attributes contain a text representation of a numeric value + * that are accessed with the get() and set() functions. + */ +-#define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \ ++#define DEFINE_SIMPLE_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, __is_signed) \ + static int __fops ## _open(struct inode *inode, struct file *file) \ + { \ + __simple_attr_check_format(__fmt, 0ull); \ +@@ -3642,10 +3642,16 @@ static const struct file_operations __fo + .open = __fops ## _open, \ + .release = simple_attr_release, \ + .read = simple_attr_read, \ +- .write = simple_attr_write, \ ++ .write = (__is_signed) ? simple_attr_write_signed : simple_attr_write, \ + .llseek = generic_file_llseek, \ + } + ++#define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \ ++ DEFINE_SIMPLE_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, false) ++ ++#define DEFINE_SIMPLE_ATTRIBUTE_SIGNED(__fops, __get, __set, __fmt) \ ++ DEFINE_SIMPLE_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, true) ++ + static inline __printf(1, 2) + void __simple_attr_check_format(const char *fmt, ...) + { +@@ -3660,6 +3666,8 @@ ssize_t simple_attr_read(struct file *fi + size_t len, loff_t *ppos); + ssize_t simple_attr_write(struct file *file, const char __user *buf, + size_t len, loff_t *ppos); ++ssize_t simple_attr_write_signed(struct file *file, const char __user *buf, ++ size_t len, loff_t *ppos); + + struct ctl_table; + int proc_nr_files(struct ctl_table *table, int write, diff --git a/series.conf b/series.conf index cd7c308..a68dbb5 100644 --- a/series.conf +++ b/series.conf @@ -17688,6 +17688,7 @@ patches.suse/nilfs2-fix-shift-out-of-bounds-due-to-too-large-expo.patch patches.suse/lib-fonts-fix-undefined-behavior-in-bit-shift-for-ge.patch patches.suse/ocfs2-fix-memory-leak-in-ocfs2_stack_glue_init.patch + patches.suse/libfs-add-DEFINE_SIMPLE_ATTRIBUTE_SIGNED-for-signed-.patch patches.suse/ocfs2-fix-memory-leak-in-ocfs2_mount_volume.patch patches.suse/acct-fix-potential-integer-overflow-in-encode_comp_t.patch patches.suse/infiniband-READ-is-data-destination-not-source.patch