ext4: reject mount options not supported when remounting in handle_mount_opt()
A message that is not in the archive (sent off-list or not yet received): [email protected]
Theodore Ts'o
maintainerPATCH 1/1 ext4: reject mount options not supported when remounting in handle_mount_opt()
Rejecting the mount options in ext4_remount() means that some mount options would be enabled for a small amount of time, and then the mount option change would be reverted. In the case of "mount -o remount,dax", this can cause a race where files would temporarily treated as DAX --- and then not.
--- fs/ext4/super.c | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-)
fs/ext4/super.c +11 -26
@@ -1726,6 +1726,7 @@ static int clear_qf_name(struct super_block *sb, int qtype)#define MOPT_NO_EXT3 0x0200#define MOPT_EXT4_ONLY (MOPT_NO_EXT2 | MOPT_NO_EXT3)#define MOPT_STRING 0x0400 +#define MOPT_NO_REMOUNT 0x0800 static const struct mount_opts { int token;
@@ -1775,12 +1776,12 @@ static const struct mount_opts { {Opt_min_batch_time, 0, MOPT_GTE0}, {Opt_inode_readahead_blks, 0, MOPT_GTE0}, {Opt_init_itable, 0, MOPT_GTE0}, - {Opt_dax, EXT4_MOUNT_DAX, MOPT_SET}, + {Opt_dax, EXT4_MOUNT_DAX, MOPT_SET | MOPT_NO_REMOUNT}, {Opt_stripe, 0, MOPT_GTE0}, {Opt_resuid, 0, MOPT_GTE0}, {Opt_resgid, 0, MOPT_GTE0}, - {Opt_journal_dev, 0, MOPT_NO_EXT2 | MOPT_GTE0}, - {Opt_journal_path, 0, MOPT_NO_EXT2 | MOPT_STRING}, + {Opt_journal_dev, 0, MOPT_NO_EXT2 | MOPT_GTE0 | MOPT_NO_REMOUNT}, + {Opt_journal_path, 0, MOPT_NO_EXT2 | MOPT_STRING | MOPT_NO_REMOUNT}, {Opt_journal_ioprio, 0, MOPT_NO_EXT2 | MOPT_GTE0}, {Opt_data_journal, EXT4_MOUNT_JOURNAL_DATA, MOPT_NO_EXT2 | MOPT_DATAJ}, {Opt_data_ordered, EXT4_MOUNT_ORDERED_DATA, MOPT_NO_EXT2 | MOPT_DATAJ},
@@ -1817,7 +1818,7 @@ static const struct mount_opts { {Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT}, {Opt_max_dir_size_kb, 0, MOPT_GTE0}, {Opt_test_dummy_encryption, 0, MOPT_GTE0}, - {Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET}, + {Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET | MOPT_NO_REMOUNT}, {Opt_err, 0, 0} };
@@ -1915,6 +1916,12 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, "Mount option \"%s\" incompatible with ext3", opt);return -1 ; } +if ((m->flags &MOPT_NO_REMOUNT ) && is_remount) { +ext4_msg (sb,KERN_ERR , +"Mount option \"%s\" not supported when remounting" , + opt); +return -1 ; + }if (args->from && !(m->flags &MOPT_STRING ) &&match_int (args, &arg))return -1 ;
@@ -1994,11 +2001,6 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, } sbi->s_resgid = gid; }else if (token == Opt_journal_dev) { -if (is_remount) { -ext4_msg (sb,KERN_ERR , -"Cannot specify journal on remount" ); -return -1 ; - } *journal_devnum = arg; }else if (token == Opt_journal_path) {char *journal_path;
@@ -2006,11 +2008,6 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,struct path path;int error; -if (is_remount) { -ext4_msg (sb,KERN_ERR , -"Cannot specify journal on remount" ); -return -1 ; - } journal_path =match_strdup (&args[0 ]);if (!journal_path) { ext4_msg(sb, KERN_ERR, "error: could not dup "
@@ -5427,18 +5424,6 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) } } -if ((sbi->s_mount_opt ^ old_opts.s_mount_opt) &EXT4_MOUNT_NO_MBCACHE ) { -ext4_msg (sb,KERN_ERR ,"can't enable nombcache during remount" ); - err = -EINVAL ; - goto restore_opts; - } - -if ((sbi->s_mount_opt ^ old_opts.s_mount_opt) &EXT4_MOUNT_DAX ) { -ext4_msg (sb,KERN_WARNING ,"warning: refusing change of " -"dax flag with busy inodes while remounting" ); - sbi->s_mount_opt ^=EXT4_MOUNT_DAX ; - } -if (sbi->s_mount_flags &EXT4_MF_FS_ABORTED )ext4_abort (sb,EXT4_ERR_ESHUTDOWN ,"Abort forced by user" );
Signature · 1 line
2.24.1
Quoted 10 lines · Theodore Ts'o
Rejecting the mount options in
ext4_remount()means that some mount options would be enabled for a small amount of time, and then the mount option change would be reverted. In the case of "mount -o remount,dax", this can cause a race where files would temporarily treated as DAX --- and then not.Reported-and-tested-by [email protected]Signed-off-by Theodore Ts'o <[email protected]>
Quoted 98 lines
---
fs/ext4/super.c| 37 +++++++++++--------------------------1 file changed, 11 insertions(+), 26 deletions(-)fs/ext4/super.c +11
-27@@ -1726,6 +1726,7 @@ static int clear_qf_name(struct super_block *sb, int qtype)#define MOPT_NO_EXT3 0x0200#define MOPT_EXT4_ONLY (MOPT_NO_EXT2 | MOPT_NO_EXT3)#define MOPT_STRING 0x0400 +#define MOPT_NO_REMOUNT 0x0800 static const struct mount_opts { int token;@@ -1775,12 +1776,12 @@ static const struct mount_opts { {Opt_min_batch_time, 0, MOPT_GTE0}, {Opt_inode_readahead_blks, 0, MOPT_GTE0}, {Opt_init_itable, 0, MOPT_GTE0}, - {Opt_dax, EXT4_MOUNT_DAX, MOPT_SET}, + {Opt_dax, EXT4_MOUNT_DAX, MOPT_SET | MOPT_NO_REMOUNT}, {Opt_stripe, 0, MOPT_GTE0}, {Opt_resuid, 0, MOPT_GTE0}, {Opt_resgid, 0, MOPT_GTE0}, - {Opt_journal_dev, 0, MOPT_NO_EXT2 | MOPT_GTE0}, - {Opt_journal_path, 0, MOPT_NO_EXT2 | MOPT_STRING}, + {Opt_journal_dev, 0, MOPT_NO_EXT2 | MOPT_GTE0 | MOPT_NO_REMOUNT}, + {Opt_journal_path, 0, MOPT_NO_EXT2 | MOPT_STRING | MOPT_NO_REMOUNT}, {Opt_journal_ioprio, 0, MOPT_NO_EXT2 | MOPT_GTE0}, {Opt_data_journal, EXT4_MOUNT_JOURNAL_DATA, MOPT_NO_EXT2 | MOPT_DATAJ}, {Opt_data_ordered, EXT4_MOUNT_ORDERED_DATA, MOPT_NO_EXT2 | MOPT_DATAJ},@@ -1817,7 +1818,7 @@ static const struct mount_opts { {Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT}, {Opt_max_dir_size_kb, 0, MOPT_GTE0}, {Opt_test_dummy_encryption, 0, MOPT_GTE0}, - {Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET}, + {Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET | MOPT_NO_REMOUNT}, {Opt_err, 0, 0} };@@ -1915,6 +1916,12 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, "Mount option \"%s\" incompatible with ext3", opt);return -1 ; } +if ((m->flags &MOPT_NO_REMOUNT ) && is_remount) { +ext4_msg (sb,KERN_ERR , +"Mount option \"%s\" not supported when remounting" , + opt); +return -1 ; + }if (args->from && !(m->flags &MOPT_STRING ) &&match_int (args, &arg))return -1 ;@@ -1994,11 +2001,6 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, } sbi->s_resgid = gid; }else if (token == Opt_journal_dev) { -if (is_remount) { -ext4_msg (sb,KERN_ERR , -"Cannot specify journal on remount" ); -return -1 ; - } *journal_devnum = arg; }else if (token == Opt_journal_path) {char *journal_path;@@ -2006,11 +2008,6 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,struct path path;int error; -if (is_remount) { -ext4_msg (sb,KERN_ERR , -"Cannot specify journal on remount" ); -return -1 ; - } journal_path =match_strdup (&args[0 ]);if (!journal_path) { ext4_msg(sb, KERN_ERR, "error: could not dup "@@ -5427,18 +5424,6 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) } } -if ((sbi->s_mount_opt ^ old_opts.s_mount_opt) &EXT4_MOUNT_NO_MBCACHE ) { -ext4_msg (sb,KERN_ERR ,"can't enable nombcache during remount" ); - err = -EINVAL ; - goto restore_opts; - } - -if ((sbi->s_mount_opt ^ old_opts.s_mount_opt) &EXT4_MOUNT_DAX ) { -ext4_msg (sb,KERN_WARNING ,"warning: refusing change of " -"dax flag with busy inodes while remounting" ); - sbi->s_mount_opt ^=EXT4_MOUNT_DAX ; - } -if (sbi->s_mount_flags &EXT4_MF_FS_ABORTED )ext4_abort (sb,EXT4_ERR_ESHUTDOWN ,"Abort forced by user" ); --
Quoted 2 lines
2.24.1
Cheers, Andreas
Quoted 92 lines · Theodore Y. Ts'o
Rejecting the mount options in
ext4_remount()means that some mount options would be enabled for a small amount of time, and then the mount option change would be reverted. In the case of "mount -o remount,dax", this can cause a race where files would temporarily treated as DAX --- and then not.Reported-and-tested-by [email protected]Signed-off-by Theodore Ts'o <[email protected]>--- fs/ext4/super.c | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-)fs/ext4/super.c +11
-15@@ -1726,6 +1726,7 @@ static int clear_qf_name(struct super_block *sb, int qtype)#define MOPT_NO_EXT3 0x0200#define MOPT_EXT4_ONLY (MOPT_NO_EXT2 | MOPT_NO_EXT3)#define MOPT_STRING 0x0400 +#define MOPT_NO_REMOUNT 0x0800 static const struct mount_opts { int token;@@ -1775,12 +1776,12 @@ static const struct mount_opts { {Opt_min_batch_time, 0, MOPT_GTE0}, {Opt_inode_readahead_blks, 0, MOPT_GTE0}, {Opt_init_itable, 0, MOPT_GTE0}, - {Opt_dax, EXT4_MOUNT_DAX, MOPT_SET}, + {Opt_dax, EXT4_MOUNT_DAX, MOPT_SET | MOPT_NO_REMOUNT}, {Opt_stripe, 0, MOPT_GTE0}, {Opt_resuid, 0, MOPT_GTE0}, {Opt_resgid, 0, MOPT_GTE0}, - {Opt_journal_dev, 0, MOPT_NO_EXT2 | MOPT_GTE0}, - {Opt_journal_path, 0, MOPT_NO_EXT2 | MOPT_STRING}, + {Opt_journal_dev, 0, MOPT_NO_EXT2 | MOPT_GTE0 | MOPT_NO_REMOUNT}, + {Opt_journal_path, 0, MOPT_NO_EXT2 | MOPT_STRING | MOPT_NO_REMOUNT}, {Opt_journal_ioprio, 0, MOPT_NO_EXT2 | MOPT_GTE0}, {Opt_data_journal, EXT4_MOUNT_JOURNAL_DATA, MOPT_NO_EXT2 | MOPT_DATAJ}, {Opt_data_ordered, EXT4_MOUNT_ORDERED_DATA, MOPT_NO_EXT2 | MOPT_DATAJ},@@ -1817,7 +1818,7 @@ static const struct mount_opts { {Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT}, {Opt_max_dir_size_kb, 0, MOPT_GTE0}, {Opt_test_dummy_encryption, 0, MOPT_GTE0}, - {Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET}, + {Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET | MOPT_NO_REMOUNT}, {Opt_err, 0, 0} };@@ -1915,6 +1916,12 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, "Mount option \"%s\" incompatible with ext3", opt);return -1 ; } +if ((m->flags &MOPT_NO_REMOUNT ) && is_remount) { +ext4_msg (sb,KERN_ERR , +"Mount option \"%s\" not supported when remounting" , + opt); +return -1 ; + }if (args->from && !(m->flags &MOPT_STRING ) &&match_int (args, &arg))return -1 ;@@ -1994,11 +2001,6 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, } sbi->s_resgid = gid; }else if (token == Opt_journal_dev) { -if (is_remount) { -ext4_msg (sb,KERN_ERR , -"Cannot specify journal on remount" ); -return -1 ; - } *journal_devnum = arg; }else if (token == Opt_journal_path) {char *journal_path;@@ -2006,11 +2008,6 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,struct path path;int error; -if (is_remount) { -ext4_msg (sb,KERN_ERR , -"Cannot specify journal on remount" ); -return -1 ; - } journal_path =match_strdup (&args[0 ]);if (!journal_path) { ext4_msg(sb, KERN_ERR, "error: could not dup "@@ -5427,18 +5424,6 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) } } -if ((sbi->s_mount_opt ^ old_opts.s_mount_opt) &EXT4_MOUNT_NO_MBCACHE ) {
fs/ext4/super.c static int ext4_remount(struct super_block *sb, int *flags, char *data) · line 5440
Quoted 10 lines
fs/ext4/super.c +0
-10-ext4_msg (sb,KERN_ERR ,"can't enable nombcache during remount" ); - err = -EINVAL ; - goto restore_opts; - } - -if ((sbi->s_mount_opt ^ old_opts.s_mount_opt) &EXT4_MOUNT_DAX ) { -ext4_msg (sb,KERN_WARNING ,"warning: refusing change of " -"dax flag with busy inodes while remounting" ); - sbi->s_mount_opt ^=EXT4_MOUNT_DAX ; - }
I like the simplification but I'm confused...
This fundamentally changes the behavior from forcing the dax mode to be the same across the remount to only failing if we are going from non-dax to dax, adding -o dax on the remount?
But going from -o dax to 'not -o dax' would be ok?
FWIW after thinking about it some I _think_ it would be ok to allow the dax mode to change on a remount and let the inodes in memory stay in the mode they are at. And newly loaded inodes would get the new mode... Unfortunately without the STATX patch I have proposed the user does not have any way of knowing which files are in which mode.
Ira
Quoted 7 lines
fs/ext4/super.c +0
-1-if (sbi->s_mount_flags &EXT4_MF_FS_ABORTED )ext4_abort (sb,EXT4_ERR_ESHUTDOWN ,"Abort forced by user" );Signature · 1 line
2.24.1
Theodore Y. Ts'o
maintainerQuoted 11 lines · Ira Weiny
This fundamentally changes the behavior from forcing the dax mode to be the same across the remount to only failing if we are going from non-dax to dax, adding -o dax on the remount?
But going from -o dax to 'not -o dax' would be ok?
FWIW after thinking about it some I _think_ it would be ok to allow the dax mode to change on a remount and let the inodes in memory stay in the mode they are at. And newly loaded inodes would get the new mode... Unfortunately without the STATX patch I have proposed the user does not have any way of knowing which files are in which mode.
We don't currently support mount -o nodax. So the intention of the current code is that the dax mode can't change in either direction (enabling or disabling) as a remount option.
The syzkaller report was because changing dax mode racing with other operations given the current code base, could result in a kernel OOPS. So we *do* need to rule it out at least for now.
I certainly don't object to allowing changing dax mode as a remount --- so long as we have tests to make sure that if we stress opening, reading, writing, mmap'ing files, etc., while another thread is flipping back and forth between dax=never and dax=always is mount -o remount --- and make sure that we don't end up crashing.
And this test needs to be in xfstests, because trying to figure out what triggers a syzkaller failures in file system land is a pain in the *ss so we really want a dedicated xfstests for this case. Have you tested your patch series to make sure we don't have some potential races here?
- Ted
Quoted 7 lines · Theodore Y. Ts'o
Quoted 6 lines · Ira Weiny
This fundamentally changes the behavior from forcing the dax mode to be the same across the remount to only failing if we are going from non-dax to dax, adding -o dax on the remount?
But going from -o dax to 'not -o dax' would be ok?
Quoted 7 lines
Quoted 5 lines
FWIW after thinking about it some I _think_ it would be ok to allow the dax mode to change on a remount and let the inodes in memory stay in the mode they are at. And newly loaded inodes would get the new mode... Unfortunately without the STATX patch I have proposed the user does not have any way of knowing which files are in which mode.
We don't currently support mount -o nodax.
But we do support not supplying the option which means 'nodax' right?
Quoted 7 lines
So the intention of the
current code is that the dax mode can't change in either direction (enabling or disabling) as a remount option.The syzkaller report was because changing dax mode racing with other operations given the current code base, could result in a kernel OOPS. So we *do* need to rule it out at least for now.
But does this new patch prevent a dax change from '-o dax' to not specifying the option? I admit this option parsing code is confusing me. So I might be missing it completely.
Quoted 10 lines
I certainly don't object to allowing changing dax mode as a remount --- so long as we have tests to make sure that if we stress opening, reading, writing, mmap'ing files, etc., while another thread is flipping back and forth between dax=never and dax=always is mount -o remount --- and make sure that we don't end up crashing.
And this test needs to be in xfstests, because trying to figure out what triggers a syzkaller failures in file system land is a pain in the *ss so we really want a dedicated xfstests for this case.
Agreed.
Quoted 3 lines
Have
you tested your patch series to make sure we don't have some potential races here?
No, I've not anticipated the potential of this until today... :-D
Ira
Jan Kara
reviewerQuoted 14 lines · Ira Weiny
Quoted 13 lines · Theodore Y. Ts'o
Quoted 11 lines · Ira Weiny
This fundamentally changes the behavior from forcing the dax mode to be the same across the remount to only failing if we are going from non-dax to dax, adding -o dax on the remount?
But going from -o dax to 'not -o dax' would be ok?
FWIW after thinking about it some I _think_ it would be ok to allow the dax mode to change on a remount and let the inodes in memory stay in the mode they are at. And newly loaded inodes would get the new mode... Unfortunately without the STATX patch I have proposed the user does not have any way of knowing which files are in which mode.
Quoted 3 lines
Quoted 1 line
We don't currently support mount -o nodax.
But we do support not supplying the option which means 'nodax' right?
Yeah, I second what Ira wrote. The new code does not seem to properly detect a case when enabled mount option is removed for remount and thus the feature would get disabled during remount as a result...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Theodore Y. Ts'o
maintainerQuoted 15 lines · Jan Kara
Quoted 14 lines · Ira Weiny
Quoted 13 lines · Theodore Y. Ts'o
Quoted 11 lines · Ira Weiny
This fundamentally changes the behavior from forcing the dax mode to be the same across the remount to only failing if we are going from non-dax to dax, adding -o dax on the remount?
But going from -o dax to 'not -o dax' would be ok?
FWIW after thinking about it some I _think_ it would be ok to allow the dax mode to change on a remount and let the inodes in memory stay in the mode they are at. And newly loaded inodes would get the new mode... Unfortunately without the STATX patch I have proposed the user does not have any way of knowing which files are in which mode.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
We don't currently support mount -o nodax.
But we do support not supplying the option which means 'nodax' right?
Yeah, I second what Ira wrote. The new code does not seem to properly detect a case when enabled mount option is removed for remount and thus the feature would get disabled during remount as a result...
Sorry for not responding earlier. The way ext4 remounting working is not supplying an mount option which toggles a switch means that we don't change its current setting.
For example, if you mount with, say dioread_nolock, if you don't specify it when remounting, the current setting of dioread_nolock remains the same. If you want to change it, you need to specify the mount option nodioread_nolock. The change is true for discard vs nodiscard, etc.
We currently don't have nodax at all, which means that once dax is set, there is no way to unset the dax mount option. This was deliberate, because I was aware that the dax->no dax transition would result in badness.
Cheers,
- Ted
Quoted 34 lines · Theodore Y. Ts'o
Quoted 15 lines · Jan Kara
Quoted 14 lines · Ira Weiny
Quoted 13 lines · Theodore Y. Ts'o
Quoted 11 lines · Ira Weiny
This fundamentally changes the behavior from forcing the dax mode to be the same across the remount to only failing if we are going from non-dax to dax, adding -o dax on the remount?
But going from -o dax to 'not -o dax' would be ok?
FWIW after thinking about it some I _think_ it would be ok to allow the dax mode to change on a remount and let the inodes in memory stay in the mode they are at. And newly loaded inodes would get the new mode... Unfortunately without the STATX patch I have proposed the user does not have any way of knowing which files are in which mode.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
We don't currently support mount -o nodax.
But we do support not supplying the option which means 'nodax' right?
Yeah, I second what Ira wrote. The new code does not seem to properly detect a case when enabled mount option is removed for remount and thus the feature would get disabled during remount as a result...
Sorry for not responding earlier. The way ext4 remounting working is not supplying an mount option which toggles a switch means that we don't change its current setting.
For example, if you mount with, say
dioread_nolock, if you don't specify it when remounting, the current setting ofdioread_nolockremains the same. If you want to change it, you need to specify the mount optionnodioread_nolock. The change is true for discard vs nodiscard, etc.
Quoted 4 lines
We currently don't have nodax at all, which means that once dax is set, there is no way to unset the dax mount option. This was deliberate, because I was aware that the
dax->nodax transition would result in badness.
At this point I'm not sure if it was working correctly before or not.
I did keep this thread in mind and did a bit more testing on the latest version of the new DAX mount option parsing[1].
I have verified that whatever state (always, never, inode) dax was in, a remount does not affect it and the warning is printed.
Furthermore I think the lead patches disabling verity and encryption[2] in that series should help, if not fix, this bug.
Ted, do you think this series can make 5.8? The prelim patches [2] could be marked stable if you think they help without the rework of the mount option.
Thanks,
Ira
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/