From 3dc3cca6e517d7d3427da5a70c7be356380d9bf8 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 15 Feb 2018 06:59:49 +0100 Subject: [PATCH] 4.4-stable patches added patches: nsfs-mark-dentry-with-dcache_rcuaccess.patch --- ...fs-mark-dentry-with-dcache_rcuaccess.patch | 60 +++++++++++++++++++ queue-4.4/series | 1 + 2 files changed, 61 insertions(+) create mode 100644 queue-4.4/nsfs-mark-dentry-with-dcache_rcuaccess.patch diff --git a/queue-4.4/nsfs-mark-dentry-with-dcache_rcuaccess.patch b/queue-4.4/nsfs-mark-dentry-with-dcache_rcuaccess.patch new file mode 100644 index 00000000000..d0750593065 --- /dev/null +++ b/queue-4.4/nsfs-mark-dentry-with-dcache_rcuaccess.patch @@ -0,0 +1,60 @@ +From 073c516ff73557a8f7315066856c04b50383ac34 Mon Sep 17 00:00:00 2001 +From: Cong Wang +Date: Wed, 19 Apr 2017 15:11:00 -0700 +Subject: nsfs: mark dentry with DCACHE_RCUACCESS + +From: Cong Wang + +commit 073c516ff73557a8f7315066856c04b50383ac34 upstream. + +Andrey reported a use-after-free in __ns_get_path(): + + spin_lock include/linux/spinlock.h:299 [inline] + lockref_get_not_dead+0x19/0x80 lib/lockref.c:179 + __ns_get_path+0x197/0x860 fs/nsfs.c:66 + open_related_ns+0xda/0x200 fs/nsfs.c:143 + sock_ioctl+0x39d/0x440 net/socket.c:1001 + vfs_ioctl fs/ioctl.c:45 [inline] + do_vfs_ioctl+0x1bf/0x1780 fs/ioctl.c:685 + SYSC_ioctl fs/ioctl.c:700 [inline] + SyS_ioctl+0x8f/0xc0 fs/ioctl.c:691 + +We are under rcu read lock protection at that point: + + rcu_read_lock(); + d = atomic_long_read(&ns->stashed); + if (!d) + goto slow; + dentry = (struct dentry *)d; + if (!lockref_get_not_dead(&dentry->d_lockref)) + goto slow; + rcu_read_unlock(); + +but don't use a proper RCU API on the free path, therefore a parallel +__d_free() could free it at the same time. We need to mark the stashed +dentry with DCACHE_RCUACCESS so that __d_free() will be called after all +readers leave RCU. + +Fixes: e149ed2b805f ("take the targets of /proc/*/ns/* symlinks to separate fs") +Cc: Alexander Viro +Cc: Andrew Morton +Reported-by: Andrey Konovalov +Signed-off-by: Cong Wang +Signed-off-by: Linus Torvalds +Cc: Eric Biggers +Signed-off-by: Greg Kroah-Hartman + +--- + fs/nsfs.c | 1 + + 1 file changed, 1 insertion(+) + +--- a/fs/nsfs.c ++++ b/fs/nsfs.c +@@ -95,6 +95,7 @@ slow: + return ERR_PTR(-ENOMEM); + } + d_instantiate(dentry, inode); ++ dentry->d_flags |= DCACHE_RCUACCESS; + dentry->d_fsdata = (void *)ns_ops; + d = atomic_long_cmpxchg(&ns->stashed, 0, (unsigned long)dentry); + if (d) { diff --git a/queue-4.4/series b/queue-4.4/series index 264f5e9397e..249f802c502 100644 --- a/queue-4.4/series +++ b/queue-4.4/series @@ -67,3 +67,4 @@ ahci-add-intel-cannon-lake-pch-h-pci-id.patch crypto-hash-introduce-crypto_hash_alg_has_setkey.patch crypto-cryptd-pass-through-absence-of-setkey.patch crypto-poly1305-remove-setkey-method.patch +nsfs-mark-dentry-with-dcache_rcuaccess.patch -- 2.47.3