Skip to contentSkip to conversation

vfs: ensure mount source is set to "none" if empty string specified

PATCH In review Prakash Sangappa 2 participants 3 messages Jul 11, 2024 – Jul 16, 2024 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfs: ensure mount source is set to "none" if empty string specified

Due to changes from commit 0f89589a8c6f1033cb847a606517998efb0da8ee mount source devname is no longer getting set to 'none' if an empty source string is passed. Therefore /proc/<PID>/mountinfo will have a empty string for source devname instead of 'none'.

This is due to following change in this commit
in vfs_parse_fs_string()

- if (v_size > 0) {

+       if (value) {
                param.string = kmemdup_nul(value, v_size, GFP_KERNEL);
                if (!param.string)
                        return -ENOMEM;
+               param.type = fs_value_is_string;
        }

That results in fc->source, which is copied from param.string, to point to an empty string instead of it being NULL. So, alloc_vfsmnt() called from vfs_create_mount() would be passed the empty string in fc->source not 'none'.

This patch fix checks if fc->source is an empty string in the call to alloc_vfsmnt() and passes 'none'.

The issue can be easily reproduced.
#mount -t tmpfs "" /tmp/tdir
#grep "/tmp/tdir" /proc/$$/mountinfo

With the fix
506 103 0:48 / /tmp/tdir rw,relatime shared:268 - tmpfs none rw,...

Without the fix
506 103 0:48 / /tmp/tdir rw,relatime shared:268 - tmpfs rw,...

---
 fs/namespace.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/namespace.c +2 -1
index 5a51315..409b48c 100644
@@ -1100,7 +1100,8 @@ struct vfsmount *vfs_create_mount(struct fs_context *fc)
 	if (!fc->root)
 		return ERR_PTR(-EINVAL);
 
-	mnt = alloc_vfsmnt(fc->source ?: "none");
+	mnt = alloc_vfsmnt(fc->source && strlen(fc->source) > 0 ?
+			   fc->source : "none");
 	if (!mnt)
 		return ERR_PTR(-ENOMEM);
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 3 lines

The issue can be easily reproduced.
#mount -t tmpfs "" /tmp/tdir
#grep "/tmp/tdir" /proc/$$/mountinfo

The kernel has accepted "" before the new mount api was introduced. So the regression was showing "none" when userspace requested "" which got fixed. The patch proposed right here would reintroduce the regression:

(1) 4.15

    root@b1:~# cat /proc/self/mountinfo | grep mnt
    386 28 0:52 / /mnt rw,relatime shared:223 - tmpfs  rw

(2) 5.4

    root@f1:~# cat /proc/self/mountinfo | grep mnt
    584 31 0:55 / /mnt rw,relatime shared:336 - tmpfs none rw

(3) 6.10-rc6

    root@localhost:~# cat /proc/self/mountinfo | grep mnt
    62 130 0:60 / /mnt rw,relatime shared:135 - tmpfs  rw,inode64
#2 lore raw
Quoted 11 lines · Christian Brauner
Quoted 4 lines

The issue can be easily reproduced.
#mount -t tmpfs "" /tmp/tdir
#grep "/tmp/tdir" /proc/$$/mountinfo

The kernel has accepted "" before the new mount api was introduced. So the regression was showing "none" when userspace requested "" which got fixed. The patch proposed right here would reintroduce the regression:

The commit messages do not indicate that ’none’ caused a regression and was changed back to being empty string again, unless I missed it.

I was under the impression ’none’ was added to address issues with parsing mount entries in /proc/<pid>mountinfo.
Below was a patch proposal describing the parsing issues with libmount and other software because the mount source is empty. Don’t think this patch was merged.

https://patchwork.kernel.org/project/linux-fsdevel/patch/[email protected]/

Due to changes in v5.4 timeframe the mount entry started showing ’none’ for source name.

Our Database application ran into an issue with libmount when moving from running on v5.4* kernel to v5.15* kernel version.

Quoted 12 lines

(1) 4.15

   root@b1:~# cat /proc/self/mountinfo | grep mnt
   386 28 0:52 / /mnt rw,relatime shared:223 - tmpfs  rw

(2) 5.4

   root@f1:~# cat /proc/self/mountinfo | grep mnt
   584 31 0:55 / /mnt rw,relatime shared:336 - tmpfs none rw

(3) 6.10-rc6

   root@localhost:~# cat /proc/self/mountinfo | grep mnt
   62 130 0:60 / /mnt rw,relatime shared:135 - tmpfs  rw,inode64