From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl0-f66.google.com ([209.85.160.66]:43593 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752077AbeDSDrv (ORCPT ); Wed, 18 Apr 2018 23:47:51 -0400 Received: by mail-pl0-f66.google.com with SMTP id a39-v6so2388494pla.10 for ; Wed, 18 Apr 2018 20:47:51 -0700 (PDT) From: Yecheng Fu To: Alexander Viro , Matthew Wilcox Cc: linux-fsdevel@vger.kernel.org, Karel Zak , Yecheng Fu Subject: [PATCH v2] vfs: use "none" if mount source is empty string Date: Thu, 19 Apr 2018 11:47:21 +0800 Message-Id: <1524109641-45617-1-git-send-email-cofyc.jackson@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: `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. This fixes issues in parsing when user uses empty string as mount source. Cc: Karel Zak Signed-off-by: Yecheng Fu --- PATCH v2 updates `show_vfsstat()` too. fs/proc_namespace.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c index 3f1190d..24591b8 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); @@ -202,7 +202,7 @@ static int show_vfsstat(struct seq_file *m, struct vfsmount *mnt) if (err) goto out; } else { - if (r->mnt_devname) { + if (r->mnt_devname && r->mnt_devname[0] != '\0') { seq_puts(m, "device "); mangle(m, r->mnt_devname); } else -- Yecheng Fu