[Devel] [PATCH RHEL7 COMMIT] ms/mnt: Only change user settable mount flags in remount

Konstantin Khorenko khorenko at virtuozzo.com
Tue Mar 15 09:04:11 PDT 2016


The commit is pushed to "branch-rh7-3.10.0-327.10.1.vz7.12.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-327.10.1.vz7.12.1
------>
commit f1af1e286c5d5dbd5afcfba031d9ee1398a33991
Author: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Date:   Tue Mar 15 20:04:11 2016 +0400

    ms/mnt: Only change user settable mount flags in remount
    
    ms commit a6138db815df ("mnt: Only change user settable mount flags in remount")
    
    Kenton Varda <kenton at sandstorm.io> discovered that by remounting a
    read-only bind mount read-only in a user namespace the
    MNT_LOCK_READONLY bit would be cleared, allowing an unprivileged user
    
    to the remount a read-only mount read-write.
    
    Correct this by replacing the mask of mount flags to preserve
    with a mask of mount flags that may be changed, and preserve
    all others.   This ensures that any future bugs with this mask and
    remount will fail in an easy to detect way where new mount flags
    simply won't change.
    
    Cc: stable at vger.kernel.org
    Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>
    Signed-off-by: "Eric W. Biederman" <ebiederm at xmission.com>
    Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
    
    Found during investigation of
    https://jira.sw.ru/browse/PSBM-43294
---
 fs/namespace.c        | 2 +-
 include/linux/mount.h | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index 787619b..dba0c40 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -2011,7 +2011,7 @@ static int do_remount(struct path *path, int flags, int mnt_flags,
 		err = do_check_and_remount_sb(sb, flags, data);
 	if (!err) {
 		br_write_lock(&vfsmount_lock);
-		mnt_flags |= mnt->mnt.mnt_flags & MNT_PROPAGATION_MASK;
+		mnt_flags |= mnt->mnt.mnt_flags & ~MNT_USER_SETTABLE_MASK;
 		mnt->mnt.mnt_flags = mnt_flags;
 		br_write_unlock(&vfsmount_lock);
 	}
diff --git a/include/linux/mount.h b/include/linux/mount.h
index f8285ec..d1e3811 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -42,7 +42,9 @@ struct mnt_namespace;
  * flag, consider how it interacts with shared mounts.
  */
 #define MNT_SHARED_MASK	(MNT_UNBINDABLE)
-#define MNT_PROPAGATION_MASK	(MNT_SHARED | MNT_UNBINDABLE)
+#define MNT_USER_SETTABLE_MASK  (MNT_NOSUID | MNT_NODEV | MNT_NOEXEC \
+				 | MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME \
+				 | MNT_READONLY)
 
 #define MNT_INTERNAL_FLAGS (MNT_SHARED | MNT_WRITE_HOLD | MNT_INTERNAL | \
 			    MNT_MARKED)


More information about the Devel mailing list