Re: [PATCH] Restrict stack space reservation to rlimit

From: KOSAKI Motohiro
Date: Mon Feb 08 2010 - 02:11:57 EST


> On Mon, Feb 8, 2010 at 2:05 PM, KOSAKI Motohiro
> <kosaki.motohiro@xxxxxxxxxxxxxx> wrote:
> >> --- linux-2.6-ozlabs.orig/fs/exec.c
> >> +++ linux-2.6-ozlabs/fs/exec.c
> >> @@ -627,10 +627,13 @@ int setup_arg_pages(struct linux_binprm
> >> Â Â Â Â Â Â Â Â Â Â Â goto out_unlock;
> >> Â Â Â }
> >>
> >> + Â Â stack_base = min(EXTRA_STACK_VM_PAGES * PAGE_SIZE,
> >> + Â Â Â Â Â Â Â Â Â Â Âcurrent->signal->rlim[RLIMIT_STACK].rlim_cur -
> >> + Â Â Â Â Â Â Â Â Â Â Â ÂPAGE_SIZE);
> >
> > This line is a bit unclear why "- PAGE_SIZE" is necessary.
> > personally, I like following likes explicit comments.
> >
> > Â Â Â Âstack_expand = EXTRA_STACK_VM_PAGES * PAGE_SIZE;
> > Â Â Â Âstack_lim = ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur);
> >
> > Â Â Â Â/* Initial stack must not cause stack overflow. */
> > Â Â Â Âif (stack_expand + PAGE_SIZE > stack_lim)
> > Â Â Â Â Â Â Â Âstack_expand = stack_lim - PAGE_SIZE;
> >
> > note: accessing rlim_cur require ACCESS_ONCE.
> >
> >
> > Thought?
>
> It's better to use the helper function: rlimit().

AFAIK, stable tree doesn't have rlimit(). but yes, making two patch
(for mainline and for stable) is good opinion.



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/