[PATCH] pidfd: show pids for nested pid namespaces in fdinfo
From: Christian Kellner
Date: Tue Oct 08 2019 - 09:37:11 EST
From: Christian Kellner <christian@xxxxxxxxxx>
The fdinfo file for a process file descriptor already contains the
pid of the process in the callers namespaces. Additionally, if pid
namespaces are configured, show the process ids of the process in
all nested namespaces in the same format as in the procfs status
file, i.e. "NSPid:\t%d\%d...". This allows the easy identification
of the processes in nested namespaces.
Signed-off-by: Christian Kellner <christian@xxxxxxxxxx>
---
kernel/fork.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/kernel/fork.c b/kernel/fork.c
index 5a0fd518e04e..801793789f33 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1685,8 +1685,18 @@ static void pidfd_show_fdinfo(struct seq_file *m, struct file *f)
{
struct pid_namespace *ns = proc_pid_ns(file_inode(m->file));
struct pid *pid = f->private_data;
+#ifdef CONFIG_PID_NS
+ int i;
+#endif
seq_put_decimal_ull(m, "Pid:\t", pid_nr_ns(pid, ns));
+#ifdef CONFIG_PID_NS
+ seq_puts(m, "\nNSpid:");
+ for (i = ns->level; i <= pid->level; i++) {
+ ns = pid_nr_ns(pid, pid->numbers[i].ns);
+ seq_put_decimal_ull(m, "\t", ns);
+ }
+#endif
seq_putc(m, '\n');
}
#endif
--
2.21.0