All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][RFC] fs/exec.c: provide the correct process pid to the pipe helper
@ 2010-09-16 18:59 Will Drewry
       [not found] ` <1284663599-3549-1-git-send-email-wad-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
                   ` (2 more replies)
  0 siblings, 3 replies; 43+ messages in thread
From: Will Drewry @ 2010-09-16 18:59 UTC (permalink / raw)
  To: linux-kernel
  Cc: Alexander Viro, Andrew Morton, Oleg Nesterov, KOSAKI Motohiro,
	Roland McGrath, Neil Horman, Andi Kleen, Eric W. Biederman,
	containers, linux-fsdevel, Will Drewry

format_corename uses task_tgid_vnr to provide the numeric pid of a
core-dumping process.  For file-based coredumps, this is perfectly
satisfactory.  However, when the core_pattern contains a pipe, the
substituted PID is invalid in the namespace of the core_pattern pipe
helper, the init namespace.

By changing this, any core collector may now find the process in the
init namespace /proc.  This helps with VFS namespacing too since the
mount root is available via /proc.  Unfortunately, it does not help in
cases of more complex namespacing, like net namespaces.  For that, the
helper thread will need to be migrated to the core-dump namespaces.

I have a separate patch series which implements migrating the
____call_usermodehelper thread to the coredump namespace, but it adds a
fair amount of complexity which might be better handled by someone who
understands that code.  I'm happy to mail it out as well though (it
works, but I don't assign a namespaced pid which may open up issues on
its own).

Any and all comments, feedback will be appreciated!

Signed-off-by: Will Drewry <wad@chromium.org>
---
 fs/exec.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 828dd24..0b8a874 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1467,6 +1467,13 @@ static int format_corename(char *corename, long signr)
 	char *const out_end = corename + CORENAME_MAX_SIZE;
 	int rc;
 	int pid_in_pattern = 0;
+	pid_t pid = task_tgid_vnr(current);
+
+	/* The pipe helper runs in the init namespace and should
+	 * receive the matching pid until that changes.
+	 */
+	if (ispipe)
+		pid = task_tgid_nr(current);
 
 	/* Repeat as long as we have more pattern to process and more output
 	   space */
@@ -1489,7 +1496,7 @@ static int format_corename(char *corename, long signr)
 			case 'p':
 				pid_in_pattern = 1;
 				rc = snprintf(out_ptr, out_end - out_ptr,
-					      "%d", task_tgid_vnr(current));
+					      "%d", pid);
 				if (rc > out_end - out_ptr)
 					goto out;
 				out_ptr += rc;
@@ -1568,7 +1575,7 @@ static int format_corename(char *corename, long signr)
 	 * the filename. Do not do this for piped commands. */
 	if (!ispipe && !pid_in_pattern && core_uses_pid) {
 		rc = snprintf(out_ptr, out_end - out_ptr,
-			      ".%d", task_tgid_vnr(current));
+			      ".%d", pid);
 		if (rc > out_end - out_ptr)
 			goto out;
 		out_ptr += rc;
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 43+ messages in thread
* [PATCH][RFC] fs/exec.c: provide the correct process pid to the pipe helper
@ 2010-09-16 18:59 Will Drewry
  0 siblings, 0 replies; 43+ messages in thread
From: Will Drewry @ 2010-09-16 18:59 UTC (permalink / raw)
  To: linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: Will Drewry, Neil Horman,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	Oleg Nesterov, Andi Kleen, Alexander Viro, KOSAKI Motohiro,
	linux-fsdevel-u79uwXL29TY76Z2rM5mHXA, Andrew Morton,
	Roland McGrath, Eric W. Biederman

format_corename uses task_tgid_vnr to provide the numeric pid of a
core-dumping process.  For file-based coredumps, this is perfectly
satisfactory.  However, when the core_pattern contains a pipe, the
substituted PID is invalid in the namespace of the core_pattern pipe
helper, the init namespace.

By changing this, any core collector may now find the process in the
init namespace /proc.  This helps with VFS namespacing too since the
mount root is available via /proc.  Unfortunately, it does not help in
cases of more complex namespacing, like net namespaces.  For that, the
helper thread will need to be migrated to the core-dump namespaces.

I have a separate patch series which implements migrating the
____call_usermodehelper thread to the coredump namespace, but it adds a
fair amount of complexity which might be better handled by someone who
understands that code.  I'm happy to mail it out as well though (it
works, but I don't assign a namespaced pid which may open up issues on
its own).

Any and all comments, feedback will be appreciated!

Signed-off-by: Will Drewry <wad-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
 fs/exec.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 828dd24..0b8a874 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1467,6 +1467,13 @@ static int format_corename(char *corename, long signr)
 	char *const out_end = corename + CORENAME_MAX_SIZE;
 	int rc;
 	int pid_in_pattern = 0;
