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
Subject: Re: [PATCH 4/6] c/r: tighten logic to protect against bogus pids in input
Date: Mon, 7 Sep 2009 20:09:22 -0500	[thread overview]
Message-ID: <20090908010922.GA16460@us.ibm.com> (raw)
In-Reply-To: <1252074054-22241-5-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>

Quoting Oren Laadan (orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org):
> During restart, each process that completes its restore will wake up
> the next process in line, using the pid provided in the image file.
> A malicious user could provide bogus pids and cause arbitrary tasks to
> be woken up.
> 
> This patch tightens the checks and requires that to wake-up a task by
> pid during restart, the target task must belong to (have) the same
> restart context (task->checkpoint_ctx) as the current process.
> 
> Also, update in-code comments about restart and zombie logic.
> 
> Signed-off-by: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>

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

> ---
>  checkpoint/restart.c |   35 ++++++++++++++++++++---------------
>  1 files changed, 20 insertions(+), 15 deletions(-)
> 
> diff --git a/checkpoint/restart.c b/checkpoint/restart.c
> index 2282ffc..840b5cb 100644
> --- a/checkpoint/restart.c
> +++ b/checkpoint/restart.c
> @@ -462,12 +462,12 @@ static int restore_read_tree(struct ckpt_ctx *ctx)
>  		return PTR_ERR(h);
> 
>  	ret = -EINVAL;
> -	if (h->nr_tasks < 0)
> +	if (h->nr_tasks <= 0)
>  		goto out;
> 
>  	ctx->nr_pids = h->nr_tasks;
>  	size = sizeof(*ctx->pids_arr) * ctx->nr_pids;
> -	if (size < 0)		/* overflow ? */
> +	if (size <= 0)		/* overflow ? */
>  		goto out;
> 
>  	ctx->pids_arr = kmalloc(size, GFP_KERNEL);
> @@ -520,8 +520,11 @@ int ckpt_activate_next(struct ckpt_ctx *ctx)
> 
>  	rcu_read_lock();
>  	task = find_task_by_pid_ns(pid, ctx->root_nsproxy->pid_ns);
> -	if (task)
> +	/* target task must have same restart context */
> +	if (task && task->checkpoint_ctx == ctx)
>  		wake_up_process(task);
> +	else
> +		task = NULL;
>  	rcu_read_unlock();
> 
>  	if (!task) {
> @@ -568,9 +571,8 @@ static int do_restore_task(void)
>  	int ret;
> 
>  	/*
> -	 * Wait for coordinator to make become visible, then grab a
> -	 * reference to its restart context. If we're the last task to
> -	 * do it, notify the coordinator.
> +	 * Wait for coordinator to become visible, then grab a
> +	 * reference to its restart context.
>  	 */
>  	ret = wait_event_interruptible(waitq, current->checkpoint_ctx);
>  	if (ret < 0)
> @@ -610,8 +612,9 @@ static int do_restore_task(void)
>  		goto out;
> 
>  	/*
> -	 * zombie: we're done here; Save @ctx on task_struct, to be
> -	 * used to ckpt_activate_next(), and released, from do_exit().
> +	 * zombie: we're done here; do_exit() will notice the @ctx on
> +	 * our current->checkpoint_ctx (and our PF_RESTARTING) - it
> +	 * will call ckpt_activate_next() and release the @ctx.
>  	 */
>  	if (ret)
>  		do_exit(current->exit_code);
> @@ -638,11 +641,11 @@ static int do_restore_task(void)
>  }
> 
>  /**
> - * prepare_descendants - set ->restart_tsk of all descendants
> + * prepare_descendants - set ->checkpoint_ctx of all descendants
>   * @ctx: checkpoint context
>   * @root: root process for restart
>   *
> - * Called by the coodinator to set the ->restart_tsk pointer of the
> + * Called by the coodinator to set the ->checkpoint_ctx pointer of the
>   * root task and all its descendants.
>   */
>  static int prepare_descendants(struct ckpt_ctx *ctx, struct task_struct *root)
> @@ -662,7 +665,7 @@ static int prepare_descendants(struct ckpt_ctx *ctx, struct task_struct *root)
>  			break;
>  		}
>  		/*
> -		 * Set task->restart_tsk of all non-zombie descendants.
> +		 * Set task->checkpoint_ctx of all non-zombie descendants.
>  		 * If a descendant already has a ->checkpoint_ctx, it
>  		 * must be a coordinator (for a different restart ?) so
>  		 * we fail.
> @@ -727,6 +730,7 @@ static int wait_all_tasks_finish(struct ckpt_ctx *ctx)
> 
>  	init_completion(&ctx->complete);
> 
> +	BUG_ON(ctx->active_pid != -1);
>  	ret = ckpt_activate_next(ctx);
>  	if (ret < 0)
>  		return ret;
> @@ -839,7 +843,7 @@ static int do_restore_coord(struct ckpt_ctx *ctx, pid_t pid)
>  		if (ret < 0)
>  			goto out;
>  	} else {
> -		/* prepare descendants' t->restart_tsk point to coord */
> +		/* prepare descendants' t->checkpoint_ctx point to coord */
>  		ret = prepare_descendants(ctx, ctx->root_task);
>  		if (ret < 0)
>  			goto out;
> @@ -970,11 +974,12 @@ void exit_checkpoint(struct task_struct *tsk)
>  {
>  	struct ckpt_ctx *ctx;
> 
> -	ctx = tsk->checkpoint_ctx;
> -	tsk->checkpoint_ctx = NULL;
> +	/* no one else will touch this, because @tsk is dead already */
> +	ctx = xchg(&tsk->checkpoint_ctx, NULL);
> 
> -	/* restarting zombies will acrivate next task in restart */
> +	/* restarting zombies will activate next task in restart */
>  	if (tsk->flags & PF_RESTARTING) {
> +		BUG_ON(ctx->active_pid == -1);
>  		if (ckpt_activate_next(ctx) < 0)
>  			pr_warning("c/r: [%d] failed zombie exit\n", tsk->pid);
>  	}
> -- 
> 1.6.0.4

  parent reply	other threads:[~2009-09-08  1:09 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 [this message]
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     ` [PATCH 5/6] c/r: correctly restore pgid Serge E. Hallyn
     [not found]       ` <20090908030445.GB16460-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-09-08 13:33         ` 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=20090908010922.GA16460@us.ibm.com \
    --to=serue-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@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