[RFC PATCH v2 2/2] ext4: ioctl add EXT4_IOC_SUPERBLOCK_KEY_S_ERRORS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Closes: https://lore.kernel.org/oe-kbuild-all/202308021801.ieUVR2xl-lkp@xxxxxxxxx/
---
 fs/ext4/ioctl.c           | 22 ++++++++++++++++++++++
 include/uapi/linux/ext4.h |  4 +++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 76653d855073..4053a038da0a 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -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},
 };
 
diff --git a/include/uapi/linux/ext4.h b/include/uapi/linux/ext4.h
index 79b5a751b83e..f5429630343e 100644
--- a/include/uapi/linux/ext4.h
+++ b/include/uapi/linux/ext4.h
@@ -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
 
-- 
2.31.1




[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux