All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH/user_cr] pass a valid stack address to clone_with_pids
@ 2009-09-01 23:14 Nathan Lynch
       [not found] ` <1251846857.23305.5.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Lynch @ 2009-09-01 23:14 UTC (permalink / raw)
  To: Oren Laadan; +Cc: Linux Containers

Off-by-one error: the stack address passed to clone/clone_with_pids
must be within the region allocated.  (Also, arithmetic on void * is a
gcc extension; change the relevant variables to char *).

Signed-off-by: Nathan Lynch <ntl-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org>
---
 mktree.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/mktree.c b/mktree.c
index 63be82d..2d8d796 100644
--- a/mktree.c
+++ b/mktree.c
@@ -1367,18 +1367,19 @@ int ckpt_fork_stub(void *data)
 static pid_t ckpt_fork_child(struct ckpt_ctx *ctx, struct task *child)
 {
 	struct target_pid_set pid_set;
-	void *stack = NULL;
+	char *stack_region;
+	char *stack_start;
 	unsigned long flags = SIGCHLD;
 	pid_t pid = 0;
 
 	ckpt_dbg("forking child vpid %d flags %#x\n", child->pid, child->flags);
 
-	stack = malloc(PTHREAD_STACK_MIN);
-	if (!stack) {
+	stack_region = malloc(PTHREAD_STACK_MIN);
+	if (!stack_region) {
 		perror("stack malloc");
 		return -1;
 	}
-	stack += PTHREAD_STACK_MIN;
+	stack_start = stack_region + PTHREAD_STACK_MIN - 1;
 
 	pid_set.target_pids = &pid;
 	pid_set.num_pids = 1;
@@ -1406,15 +1407,15 @@ static pid_t ckpt_fork_child(struct ckpt_ctx *ctx, struct task *child)
 	else
 		child->real_parent = _getpid();
 
-	pid = clone_with_pids(ckpt_fork_stub, stack, flags, &pid_set, child);
+	pid = clone_with_pids(ckpt_fork_stub, stack_start, flags, &pid_set, child);
 	if (pid < 0) {
 		perror("clone");
-		free(stack - PTHREAD_STACK_MIN);
+		free(stack_region);
 		return -1;
 	}
 
 	if (!(child->flags & TASK_THREAD))
-		free(stack - PTHREAD_STACK_MIN);
+		free(stack_region);
 
 	ckpt_dbg("forked child vpid %d (asked %d)\n", pid, child->pid);
 	return pid;
-- 
1.6.0.6

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

* Re: [PATCH/user_cr] pass a valid stack address to clone_with_pids
       [not found] ` <1251846857.23305.5.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
@ 2009-09-03 20:44   ` Oren Laadan
  0 siblings, 0 replies; 2+ messages in thread
From: Oren Laadan @ 2009-09-03 20:44 UTC (permalink / raw)
  To: Nathan Lynch; +Cc: Linux Containers


Pulled, thanks.

Nathan Lynch wrote:
> Off-by-one error: the stack address passed to clone/clone_with_pids
> must be within the region allocated.  (Also, arithmetic on void * is a
> gcc extension; change the relevant variables to char *).
> 
> Signed-off-by: Nathan Lynch <ntl-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org>
> ---
>  mktree.c |   15 ++++++++-------
>  1 files changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/mktree.c b/mktree.c
> index 63be82d..2d8d796 100644
> --- a/mktree.c
> +++ b/mktree.c
> @@ -1367,18 +1367,19 @@ int ckpt_fork_stub(void *data)
>  static pid_t ckpt_fork_child(struct ckpt_ctx *ctx, struct task *child)
>  {
>  	struct target_pid_set pid_set;
> -	void *stack = NULL;
> +	char *stack_region;
> +	char *stack_start;
>  	unsigned long flags = SIGCHLD;
>  	pid_t pid = 0;
>  
>  	ckpt_dbg("forking child vpid %d flags %#x\n", child->pid, child->flags);
>  
> -	stack = malloc(PTHREAD_STACK_MIN);
> -	if (!stack) {
> +	stack_region = malloc(PTHREAD_STACK_MIN);
> +	if (!stack_region) {
>  		perror("stack malloc");
>  		return -1;
>  	}
> -	stack += PTHREAD_STACK_MIN;
> +	stack_start = stack_region + PTHREAD_STACK_MIN - 1;
>  
>  	pid_set.target_pids = &pid;
>  	pid_set.num_pids = 1;
> @@ -1406,15 +1407,15 @@ static pid_t ckpt_fork_child(struct ckpt_ctx *ctx, struct task *child)
>  	else
>  		child->real_parent = _getpid();
>  
> -	pid = clone_with_pids(ckpt_fork_stub, stack, flags, &pid_set, child);
> +	pid = clone_with_pids(ckpt_fork_stub, stack_start, flags, &pid_set, child);
>  	if (pid < 0) {
>  		perror("clone");
> -		free(stack - PTHREAD_STACK_MIN);
> +		free(stack_region);
>  		return -1;
>  	}
>  
>  	if (!(child->flags & TASK_THREAD))
> -		free(stack - PTHREAD_STACK_MIN);
> +		free(stack_region);
>  
>  	ckpt_dbg("forked child vpid %d (asked %d)\n", pid, child->pid);
>  	return pid;

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

end of thread, other threads:[~2009-09-03 20:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-01 23:14 [PATCH/user_cr] pass a valid stack address to clone_with_pids Nathan Lynch
     [not found] ` <1251846857.23305.5.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2009-09-03 20:44   ` Oren Laadan

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.