Linux Container Development
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: Oren Laadan <orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	Oren Laadan <orenl-3n9FKfXVdfcggxPgtCmjjw@public.gmane.org>
Subject: Re: [PATCH 5/6] c/r: correctly restore pgid
Date: Mon, 7 Sep 2009 22:04:45 -0500	[thread overview]
Message-ID: <20090908030445.GB16460@us.ibm.com> (raw)
In-Reply-To: <1252074054-22241-6-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>

Quoting Oren Laadan (orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org):
> The main challenge with restoring the pgid of tasks is that the
> original "owner" (the process with that pid) might have exited
> already. I call these "ghost" pgids. 'mktree' does create these
> processes, but they then exit without participating in the restart.
> 
> To solve this, this patch introduces a RESTART_GHOST flag, used for
> "ghost" owners that are created only to pass their pgid to other
> tasks. ('mktree' now makes them call restart(2) instead of exiting).
> 
> When a "ghost" task calls restart(2), it will be placed on a wait
> queue until the restart completes and then exit. This guarantees that
> the pgid that it owns remains available for all (regular) restarting
> tasks for when they need it.
> 
> Regular tasks perform the restart as before, except that they also
> now restore their old pgrp, which is guaranteed to exist.
> 
> Changelog [v1]:
>   - Verify that pgid owner is a thread-group-leader.
>   - Handle the case of pgid/sid == 0 using root's parent pid-ns
> 
> Signed-off-by: Oren Laadan <orenl-3n9FKfXVdfcggxPgtCmjjw@public.gmane.org>
> ---
>  checkpoint/process.c             |  106 ++++++++++++++++++++++++-
>  checkpoint/restart.c             |  158 ++++++++++++++++++++++++++------------
>  checkpoint/sys.c                 |    3 +-
>  include/linux/checkpoint.h       |   11 ++-
>  include/linux/checkpoint_hdr.h   |    3 +
>  include/linux/checkpoint_types.h |    6 +-
>  6 files changed, 230 insertions(+), 57 deletions(-)
> 
> diff --git a/checkpoint/process.c b/checkpoint/process.c
> index 40b2580..5d6bdb9 100644
> --- a/checkpoint/process.c
> +++ b/checkpoint/process.c
> @@ -23,6 +23,57 @@
>  #include <linux/syscalls.h>
> 
> 
> +pid_t ckpt_pid_nr(struct ckpt_ctx *ctx, struct pid *pid)
> +{
> +	return pid ? pid_nr_ns(pid, ctx->root_nsproxy->pid_ns) : CKPT_PID_NULL;
> +}
> +
> +/* must be called with tasklist_lock or rcu_read_lock() held */
> +struct pid *_ckpt_find_pgrp(struct ckpt_ctx *ctx, pid_t pgid)
> +{
> +	struct task_struct *p;
> +	struct pid *pgrp;
> +
> +	if (pgid == 0) {
> +		/*
> +		 * At checkpoint the pgid owner lived in an ancestor
> +		 * pid-ns. The best we can do (sanely and safely) is
> +		 * to examine the parent of this restart's root: if in
> +		 * a distinct pid-ns, use its pgrp; otherwise fail.
> +		 */
> +		p = ctx->root_task->real_parent;
> +		if (p->nsproxy->pid_ns == current->nsproxy->pid_ns)
> +			return NULL;
> +		pgrp = task_pgrp(p);
> +	} else {
> +		/*
> +		 * Find the owner process of this pgid (it must exist
> +		 * if pgrp exists). It must be a thread group leader.
> +		 */
> +		pgrp = find_vpid(pgid);
> +		p = pid_task(pgrp, PIDTYPE_PID);
> +		if (!p || !thread_group_leader(p))
> +			return NULL;
> +		/*
> +		 * The pgrp must "belong" to our restart tree (compare
> +		 * p->checkpoint_ctx to ours). This prevents malicious
> +		 * input from (guessing and) using unrelated pgrps. If
> +		 * the owner is dead, then it doesn't have a context,
> +		 * so instead compare against its (real) parent's.
> +		 */
> +		if (p->exit_state == EXIT_ZOMBIE)
> +			p = p->real_parent;
> +		if (p->checkpoint_ctx != ctx)
> +			return NULL;
> +	}
> +
> +	if (task_session(current) != task_session(p))
> +		return NULL;
> +
> +	return pgrp;
> +}
> +
> +
>  #ifdef CONFIG_FUTEX
>  static void save_task_robust_futex_list(struct ckpt_hdr_task *h,
>  					struct task_struct *t)
> @@ -94,8 +145,8 @@ static int checkpoint_task_struct(struct ckpt_ctx *ctx, struct task_struct *t)
>  		h->exit_signal = t->exit_signal;
>  		h->pdeath_signal = t->pdeath_signal;
> 
> -		h->set_child_tid = t->set_child_tid;
> -		h->clear_child_tid = t->clear_child_tid;
> +		h->set_child_tid = (unsigned long) t->set_child_tid;