+	pid_t pid = task_tgid_vnr(current);
+
+	/* The pipe helper runs in the init namespace and should
+	 * receive the matching pid until that changes.
+	 */
+	if (ispipe)
+		pid = task_tgid_nr(current);
 
 	/* Repeat as long as we have more pattern to process and more output
 	   space */
@@ -1489,7 +1496,7 @@ static int format_corename(char *corename, long signr)
 			case 'p':
 				pid_in_pattern = 1;
 				rc = snprintf(out_ptr, out_end - out_ptr,
-					      "%d", task_tgid_vnr(current));
+					      "%d", pid);
 				if (rc > out_end - out_ptr)
 					goto out;
 				out_ptr += rc;
@@ -1568,7 +1575,7 @@ static int format_corename(char *corename, long signr)
 	 * the filename. Do not do this for piped commands. */
 	if (!ispipe && !pid_in_pattern && core_uses_pid) {
 		rc = snprintf(out_ptr, out_end - out_ptr,
-			      ".%d", task_tgid_vnr(current));
+			      ".%d", pid);
 		if (rc > out_end - out_ptr)
 			goto out;
 		out_ptr += rc;
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

end of thread, other threads:[~2010-09-20 20:28 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-16 18:59 [PATCH][RFC] fs/exec.c: provide the correct process pid to the pipe helper Will Drewry
     [not found] ` <1284663599-3549-1-git-send-email-wad-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2010-09-16 19:35   ` Oleg Nesterov
2010-09-17 13:26   ` Andi Kleen
2010-09-16 19:35 ` Oleg Nesterov
     [not found]   ` <20100916193543.GA11016-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-09-16 20:12     ` Eric W. Biederman
2010-09-16 20:12   ` Eric W. Biederman
2010-09-16 21:02     ` Will Drewry
     [not found]     ` <m1zkvh4fdc.fsf-+imSwln9KH6u2/kzUuoCbdi2O/JbrIOy@public.gmane.org>
2010-09-16 21:02       ` Will Drewry
2010-09-17 19:08       ` Roland McGrath
2010-09-17 19:08     ` Roland McGrath
2010-09-17 13:26 ` Andi Kleen
2010-09-17 14:52   ` Will Drewry
2010-09-17 14:52     ` Will Drewry
     [not found]   ` <20100917152639.0e88341a-3rXA9MLqAseW/qJFnhkgxti2O/JbrIOy@public.gmane.org>
2010-09-17 14:52     ` Will Drewry
2010-09-17 15:16     ` [PATCH 1/2] nsproxy: add copy_namespaces_unattached Will Drewry
2010-09-17 15:16     ` [PATCH 2/2] exec: move core_pattern pipe helper into the crashing namespace Will Drewry
2010-09-17 15:16   ` [PATCH 1/2] nsproxy: add copy_namespaces_unattached Will Drewry
2010-09-17 15:16   ` [PATCH 2/2] exec: move core_pattern pipe helper into the crashing namespace Will Drewry
     [not found]     ` <1284736618-27153-2-git-send-email-wad-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2010-09-17 18:15       ` Neil Horman
2010-09-18  1:29       ` Oleg Nesterov
2010-09-18  1:29         ` Oleg Nesterov
     [not found]         ` <20100918012939.GA25046-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-09-18  2:34           ` Will Drewry
2010-09-18  2:34             ` Will Drewry
2010-09-18  3:14             ` Will Drewry
2010-09-18  3:14             ` Will Drewry
2010-09-20 18:50             ` Oleg Nesterov
2010-09-20 18:50             ` Oleg Nesterov
     [not found]               ` <20100920185001.GA955-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-09-20 20:28                 ` Will Drewry
2010-09-20 20:28               ` Will Drewry
2010-09-20 20:28                 ` Will Drewry
2010-09-18  3:13           ` [PATCH][RFC] v2 " Will Drewry
2010-09-18  3:13         ` Will Drewry
2010-09-20 18:34           ` Eric W. Biederman
2010-09-20 19:12             ` Andi Kleen
2010-09-20 20:26               ` Will Drewry
2010-09-20 20:26                 ` Will Drewry
     [not found]               ` <20100920191214.GB7496-qrUzlfsMFqo/4alezvVtWx2eb7JE58TQ@public.gmane.org>
2010-09-20 20:26                 ` Will Drewry
     [not found]             ` <m1eico1cyv.fsf-+imSwln9KH6u2/kzUuoCbdi2O/JbrIOy@public.gmane.org>
2010-09-20 19:12               ` Andi Kleen
     [not found]           ` <1284779629-15273-1-git-send-email-wad-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2010-09-20 18:34             ` Eric W. Biederman
2010-09-17 18:15     ` [PATCH 2/2] " Neil Horman
     [not found]       ` <20100917181556.GA2499-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2010-09-18  2:33         ` Will Drewry
2010-09-18  2:33       ` Will Drewry
2010-09-16 18:59 [PATCH][RFC] fs/exec.c: provide the correct process pid to the pipe helper Will Drewry

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.