linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vfs: use "none" if mount source is empty string
@ 2018-04-18 15:18 Yecheng Fu
  2018-04-18 15:28 ` Matthew Wilcox
  0 siblings, 1 reply; 2+ messages in thread
From: Yecheng Fu @ 2018-04-18 15:18 UTC (permalink / raw)
  To: Alexander Viro; +Cc: linux-fsdevel, Karel Zak, Yecheng Fu

`libmount` from util-linux and many softwares in userspace (e.g.
kubelet) did not expect empty string as mount source:

```
$ mount -t tmpfs "" /mnt/tmpfs
$ findmnt /mnt/tmpfs
findmnt: /proc/self/mountinfo: parse error at line 51
$ cat /proc/self/mountinfo | grep -P '\/mnt\/tmpfs'
74 25 0:59 / /mnt/tmpfs rw,relatime shared:38 - tmpfs  rw
$ cat /proc/self/mounts | grep -P '\/mnt\/tmpfs'
 /mnt/tmpfs tmpfs rw,relatime 0 0
```

`source` field in mounts/mountinfo is empty, which breaks a lot of
mounts/mountinfo parsers when user use empty string as mount source.

This fixes issues in parsing when user use empty string as mount
source.

Cc: Karel Zak <kzak@redhat.com>
Signed-off-by: Yecheng Fu <cofyc.jackson@gmail.com>
---
 fs/proc_namespace.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c
index 3f1190d..0aa16a0 100644
--- a/fs/proc_namespace.c
+++ b/fs/proc_namespace.c
@@ -104,7 +104,7 @@ static int show_vfsmnt(struct seq_file *m, struct vfsmount *mnt)
 		if (err)
 			goto out;
 	} else {
-		mangle(m, r->mnt_devname ? r->mnt_devname : "none");
+		mangle(m, (r->mnt_devname && r->mnt_devname[0] != '\0') ? r->mnt_devname : "none");
 	}
 	seq_putc(m, ' ');
 	/* mountpoints outside of chroot jail will give SEQ_SKIP on this */
@@ -174,7 +174,7 @@ static int show_mountinfo(struct seq_file *m, struct vfsmount *mnt)
 		if (err)
 			goto out;
 	} else {
-		mangle(m, r->mnt_devname ? r->mnt_devname : "none");
+		mangle(m, (r->mnt_devname && r->mnt_devname[0] != '\0') ? r->mnt_devname : "none");
 	}
 	seq_puts(m, sb->s_flags & MS_RDONLY ? " ro" : " rw");
 	err = show_sb_opts(m, sb);
-- 
Yecheng Fu

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-04-18 15:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-18 15:18 [PATCH] vfs: use "none" if mount source is empty string Yecheng Fu
2018-04-18 15:28 ` Matthew Wilcox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).