diff mbox series

[2/2] vfs: escape hash as well

Message ID 165637625806.37717.2027157232247047949.stgit@donald.themaw.net (mailing list archive)
State New, archived
Headers show
Series vfs: fix a couple of mount table handling problems | expand

Commit Message

Ian Kent June 28, 2022, 12:30 a.m. UTC
From: Siddhesh Poyarekar <siddhesh@gotplt.org>

When a filesystem is mounted with a name that starts with a #:

 # mount '#name' /mnt/bad -t tmpfs

this will cause the entry to look like this (leading space added so
that git does not strip it out):

 #name /mnt/bad tmpfs rw,seclabel,relatime,inode64 0 0

This breaks getmntent and any code that aims to parse fstab as well as
/proc/mounts with the same logic since they need to strip leading spaces
or skip over comment lines, due to which they report incorrect output or
skip over the line respectively.

Solve this by translating the hash character into its octal encoding
equivalent so that applications can decode the name correctly.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
Signed-off-by: Ian Kent <raven@themaw.net>
---
 fs/proc_namespace.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Al Viro June 28, 2022, 5:57 p.m. UTC | #1
On Tue, Jun 28, 2022 at 08:30:58AM +0800, Ian Kent wrote:
> From: Siddhesh Poyarekar <siddhesh@gotplt.org>
> 
> When a filesystem is mounted with a name that starts with a #:
> 
>  # mount '#name' /mnt/bad -t tmpfs
> 
> this will cause the entry to look like this (leading space added so
> that git does not strip it out):
> 
>  #name /mnt/bad tmpfs rw,seclabel,relatime,inode64 0 0
> 
> This breaks getmntent and any code that aims to parse fstab as well as
> /proc/mounts with the same logic since they need to strip leading spaces
> or skip over comment lines, due to which they report incorrect output or
> skip over the line respectively.
> 
> Solve this by translating the hash character into its octal encoding
> equivalent so that applications can decode the name correctly.
> 
> Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
> Signed-off-by: Ian Kent <raven@themaw.net>

ACK; I'll grab that one (in #work.misc - I don't believe it's #fixes
fodder).
diff mbox series

Patch

diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c
index 49650e54d2f8..846f9455ae22 100644
--- a/fs/proc_namespace.c
+++ b/fs/proc_namespace.c
@@ -86,7 +86,7 @@  static void show_mnt_opts(struct seq_file *m, struct vfsmount *mnt)
 
 static inline void mangle(struct seq_file *m, const char *s)
 {
-	seq_escape(m, s, " \t\n\\");
+	seq_escape(m, s, " \t\n\\#");
 }
 
 static void show_type(struct seq_file *m, struct super_block *sb)