aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2014-07-28 20:10:56 -0400
committerEric W. Biederman <ebiederm@xmission.com>2014-07-31 20:12:17 -0400
commit07b645589dcda8b7a5249e096fece2a67556f0f4 (patch)
tree984891e348c4ed58d8432aa9055b95ec89e5bf89
parenta6138db815df5ee542d848318e5dae681590fccd (diff)
mnt: Move the test for MNT_LOCK_READONLY from change_mount_flags into do_remount
There are no races as locked mount flags are guaranteed to never change. Moving the test into do_remount makes it more visible, and ensures all filesystem remounts pass the MNT_LOCK_READONLY permission check. This second case is not an issue today as filesystem remounts are guarded by capable(CAP_DAC_ADMIN) and thus will always fail in less privileged mount namespaces, but it could become an issue in the future. Cc: stable@vger.kernel.org Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
-rw-r--r--fs/namespace.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/fs/namespace.c b/fs/namespace.c
index cb40449ea0df..1105a577a14f 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1896,9 +1896,6 @@ static int change_mount_flags(struct vfsmount *mnt, int ms_flags)
1896 if (readonly_request == __mnt_is_readonly(mnt)) 1896 if (readonly_request == __mnt_is_readonly(mnt))
1897 return 0; 1897 return 0;
1898 1898
1899 if (mnt->mnt_flags & MNT_LOCK_READONLY)
1900 return -EPERM;
1901
1902 if (readonly_request) 1899 if (readonly_request)
1903 error = mnt_make_readonly(real_mount(mnt)); 1900 error = mnt_make_readonly(real_mount(mnt));
1904 else 1901 else
@@ -1924,6 +1921,16 @@ static int do_remount(struct path *path, int flags, int mnt_flags,
1924 if (path->dentry != path->mnt->mnt_root) 1921 if (path->dentry != path->mnt->mnt_root)
1925 return -EINVAL; 1922 return -EINVAL;
1926 1923
1924 /* Don't allow changing of locked mnt flags.
1925 *
1926 * No locks need to be held here while testing the various
1927 * MNT_LOCK flags because those flags can never be cleared
1928 * once they are set.
1929 */
1930 if ((mnt->mnt.mnt_flags & MNT_LOCK_READONLY) &&
1931 !(mnt_flags & MNT_READONLY)) {
1932 return -EPERM;
1933 }
1927 err = security_sb_remount(sb, data); 1934 err = security_sb_remount(sb, data);
1928 if (err) 1935 if (err)
1929 return err; 1936 return err;