summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Krysiuk <piotras@gmail.com>2020-04-27 11:34:12 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-05-02 17:24:20 +0200
commite21c8c03af20932c15d8b1d3bb9cbad9607a6eab (patch)
tree5e75293578edcf86e8d7fe7830ff5fa56f17b9d6
parenta2dad369d0ee4c78467163c6a4a22f5b026e991d (diff)
downloadlinux-stable-e21c8c03af20932c15d8b1d3bb9cbad9607a6eab.tar.gz
linux-stable-e21c8c03af20932c15d8b1d3bb9cbad9607a6eab.tar.bz2
linux-stable-e21c8c03af20932c15d8b1d3bb9cbad9607a6eab.zip
fs/namespace.c: fix mountpoint reference counter race
A race condition between threads updating mountpoint reference counter affects longterm releases 4.4.220, 4.9.220, 4.14.177 and 4.19.118. The mountpoint reference counter corruption may occur when: * one thread increments m_count member of struct mountpoint [under namespace_sem, but not holding mount_lock] pivot_root() * another thread simultaneously decrements the same m_count [under mount_lock, but not holding namespace_sem] put_mountpoint() unhash_mnt() umount_mnt() mntput_no_expire() To fix this race condition, grab mount_lock before updating m_count in pivot_root(). Reference: CVE-2020-12114 Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Piotr Krysiuk <piotras@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--fs/namespace.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/fs/namespace.c b/fs/namespace.c
index e9c13eedd739..c8acc60c456d 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -3216,8 +3216,8 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
/* make certain new is below the root */
if (!is_path_reachable(new_mnt, new.dentry, &root))
goto out4;
- root_mp->m_count++; /* pin it so it won't go away */
lock_mount_hash();
+ root_mp->m_count++; /* pin it so it won't go away */
detach_mnt(new_mnt, &parent_path);
detach_mnt(root_mnt, &root_parent);
if (root_mnt->mnt.mnt_flags & MNT_LOCKED) {