Skip to content

Commit a6138db

Browse files
committed
mnt: Only change user settable mount flags in remount
Kenton Varda <kenton@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@vger.kernel.org Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent 728dba3 commit a6138db

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Diff for: fs/namespace.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,7 @@ static int do_remount(struct path *path, int flags, int mnt_flags,
19371937
err = do_remount_sb(sb, flags, data, 0);
19381938
if (!err) {
19391939
lock_mount_hash();
1940-
mnt_flags |= mnt->mnt.mnt_flags & MNT_PROPAGATION_MASK;
1940+
mnt_flags |= mnt->mnt.mnt_flags & ~MNT_USER_SETTABLE_MASK;
19411941
mnt->mnt.mnt_flags = mnt_flags;
19421942
touch_mnt_namespace(mnt->mnt_ns);
19431943
unlock_mount_hash();

Diff for: include/linux/mount.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ struct mnt_namespace;
4242
* flag, consider how it interacts with shared mounts.
4343
*/
4444
#define MNT_SHARED_MASK (MNT_UNBINDABLE)
45-
#define MNT_PROPAGATION_MASK (MNT_SHARED | MNT_UNBINDABLE)
45+
#define MNT_USER_SETTABLE_MASK (MNT_NOSUID | MNT_NODEV | MNT_NOEXEC \
46+
| MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME \
47+
| MNT_READONLY)
4648

4749
#define MNT_INTERNAL_FLAGS (MNT_SHARED | MNT_WRITE_HOLD | MNT_INTERNAL | \
4850
MNT_DOOMED | MNT_SYNC_UMOUNT | MNT_MARKED)

0 commit comments

Comments
 (0)