From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757432AbbE2WV6 (ORCPT ); Fri, 29 May 2015 18:21:58 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:57043 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757237AbbE2WVo (ORCPT ); Fri, 29 May 2015 18:21:44 -0400 Date: Fri, 29 May 2015 15:21:43 -0700 From: Andrew Morton To: Kuenhwan Kwak Cc: Serge Hallyn , Chen Hanxiao , cpgs@samsung.com, linux-kernel@vger.kernel.org, "Eric W. Biederman" Subject: Re: [PATCH 1/1] /proc/$PID/status : show list NSpid data based on current process namespace. Message-Id: <20150529152143.5d3dce7fc4986744e4f64ac8@linux-foundation.org> In-Reply-To: <1432868242-11843-1-git-send-email-kh243.kwak@samsung.com> References: <1432868242-11843-1-git-send-email-kh243.kwak@samsung.com> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 29 May 2015 11:57:21 +0900 Kuenhwan Kwak wrote: > This patch helps creating a pid mapping data to parent processes. > > Reading 'NSpid' field in '/proc/$PID/status' is currently a simple > way to getting child pid from parent pid in userspace. But this field > supplies only single direction mapping('parent pid' to 'child pid'). > If parent process want to translate child pid to current namespace pid, > there is no way to get except full searching in current procfs. > > This patch will helps in getting current namespace pid by reading child > procfs file without any side effects. > > For example, Process id is 24771 in level 0, 435 in level 1. > a) The output of '/proc/24771/status' in level 0 namespace. > NSpid : 24771 435 > > b) The output of '/proc/435/status' in level 1 namespace. > NSpid : 435 > > c) Process in level 0 mount level1 proc to '/var/child/proc' > after setns(). The output of '/var/child/proc/435/status' is > NSpid : 24771 435 > > ... > > --- a/fs/proc/array.c > +++ b/fs/proc/array.c > @@ -83,6 +83,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -149,6 +150,9 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns, > const struct cred *cred; > pid_t ppid, tpid = 0, tgid, ngid; > unsigned int max_fds = 0; > +#ifdef CONFIG_PID_NS > + struct pid_namespace *current_pid_ns = task_active_pid_ns(current); > +#endif > > rcu_read_lock(); > ppid = pid_alive(p) ? > @@ -198,19 +202,19 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns, > > #ifdef CONFIG_PID_NS > seq_puts(m, "\nNStgid:"); > - for (g = ns->level; g <= pid->level; g++) > + for (g = current_pid_ns->level; g <= pid->level; g++) > seq_printf(m, "\t%d", > task_tgid_nr_ns(p, pid->numbers[g].ns)); > seq_puts(m, "\nNSpid:"); > - for (g = ns->level; g <= pid->level; g++) > + for (g = current_pid_ns->level; g <= pid->level; g++) > seq_printf(m, "\t%d", > task_pid_nr_ns(p, pid->numbers[g].ns)); > seq_puts(m, "\nNSpgid:"); > - for (g = ns->level; g <= pid->level; g++) > + for (g = current_pid_ns->level; g <= pid->level; g++) > seq_printf(m, "\t%d", > task_pgrp_nr_ns(p, pid->numbers[g].ns)); > seq_puts(m, "\nNSsid:"); > - for (g = ns->level; g <= pid->level; g++) > + for (g = current_pid_ns->level; g <= pid->level; g++) > seq_printf(m, "\t%d", > task_session_nr_ns(p, pid->numbers[g].ns)); These changes alter current behaviour, don't they? How do we know this won't impact existing userspace code?