note that set_child_tid is an int (signed), not a long.  Same on
x86, but not on other arches.  Shouldn't lose info so could be worse.

On the whole,

Acked-by: Serge Hallyn <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

-serge

  parent reply	other threads:[~2009-09-08  3:04 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-04 14:20 Checkpoint/restart of ptys, pgids, and controlling tty Oren Laadan
     [not found] ` <1252074054-22241-1-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-09-04 14:20   ` [PATCH 1/6] c/r: [objhash] add ckpt_obj_reserve() Oren Laadan
2009-09-04 14:20   ` [PATCH 2/6] c/r: [pty 1/2] allow allocation of desired pty slave Oren Laadan
     [not found]     ` <1252074054-22241-3-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-09-04 15:26       ` Serge E. Hallyn
     [not found]         ` <20090904152644.GA15253-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-09-04 16:08           ` Oren Laadan
2009-09-08  8:09           ` Louis Rilling
     [not found]             ` <20090908080944.GP12824-Hu8+6S1rdjywhHL9vcZdMVaTQe2KTcn/@public.gmane.org>
2009-09-08 13:19               ` Oren Laadan
     [not found]                 ` <4AA659C7.5020700-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-09-08 14:04                   ` Louis Rilling
2009-09-04 14:20   ` [PATCH 3/6] c/r: [pty 2/2] support for pseudo terminals Oren Laadan
     [not found]     ` <1252074054-22241-4-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-09-04 16:21       ` Serge E. Hallyn
2009-09-08  8:50       ` Louis Rilling
     [not found]         ` <20090908085013.GQ12824-Hu8+6S1rdjywhHL9vcZdMVaTQe2KTcn/@public.gmane.org>
2009-09-08 13:19           ` Oren Laadan
2009-09-04 14:20   ` [PATCH 4/6] c/r: tighten logic to protect against bogus pids in input Oren Laadan
     [not found]     ` <1252074054-22241-5-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-09-08  1:09       ` Serge E. Hallyn
2009-09-04 14:20   ` [PATCH 1/3] mktree: add support to ghost tasks (TASK_GHOST) Oren Laadan
2009-09-04 14:20   ` [PATCH 2/3] test/pgrp.c: add test case for process-groups Oren Laadan
2009-09-04 14:20   ` [PATCH 3/3] restart: correctly handle pgid/ppid/sid = 0 Oren Laadan
     [not found] ` <1252074054-22241-6-git-send-email-orenl@librato.com>
     [not found]   ` <1252074054-22241-6-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-09-08  3:04     ` Serge E. Hallyn [this message]
     [not found]       ` <20090908030445.GB16460-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-09-08 13:33         ` [PATCH 5/6] c/r: correctly restore pgid Oren Laadan
     [not found]           ` <4AA65D10.6000702-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-09-08 14:00             ` Serge E. Hallyn
     [not found]               ` <20090908140056.GA873-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-09-08 16:40                 ` Oren Laadan
     [not found] ` <1252074054-22241-7-git-send-email-orenl@librato.com>
     [not found]   ` <1252074054-22241-7-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-09-08  3:21     ` [PATCH 6/6] c/r: support for controlling terminal and job control Serge E. Hallyn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090908030445.GB16460@us.ibm.com \
    --to=serue-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=orenl-3n9FKfXVdfcggxPgtCmjjw@public.gmane.org \
    --cc=orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox