Re: [PATCH] Restrict stack space reservation to rlimit
From: Américo Wang <hidden>
Date: 2010-02-08 07:07:48
Also in:
linux-fsdevel, lkml
On Mon, Feb 8, 2010 at 2:05 PM, KOSAKI Motohiro [off-list ref] wrote:
quoted
--- 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=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 goto out_unlock;
quoted
=C2=A0 =C2=A0 =C2=A0 } + =C2=A0 =C2=A0 stack_base =3D min(EXTRA_STACK_VM_PAGES * PAGE_SIZE, + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0current->signal->rlim[RLIMIT_STACK].rlim_cur -
quoted
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0PAGE_SIZE);
This line is a bit unclear why "- PAGE_SIZE" is necessary. personally, I like following likes explicit comments. =C2=A0 =C2=A0 =C2=A0 =C2=A0stack_expand =3D EXTRA_STACK_VM_PAGES * PAGE_S=
IZE;
=C2=A0 =C2=A0 =C2=A0 =C2=A0stack_lim =3D ACCESS_ONCE(rlim[RLIMIT_STACK].r=
lim_cur);
=C2=A0 =C2=A0 =C2=A0 =C2=A0/* Initial stack must not cause stack overflow=
. */
=C2=A0 =C2=A0 =C2=A0 =C2=A0if (stack_expand + PAGE_SIZE > stack_lim) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0stack_expand =3D s=
tack_lim - PAGE_SIZE;
note: accessing rlim_cur require ACCESS_ONCE. Thought?
It's better to use the helper function: rlimit().