Skip to content

Commit 08582d6

Browse files
amir73ilbrauner
authored andcommitted
fs: create helper file_user_path() for user displayed mapped file path
Overlayfs uses backing files with "fake" overlayfs f_path and "real" underlying f_inode, in order to use underlying inode aops for mapped files and to display the overlayfs path in /proc/<pid>/maps. In preparation for storing the overlayfs "fake" path instead of the underlying "real" path in struct backing_file, define a noop helper file_user_path() that returns f_path for now. Use the new helper in procfs and kernel logs whenever a path of a mapped file is displayed to users. Signed-off-by: Amir Goldstein <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 83bc1d2 commit 08582d6

File tree

7 files changed

+24
-8
lines changed

7 files changed

+24
-8
lines changed

arch/arc/kernel/troubleshoot.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ static void show_faulting_vma(unsigned long address)
9090
*/
9191
if (vma) {
9292
char buf[ARC_PATH_MAX];
93-
char *nm = "?";
93+
char *nm = "anon";
9494

9595
if (vma->vm_file) {
96-
nm = file_path(vma->vm_file, buf, ARC_PATH_MAX-1);
96+
/* XXX: can we use %pD below and get rid of buf? */
97+
nm = d_path(file_user_path(vma->vm_file), buf,
98+
ARC_PATH_MAX-1);
9799
if (IS_ERR(nm))
98100
nm = "?";
99101
}

fs/proc/base.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2218,7 +2218,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
22182218
rc = -ENOENT;
22192219
vma = find_exact_vma(mm, vm_start, vm_end);
22202220
if (vma && vma->vm_file) {
2221-
*path = vma->vm_file->f_path;
2221+
*path = *file_user_path(vma->vm_file);
22222222
path_get(path);
22232223
rc = 0;
22242224
}

fs/proc/nommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
5858

5959
if (file) {
6060
seq_pad(m, ' ');
61-
seq_file_path(m, file, "");
61+
seq_path(m, file_user_path(file), "");
6262
}
6363

6464
seq_putc(m, '\n');

fs/proc/task_mmu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
296296
if (anon_name)
297297
seq_printf(m, "[anon_shmem:%s]", anon_name->name);
298298
else
299-
seq_file_path(m, file, "\n");
299+
seq_path(m, file_user_path(file), "\n");
300300
goto done;
301301
}
302302

@@ -1967,7 +1967,7 @@ static int show_numa_map(struct seq_file *m, void *v)
19671967

19681968
if (file) {
19691969
seq_puts(m, " file=");
1970-
seq_file_path(m, file, "\n\t= ");
1970+
seq_path(m, file_user_path(file), "\n\t= ");
19711971
} else if (vma_is_initial_heap(vma)) {
19721972
seq_puts(m, " heap");
19731973
} else if (vma_is_initial_stack(vma)) {

fs/proc/task_nommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
157157

158158
if (file) {
159159
seq_pad(m, ' ');
160-
seq_file_path(m, file, "");
160+
seq_path(m, file_user_path(file), "");
161161
} else if (mm && vma_is_initial_stack(vma)) {
162162
seq_pad(m, ' ');
163163
seq_puts(m, "[stack]");

include/linux/fs.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,6 +2513,20 @@ static inline const struct path *file_real_path(struct file *f)
25132513
return &f->f_path;
25142514
}
25152515

2516+
/*
2517+
* file_user_path - get the path to display for memory mapped file
2518+
*
2519+
* When mmapping a file on a stackable filesystem (e.g., overlayfs), the file
2520+
* stored in ->vm_file is a backing file whose f_inode is on the underlying
2521+
* filesystem. When the mapped file path is displayed to user (e.g. via
2522+
* /proc/<pid>/maps), this helper should be used to get the path to display
2523+
* to the user, which is the path of the fd that user has requested to map.
2524+
*/
2525+
static inline const struct path *file_user_path(struct file *f)
2526+
{
2527+
return &f->f_path;
2528+
}
2529+
25162530
static inline struct file *file_clone_open(struct file *file)
25172531
{
25182532
return dentry_open(&file->f_path, file->f_flags, file->f_cred);

kernel/trace/trace_output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ static int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
404404
vmstart = vma->vm_start;
405405
}
406406
if (file) {
407-
ret = trace_seq_path(s, &file->f_path);
407+
ret = trace_seq_path(s, file_user_path(file));
408408
if (ret)
409409
trace_seq_printf(s, "[+0x%lx]",
410410
ip - vmstart);

0 commit comments

Comments
 (0)