minijail: When pid-namespacing, init should be session leader
When running a jailed process, the init process should take
the role of process group and session leader -- otherwise
calls to check these values for processes in the namespace
may get 0 (as the actual leader is a process outside the
namespace).
BUG=None
TEST=minijail0 -p /sbin/session_manager
Change-Id: I35dc7c5ba63db57e64ad6c05018403d4b535922d
Reviewed-on: https://chromium-review.googlesource.com/238849
Trybot-Ready: Chris Masone <cmasone@chromium.org>
Tested-by: Chris Masone <cmasone@chromium.org>
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
Commit-Queue: Chris Masone <cmasone@chromium.org>
diff --git a/libminijail.c b/libminijail.c
index 7a18831..53a554e 100644
--- a/libminijail.c
+++ b/libminijail.c
@@ -1216,6 +1216,8 @@
minijail_enter(j);
if (pid_namespace) {
+ if (setsid() < 0)
+ pdie("failed to make init the session leader");
/*
* pid namespace: this process will become init inside the new
* namespace, so fork off a child to actually run the program