From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?Q?Am=C3=A9rico_Wang?= Subject: Re: [PATCH] Restrict stack space reservation to rlimit Date: Mon, 8 Feb 2010 15:07:47 +0800 Message-ID: <2375c9f91002072307h4af1ba6dw1b7a598582991dc4@mail.gmail.com> References: <20100208141716.FB55.A69D9226@jp.fujitsu.com> <9729.1265607469@neuling.org> <20100208145240.FB58.A69D9226@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Michael Neuling , Anton Blanchard , Andrew Morton , Linus Torvalds , Alexander Viro , Oleg Nesterov , James Morris , Ingo Molnar , linux-fsdevel@vger.kernel.org, stable@kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@ozlabs.org, Serge Hallyn , Paul Mackerras , benh@kernel.crashing.org, miltonm@bga.com, aeb@cwi.nl To: KOSAKI Motohiro Return-path: Received: from qw-out-2122.google.com ([74.125.92.26]:11957 "EHLO qw-out-2122.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751909Ab0BHHHs convert rfc822-to-8bit (ORCPT ); Mon, 8 Feb 2010 02:07:48 -0500 In-Reply-To: <20100208145240.FB58.A69D9226@jp.fujitsu.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Mon, Feb 8, 2010 at 2:05 PM, KOSAKI Motohiro 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 >> =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; >> =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 - >> + =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 * PA= GE_SIZE; > =C2=A0 =C2=A0 =C2=A0 =C2=A0stack_lim =3D ACCESS_ONCE(rlim[RLIMIT_STAC= K].rlim_cur); > > =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Initial stack must not cause stack over= flow. */ > =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= stack_lim - PAGE_SIZE; > > note: accessing rlim_cur require ACCESS_ONCE. > > > Thought? It's better to use the helper function: rlimit(). -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel= " in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html