Skip to contentSkip to conversation

seq_file_path() invocations and backslash escaping

PATCH Adam Osuchowski 1 participant 1 message Feb 25, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi all,

seq_file_path() invocations in several places have not specified proper characters set to escape. It leads to potentially ambiguous content in /proc/<pid>/maps, /proc/<pid>/smaps /proc/<pid>/numa_maps, and also in /proc/mdstat files. In corner cases contents of these files may be unparseable in correct way and may give invalid results (non-existing paths).

The reason is that if any of sensitive characters (space, TAB, NL, etc.) are escaped as octal using backslash character (ASCII 0x5C), the backslash itself should be escaped as well.

Find attached a patch for this issue.

Additionally, paths in contents of /proc/<pid>/{,s}maps files may have " (deleted)" string appended to them to indicate that path is non-existing. Maybe one should consider escaping space in paths in this files to distinguish non-existing path case from case when real path name ends with " (deleted)" string. Of course, then space in this suffix must not be escaped, only path part.

Regards,
Adam

fs/proc/task_mmu.c +2 -2
@@ -296,7 +296,7 @@
 		if (anon_name)
 			seq_printf(m, "[anon_shmem:%s]", anon_name->name);
 		else
-			seq_file_path(m, file, "\n");
+			seq_file_path(m, file, "\n\\");
 		goto done;
 	}
 
@@ -1967,7 +1967,7 @@
 
 	if (file) {
 		seq_puts(m, " file=");
-		seq_file_path(m, file, "\n\t= ");
+		seq_file_path(m, file, "\n\t= \\");
 	} else if (vma_is_initial_heap(vma)) {
 		seq_puts(m, " heap");
 	} else if (vma_is_initial_stack(vma)) {
drivers/md/md-bitmap.c +1 -1
@@ -2115,7 +2115,7 @@
 		   chunk_kb ? "KB" : "B");
 	if (bitmap->storage.file) {
 		seq_printf(seq, ", file: ");
-		seq_file_path(seq, bitmap->storage.file, " \t\n");
+		seq_file_path(seq, bitmap->storage.file, " \t\n\\");
 	}
 
 	seq_printf(seq, "\n");