Commit d55f90e9 authored by Christian Brauner's avatar Christian Brauner

ntfs3: enforce read-only when used as legacy ntfs driver

Ensure that ntfs3 is mounted read-only when it is used to provide the
legacy ntfs driver.
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent 74871791
...@@ -1154,4 +1154,6 @@ static inline void le64_sub_cpu(__le64 *var, u64 val) ...@@ -1154,4 +1154,6 @@ static inline void le64_sub_cpu(__le64 *var, u64 val)
*var = cpu_to_le64(le64_to_cpu(*var) - val); *var = cpu_to_le64(le64_to_cpu(*var) - val);
} }
bool is_legacy_ntfs(struct super_block *sb);
#endif /* _LINUX_NTFS3_NTFS_FS_H */ #endif /* _LINUX_NTFS3_NTFS_FS_H */
...@@ -408,6 +408,12 @@ static int ntfs_fs_reconfigure(struct fs_context *fc) ...@@ -408,6 +408,12 @@ static int ntfs_fs_reconfigure(struct fs_context *fc)
struct ntfs_mount_options *new_opts = fc->fs_private; struct ntfs_mount_options *new_opts = fc->fs_private;
int ro_rw; int ro_rw;
/* If ntfs3 is used as legacy ntfs enforce read-only mode. */
if (is_legacy_ntfs(sb)) {
fc->sb_flags |= SB_RDONLY;
goto out;
}
ro_rw = sb_rdonly(sb) && !(fc->sb_flags & SB_RDONLY); ro_rw = sb_rdonly(sb) && !(fc->sb_flags & SB_RDONLY);
if (ro_rw && (sbi->flags & NTFS_FLAGS_NEED_REPLAY)) { if (ro_rw && (sbi->flags & NTFS_FLAGS_NEED_REPLAY)) {
errorf(fc, errorf(fc,
...@@ -427,8 +433,6 @@ static int ntfs_fs_reconfigure(struct fs_context *fc) ...@@ -427,8 +433,6 @@ static int ntfs_fs_reconfigure(struct fs_context *fc)
fc, fc,
"ntfs3: Cannot use different iocharset when remounting!"); "ntfs3: Cannot use different iocharset when remounting!");
sync_filesystem(sb);
if (ro_rw && (sbi->volume.flags & VOLUME_FLAG_DIRTY) && if (ro_rw && (sbi->volume.flags & VOLUME_FLAG_DIRTY) &&
!new_opts->force) { !new_opts->force) {
errorf(fc, errorf(fc,
...@@ -436,6 +440,8 @@ static int ntfs_fs_reconfigure(struct fs_context *fc) ...@@ -436,6 +440,8 @@ static int ntfs_fs_reconfigure(struct fs_context *fc)
return -EINVAL; return -EINVAL;
} }
out:
sync_filesystem(sb);
swap(sbi->options, fc->fs_private); swap(sbi->options, fc->fs_private);
return 0; return 0;
...@@ -1613,6 +1619,8 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc) ...@@ -1613,6 +1619,8 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
} }
#endif #endif
if (is_legacy_ntfs(sb))
sb->s_flags |= SB_RDONLY;
return 0; return 0;
put_inode_out: put_inode_out:
...@@ -1730,7 +1738,7 @@ static const struct fs_context_operations ntfs_context_ops = { ...@@ -1730,7 +1738,7 @@ static const struct fs_context_operations ntfs_context_ops = {
* This will called when mount/remount. We will first initialize * This will called when mount/remount. We will first initialize
* options so that if remount we can use just that. * options so that if remount we can use just that.
*/ */
static int ntfs_init_fs_context(struct fs_context *fc) static int __ntfs_init_fs_context(struct fs_context *fc)
{ {
struct ntfs_mount_options *opts; struct ntfs_mount_options *opts;
struct ntfs_sb_info *sbi; struct ntfs_sb_info *sbi;
...@@ -1778,6 +1786,11 @@ static int ntfs_init_fs_context(struct fs_context *fc) ...@@ -1778,6 +1786,11 @@ static int ntfs_init_fs_context(struct fs_context *fc)
return -ENOMEM; return -ENOMEM;
} }
static int ntfs_init_fs_context(struct fs_context *fc)
{
return __ntfs_init_fs_context(fc);
}
static void ntfs3_kill_sb(struct super_block *sb) static void ntfs3_kill_sb(struct super_block *sb)
{ {
struct ntfs_sb_info *sbi = sb->s_fs_info; struct ntfs_sb_info *sbi = sb->s_fs_info;
...@@ -1800,10 +1813,20 @@ static struct file_system_type ntfs_fs_type = { ...@@ -1800,10 +1813,20 @@ static struct file_system_type ntfs_fs_type = {
}; };
#if IS_ENABLED(CONFIG_NTFS_FS) #if IS_ENABLED(CONFIG_NTFS_FS)
static int ntfs_legacy_init_fs_context(struct fs_context *fc)
{
int ret;
ret = __ntfs_init_fs_context(fc);
/* If ntfs3 is used as legacy ntfs enforce read-only mode. */
fc->sb_flags |= SB_RDONLY;
return ret;
}
static struct file_system_type ntfs_legacy_fs_type = { static struct file_system_type ntfs_legacy_fs_type = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "ntfs", .name = "ntfs",
.init_fs_context = ntfs_init_fs_context, .init_fs_context = ntfs_legacy_init_fs_context,
.parameters = ntfs_fs_parameters, .parameters = ntfs_fs_parameters,
.kill_sb = ntfs3_kill_sb, .kill_sb = ntfs3_kill_sb,
.fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
...@@ -1821,9 +1844,14 @@ static inline void unregister_as_ntfs_legacy(void) ...@@ -1821,9 +1844,14 @@ static inline void unregister_as_ntfs_legacy(void)
{ {
unregister_filesystem(&ntfs_legacy_fs_type); unregister_filesystem(&ntfs_legacy_fs_type);
} }
bool is_legacy_ntfs(struct super_block *sb)
{
return sb->s_type == &ntfs_legacy_fs_type;
}
#else #else
static inline void register_as_ntfs_legacy(void) {} static inline void register_as_ntfs_legacy(void) {}
static inline void unregister_as_ntfs_legacy(void) {} static inline void unregister_as_ntfs_legacy(void) {}
bool is_legacy_ntfs(struct super_block *sb) { return false; }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment