lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 2 Aug 2023 16:34:02 +0800
From:   zhanchengbin <zhanchengbin1@...wei.com>
To:     <tytso@....edu>
CC:     <linux-ext4@...r.kernel.org>, <louhongxiang@...wei.com>,
        <linfeilong@...wei.com>, <yi.zhang@...wei.com>,
        <yebin10@...wei.com>, <liuzhiqiang26@...wei.com>,
        zhanchengbin <zhanchengbin1@...wei.com>
Subject: [RFC PATCH 2/2] ext4: ioctl add EXT4_IOC_SUPERBLOCK_KEY_S_ERRORS

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@...wei.com>
---
 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..81cb403bacf7 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);
 
+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;
+}
+
+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 a9f33a0399e8..aad2de6528dd 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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