[Devel] [PATCH RH9 04/12] ve/ext3: treat panic_on_errors as remount-ro_on_errors in CTs

Kirill Tkhai ktkhai at virtuozzo.com
Thu Oct 7 13:20:16 MSK 2021


This is a port from 2.6.32-x of:

        * diff-ext4-in-containers-treat-panic_on_errors-as-remount-ro_on_errors

        ext4: in containers treat errors=panic as

        Container can explode whole node if it remounts its ploop
        with option 'errors=panic' and triggers abort after that.

        Signed-off-by: Konstantin Khlebnikov <khlebnikov at openvz.org>
        Acked-by: Maxim V. Patlasov <mpatlasov at parallels.com>

Signed-off-by: Dmitry Monakhov <dmonakhov at openvz.org>

khorenko@: currently we have devmnt->allowed_options options which are
configured via userspace and currently vzctl provides empty list.
This is an additional check - just in case someone get secondary
ploop image with 'errors=panic' mount option saved in the image
and mounts it from inside a CT.

Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 fs/ext4/super.c |   14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index f09a2432a20e..685686f5b849 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1906,6 +1906,7 @@ static int clear_qf_name(struct super_block *sb, int qtype)
 #define MOPT_STRING	0x0400
 #define MOPT_SKIP	0x0800
 #define	MOPT_2		0x1000
+#define MOPT_WANT_SYS_ADMIN	0x4000
 
 static const struct mount_opts {
 	int	token;
@@ -1938,7 +1939,7 @@ static const struct mount_opts {
 				    EXT4_MOUNT_JOURNAL_CHECKSUM),
 	 MOPT_EXT4_ONLY | MOPT_SET | MOPT_EXPLICIT},
 	{Opt_noload, EXT4_MOUNT_NOLOAD, MOPT_NO_EXT2 | MOPT_SET},
-	{Opt_err_panic, EXT4_MOUNT_ERRORS_PANIC, MOPT_SET | MOPT_CLEAR_ERR},
+	{Opt_err_panic, EXT4_MOUNT_ERRORS_PANIC, MOPT_SET | MOPT_CLEAR_ERR|MOPT_WANT_SYS_ADMIN},
 	{Opt_err_ro, EXT4_MOUNT_ERRORS_RO, MOPT_SET | MOPT_CLEAR_ERR},
 	{Opt_err_cont, EXT4_MOUNT_ERRORS_CONT, MOPT_SET | MOPT_CLEAR_ERR},
 	{Opt_data_err_abort, EXT4_MOUNT_DATA_ERR_ABORT,
@@ -2182,6 +2183,9 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
 	}
 	if (m->flags & MOPT_CLEAR_ERR)
 		clear_opt(sb, ERRORS_MASK);
+	if (m->flags & MOPT_WANT_SYS_ADMIN && !capable(CAP_SYS_ADMIN))
+		return 1;
+
 	if (token == Opt_noquota && sb_any_quota_loaded(sb)) {
 		ext4_msg(sb, KERN_ERR, "Cannot change quota "
 			 "options when quota turned on");
@@ -4226,8 +4230,12 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 	else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_WBACK)
 		set_opt(sb, WRITEBACK_DATA);
 
-	if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_PANIC)
-		set_opt(sb, ERRORS_PANIC);
+	if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_PANIC) {
+		if (capable(CAP_SYS_ADMIN))
+			set_opt(sb, ERRORS_PANIC);
+		else
+			set_opt(sb, ERRORS_RO);
+	}
 	else if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_CONTINUE)
 		set_opt(sb, ERRORS_CONT);
 	else




More information about the Devel mailing list