Skip to contentSkip to conversation

concrete /proc/mounts

PATCH NAK J. R. Okajima 2 participants 3 messages May 26, 2019 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 concrete /proc/mounts

commit 1e83f8634c6efe7dd4e6036ee202ca10bdbca0b3

Author: J. R. Okajima <[email protected]>
Date:   Sat May 25 18:35:13 2019 +0900

concrete /proc/mounts

When the size of /proc/mounts exceeds PAGE_SIZE, seq_read() has to release namespace_sem via mounts_op.m_stop(). It means if someone else issues mount(2) or umount(2) and the mounts list got changed, then the continuous getmntent(3) calls show the incomplete mounts list and some entries may not appear in it.

This patch generates the full mounts list when mounts_op.m_start() is called, and keep it in the seq_file buffer until the file is closed. The size of the buffer increases if necessary. Other operations m_next, m_stop, m_show become meaningless, but still necessary for the seq_file manner.

I don't think the size of the buffer matters because many /proc entries already keep the similar PAGE_SIZE buffer. Increasing /proc/mounts buffer is to keep the correctness of the mount list.

See-also: https://github.com/kolyshkin/procfs-test

fs/mount.h +1 -3
index f39bc9da4d73..1ffd97696ca9 100644
@@ -131,9 +131,7 @@ struct proc_mounts {
 	struct mnt_namespace *ns;
 	struct path root;
 	int (*show)(struct seq_file *, struct vfsmount *);
-	void *cached_mount;
-	u64 cached_event;
-	loff_t cached_index;
+	bool filled;
 };
 
 extern const struct seq_operations mounts_op;
fs/namespace.c +51 -20

97 lines not on this page · raw message

fs/proc_namespace.c +0 -1
index 7626ee11b06c..f8aee5cca1b1 100644
@@ -279,7 +279,6 @@ static int mounts_open_common(struct inode *inode, struct file *file,
 	p->ns = ns;
 	p->root = root;
 	p->show = show;
-	p->cached_event = ~0ULL;
 
 	return 0;
 
maintainer NAK
#1 lore raw
Quoted 18 lines · J. R. Okajima

commit 1e83f8634c6efe7dd4e6036ee202ca10bdbca0b3

Author: J. R. Okajima <[email protected]>
Date:   Sat May 25 18:35:13 2019 +0900

concrete /proc/mounts

When the size of /proc/mounts exceeds PAGE_SIZE, seq_read() has to release namespace_sem via mounts_op.m_stop(). It means if someone else issues mount(2) or umount(2) and the mounts list got changed, then the continuous getmntent(3) calls show the incomplete mounts list and some entries may not appear in it.

This patch generates the full mounts list when mounts_op.m_start() is called, and keep it in the seq_file buffer until the file is closed. The size of the buffer increases if necessary. Other operations m_next, m_stop, m_show become meaningless, but still necessary for the seq_file manner.

Quoted 7 lines

I don't think the size of the buffer matters because many /proc entries already keep the similar PAGE_SIZE buffer. Increasing /proc/mounts buffer is to keep the correctness of the mount list.

See-also: https://github.com/kolyshkin/procfs-test

Translation: let's generate the entire contents on the first read() and keep it until the sucker's closed; that way userland wont' see anything changing under it. Oh, wait...

NAK.

#2 lore raw

Al Viro:

Quoted 5 lines

Translation: let's generate the entire contents on the first read() and keep it until the sucker's closed; that way userland wont' see anything changing under it. Oh, wait...

NAK.

Do you mean that the change can hide other mountpoints which are kept unchanged before/after read()?

J. R. Okajima