@@ -30,10 +30,32 @@
typedef void ext4_update_sb_callback(struct ext4_super_block *es,
const void *arg);
+static int sb_attr_errors_check(struct ext4_sbattr *p_sbattr)
+{
+ __u16 error_behavior = *(__u16 *)(p_sbattr->sba_value);
+
+ if (p_sbattr->sba_len != EXT4_IOC_SUPERBLOCK_LEN_S_ERRORS)
+ return -EINVAL;
+
+ if (error_behavior < EXT4_ERRORS_CONTINUE ||
+ error_behavior > EXT4_ERRORS_PANIC)
+ return -EINVAL;
+
+ return 0;
+}
+
+static void sb_attr_errors_set(struct ext4_super_block *es, const void *arg)
+{
+ struct ext4_sbattr *p_sbattr = (struct ext4_sbattr *)arg;
+
+ es->s_errors = cpu_to_le16(*(__u16 *)p_sbattr->sba_value);
+}
+
/*
* Check and modify functions for each superblock variable
*/
struct ext4_sbattr_operation ext4_sbattr_ops[] = {
+ {EXT4_IOC_SUPERBLOCK_KEY_S_ERRORS, sb_attr_errors_check, sb_attr_errors_set},
{EXT4_IOC_SUPERBLOCK_KEY_MAX, NULL, NULL},
};
@@ -90,8 +90,10 @@ struct ext4_sbattr {
};
enum ext4_ioc_superblock_key {
- EXT4_IOC_SUPERBLOCK_KEY_MAX = 0,
+ EXT4_IOC_SUPERBLOCK_KEY_S_ERRORS = 0,
+ EXT4_IOC_SUPERBLOCK_KEY_MAX,
};
+#define EXT4_IOC_SUPERBLOCK_LEN_S_ERRORS 2
#define EXT4_SBATTR_MAX_COUNT 20
Added modifications to s_errors in the modification framework of superblock's attrs. There is no lock protection when the user mode operates on the same block, so I modify the s_errors by the modification framework of superblock's attrs. The parameters passed in from the user mode will be checked by sb_attr_errors_check first, if the check is passed, It will call buffer_lock in ext4_update_superblocks_fn and use sb_attr_errors_set, so it can ensure the atomicity of a modification. Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com> Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202308021801.ieUVR2xl-lkp@intel.com/ --- fs/ext4/ioctl.c | 22 ++++++++++++++++++++++ include/uapi/linux/ext4.h | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-)