Skip to contentSkip to conversation

namespace: update event counter when umounting a deleted dentry

PATCH In review Andrey Ulanov 2 participants 4 messages Apr 14, 2016 – Apr 15, 2016 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 namespace: update event counter when umounting a deleted dentry

This change fixes a problem originally reported at:
https://github.com/coreos/bugs/issues/1153
You can find code that reproduces it at:
https://github.com/coreos/bugs/issues/1153#issuecomment-210201681

- m_start() in fs/namespace.c expects that ns->event is incremented each time a mount added or removed from ns->list.
- umount_tree() removes items from the list but does not increment event counter, expecting that it's done before the function is called.
- There are some codepaths that call umount_tree() without updating "event" counter. e.g. from __detach_mounts().
- When this happens m_start may reuse a cached mount structure that no longer belongs to ns->list (i.e. use after free which usually leads to infinite loop).

This change fixes the above problem by incrementing global event counter before invoking umount_tree().

---
 fs/namespace.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/namespace.c +3 -1
index 4fb1691..b06bb9a 100644
@@ -1562,6 +1562,7 @@ void __detach_mounts(struct dentry *dentry)
 		goto out_unlock;
 
 	lock_mount_hash();
+	event++;
 	while (!hlist_empty(&mp->m_list)) {
 		mnt = hlist_entry(mp->m_list.first, struct mount, mnt_mp_list);
 		if (mnt->mnt.mnt_flags & MNT_UMOUNT) {
@@ -1576,7 +1577,7 @@ out_unlock:
 	namespace_unlock();
 }
 
-/* 
+/*
  * Is the caller allowed to modify his namespace?
  */
 static inline bool may_mount(void)
@@ -1765,6 +1766,7 @@ void drop_collected_mounts(struct vfsmount *mnt)
 {
 	namespace_lock();
 	lock_mount_hash();
+	event++;
 	umount_tree(real_mount(mnt), UMOUNT_SYNC);
 	unlock_mount_hash();
 	namespace_unlock();
Signature · 1 line
2.8.0.rc3.226.g39d4020
maintainer
#1 lore raw

fs/namespace.c void __detach_mounts(struct dentry *dentry) · line 1565

Quoted 6 lines · Andrey Ulanov

+++ b/fs/namespace.c

fs/namespace.c +1 -0
@@ -1562,6 +1562,7 @@ void __detach_mounts(struct dentry *dentry)
 		goto out_unlock;
 
 	lock_mount_hash();
+	event++;

That part makes sense.

fs/namespace.c void drop_collected_mounts(struct vfsmount *mnt) · line 1769

Quoted 10 lines
fs/namespace.c +1 -1
-/* 
+/*
  * Is the caller allowed to modify his namespace?
  */

static inline bool may_mount(void)

fs/namespace.c +1 -0
@@ -1765,6 +1766,7 @@ void drop_collected_mounts(struct vfsmount *mnt)
 {
 	namespace_lock();
 	lock_mount_hash();
+	event++;

... but what the hell is this one for?

#2 lore raw

PATCH 1/1 namespace: update event counter when umounting a deleted dentry

- m_start() in fs/namespace.c expects that ns->event is incremented each time a mount added or removed from ns->list.
- umount_tree() removes items from the list but does not increment event counter, expecting that it's done before the function is called.
- There are some codepaths that call umount_tree() without updating "event" counter. e.g. from __detach_mounts().
- When this happens m_start may reuse a cached mount structure that no longer belongs to ns->list (i.e. use after free which usually leads to infinite loop).

This change fixes the above problem by incrementing global event counter before invoking umount_tree().

Change-Id I622c8e84dcb9fb63542372c5dbf0178ee86bb589
---
 fs/namespace.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/namespace.c +2 -1
index 4fb1691..72508d2 100644
@@ -1562,6 +1562,7 @@ void __detach_mounts(struct dentry *dentry)
 		goto out_unlock;
 
 	lock_mount_hash();
+	event++;
 	while (!hlist_empty(&mp->m_list)) {
 		mnt = hlist_entry(mp->m_list.first, struct mount, mnt_mp_list);
 		if (mnt->mnt.mnt_flags & MNT_UMOUNT) {
@@ -1576,7 +1577,7 @@ out_unlock:
 	namespace_unlock();
 }
 
-/* 
+/*
  * Is the caller allowed to modify his namespace?
  */
 static inline bool may_mount(void)
Signature · 1 line
2.8.0.rc3.226.g39d4020
#3 lore raw
In reply to Al Viro
Quoted 2 lines · Al Viro
Quoted 1 line

+ event++;

... but what the hell is this one for?

You're right this wasn't necessary. See updated patch.