From: Jan Kara <jack@suse.cz>
Subject: ext4: add allow_unsupported module parameter
Patch-mainline: never, SUSE-specific
References: fate#317919, SLE-8615, bsc#1149651
Disallow access to filesystem with unsupported features by default but
leave a chance to access the filesystem via module parameter override
(taints kernel).
The status can be toggled during runtime by changing the exported module
parameter in /sys.
Currently we make bigalloc feature supported only in read-only mode as it is
not completely mature yet.
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/ext4/ext4.h | 3 +++
fs/ext4/super.c | 21 +++++++++++++++++++++
2 files changed, 24 insertions(+)
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -39,6 +39,8 @@
#ifdef __KERNEL__
#include <linux/compat.h>
#endif
+#include <linux/module.h>
+#include <linux/unsupported-feature.h>
#include <linux/fscrypt.h>
#include <linux/fsverity.h>
@@ -3350,4 +3352,5 @@ extern const struct iomap_ops ext4_iomap
#define EFSBADCRC EBADMSG /* Bad CRC detected */
#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
+DECLARE_SUSE_UNSUPPORTED_FEATURE(ext4);
#endif /* _EXT4_H */
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -55,6 +55,8 @@
#include "mballoc.h"
#include "fsmap.h"
+DEFINE_SUSE_UNSUPPORTED_FEATURE(ext4)
+
#define CREATE_TRACE_POINTS
#include <trace/events/ext4.h>
@@ -2898,6 +2900,21 @@ static unsigned long ext4_get_stripe_siz
return ret;
}
+static int
+ext4_check_unsupported_ro(struct super_block *sb, bool allow_ro, bool readonly,
+ const char *description)
+{
+ if (allow_ro && readonly)
+ return 0;
+
+ if (ext4_allow_unsupported())
+ return 0;
+
+ ext4_msg(sb, KERN_ERR, "Couldn't mount %sbecause of SUSE-unsupported optional feature %s. Load module with allow_unsupported=1.",
+ allow_ro ? "RDWR " : "", description);
+ return -EINVAL;
+}
+
/*
* Check whether this filesystem can be mounted based on
* the features present and the RDONLY/RDWR mount requested.
@@ -2948,6 +2965,10 @@ static int ext4_feature_set_ok(struct su
return 0;
}
+ if (ext4_has_feature_bigalloc(sb) &&
+ ext4_check_unsupported_ro(sb, true, readonly, "BIGALLOC"))
+ return 0;
+
#if !IS_ENABLED(CONFIG_QUOTA) || !IS_ENABLED(CONFIG_QFMT_V2)
if (!readonly && (ext4_has_feature_quota(sb) ||
ext4_has_feature_project(sb))) {