All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Ollie Wild <aaw@google.com>
Cc: "Luck, Tony" <tony.luck@intel.com>,
	linux-kernel@vger.kernel.org,
	parisc-linux@lists.parisc-linux.org, linux-mm@kvack.org,
	linux-arch@vger.kernel.org, Andrew Morton <akpm@osdl.org>,
	Ingo Molnar <mingo@elte.hu>, Andi Kleen <ak@suse.de>
Subject: Re: [patch 0/3] no MAX_ARG_PAGES -v2
Date: Fri, 15 Jun 2007 11:24:38 +0200	[thread overview]
Message-ID: <1181899478.7348.349.camel@twins> (raw)
In-Reply-To: <65dd6fd50706141358i39bba32aq139766c8a1a3de2b@mail.gmail.com>

On Thu, 2007-06-14 at 13:58 -0700, Ollie Wild wrote:

>   A good heuristic, though, might be to limit
> argument size to a percentage (say 25%) of maximum stack size and
> validate this inside copy_strings().

This seems to do:


Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 fs/exec.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Index: linux-2.6-2/fs/exec.c
===================================================================
--- linux-2.6-2.orig/fs/exec.c	2007-06-15 11:05:09.000000000 +0200
+++ linux-2.6-2/fs/exec.c	2007-06-15 11:05:18.000000000 +0200
@@ -199,6 +199,23 @@ static struct page *get_arg_page(struct 
 	if (ret <= 0)
 		return NULL;
 
+	if (write) {
+		struct rlimit *rlim = current->signal->rlim;
+		unsigned long size = bprm->vma->vm_end - bprm->vma->vm_start;
+
+		/*
+		 * Limit to 1/4-th the stack size for the argv+env strings.
+		 * This ensures that:
+		 *  - the remaining binfmt code will not run out of stack space,
+		 *  - the program will have a reasonable amount of stack left
+		 *    to work from.
+		 */
+		if (size > rlim[RLIMIT_STACK].rlim_cur / 4) {
+			put_page(page);
+			return NULL;
+		}
+	}
+
 	return page;
 }
 



WARNING: multiple messages have this Message-ID (diff)
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Ollie Wild <aaw@google.com>
Cc: "Luck, Tony" <tony.luck@intel.com>,
	linux-kernel@vger.kernel.org,
	parisc-linux@lists.parisc-linux.org, linux-mm@kvack.org,
	linux-arch@vger.kernel.org, Andrew Morton <akpm@osdl.org>,
	Ingo Molnar <mingo@elte.hu>, Andi Kleen <ak@suse.de>
Subject: Re: [patch 0/3] no MAX_ARG_PAGES -v2
Date: Fri, 15 Jun 2007 11:24:38 +0200	[thread overview]
Message-ID: <1181899478.7348.349.camel@twins> (raw)
In-Reply-To: <65dd6fd50706141358i39bba32aq139766c8a1a3de2b@mail.gmail.com>

On Thu, 2007-06-14 at 13:58 -0700, Ollie Wild wrote:

>   A good heuristic, though, might be to limit
> argument size to a percentage (say 25%) of maximum stack size and
> validate this inside copy_strings().

This seems to do:


Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 fs/exec.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Index: linux-2.6-2/fs/exec.c
===================================================================
--- linux-2.6-2.orig/fs/exec.c	2007-06-15 11:05:09.000000000 +0200
+++ linux-2.6-2/fs/exec.c	2007-06-15 11:05:18.000000000 +0200
@@ -199,6 +199,23 @@ static struct page *get_arg_page(struct 
 	if (ret <= 0)
 		return NULL;
 
+	if (write) {
+		struct rlimit *rlim = current->signal->rlim;
+		unsigned long size = bprm->vma->vm_end - bprm->vma->vm_start;
+
+		/*
+		 * Limit to 1/4-th the stack size for the argv+env strings.
+		 * This ensures that:
+		 *  - the remaining binfmt code will not run out of stack space,
+		 *  - the program will have a reasonable amount of stack left
+		 *    to work from.
+		 */
+		if (size > rlim[RLIMIT_STACK].rlim_cur / 4) {
+			put_page(page);
+			return NULL;
+		}
+	}
+
 	return page;
 }
 


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2007-06-15  9:24 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-13 10:03 [patch 0/3] no MAX_ARG_PAGES -v2 Peter Zijlstra
2007-06-13 10:03 ` Peter Zijlstra
2007-06-13 10:03 ` [patch 1/3] arch: personality independent stack top Peter Zijlstra
2007-06-13 10:03   ` Peter Zijlstra
2007-06-13 10:03 ` [patch 2/3] audit: rework execve audit Peter Zijlstra
2007-06-13 10:03   ` Peter Zijlstra
2007-06-13 10:03   ` Peter Zijlstra
2007-06-26 22:55   ` Andrew Morton
2007-06-26 22:55     ` Andrew Morton
2007-06-26 22:55     ` Andrew Morton
2007-07-03 15:00     ` Peter Zijlstra
2007-07-03 15:00       ` Peter Zijlstra
2007-07-03 15:00       ` Peter Zijlstra
2007-07-03 15:00     ` [parisc-linux] " Peter Zijlstra
2007-06-13 10:03 ` [patch 3/3] mm: variable length argument support Peter Zijlstra
2007-06-13 10:03   ` Peter Zijlstra, Ollie Wild
2007-08-07 19:03   ` Olaf Hering
2007-08-07 19:03     ` Olaf Hering
2007-08-07 19:20     ` Andrew Morton
2007-08-07 19:20       ` Andrew Morton
2007-08-07 19:26       ` Peter Zijlstra
2007-08-07 19:26         ` Peter Zijlstra
2007-08-07 20:10       ` Olaf Hering
2007-08-07 20:10         ` Olaf Hering
2007-08-22  8:48   ` Dan Aloni
2007-08-22  8:48     ` Dan Aloni
2007-08-22  8:54     ` Peter Zijlstra
2007-08-22  9:05       ` Andrew Morton
2007-08-22  9:05         ` Andrew Morton
2007-08-22  9:02     ` Fengguang Wu
2007-08-22  9:02       ` Fengguang Wu
2007-08-22  9:02         ` Fengguang Wu
2007-08-22  9:02       ` Fengguang Wu
2007-06-13 23:36 ` [patch 0/3] no MAX_ARG_PAGES -v2 Luck, Tony
2007-06-13 23:36   ` Luck, Tony
2007-06-13 23:36   ` Luck, Tony
2007-06-14  6:23   ` Ollie Wild
2007-06-14  6:23     ` Ollie Wild
2007-06-14  8:38     ` Peter Zijlstra
2007-06-14  8:38       ` Peter Zijlstra
2007-06-14 18:22       ` Luck, Tony
2007-06-14 18:22         ` Luck, Tony
2007-06-14 18:22         ` Luck, Tony
2007-06-14 18:32         ` Peter Zijlstra
2007-06-14 18:32           ` Peter Zijlstra
2007-06-14 20:58       ` Ollie Wild
2007-06-14 20:58         ` Ollie Wild
2007-06-14 21:18         ` Peter Zijlstra
2007-06-14 21:18           ` Peter Zijlstra
2007-06-15  9:24         ` Peter Zijlstra [this message]
2007-06-15  9:24           ` Peter Zijlstra
2007-06-15 18:07           ` Ollie Wild
2007-06-15 18:07             ` Ollie Wild
2007-06-15 18:49             ` Luck, Tony
2007-06-15 18:49               ` Luck, Tony
2007-06-15 18:49               ` Luck, Tony
2007-06-17 18:32 ` Pavel Machek
2007-06-17 18:32   ` Pavel Machek
2007-06-17 19:07   ` Ingo Molnar
2007-06-17 19:07     ` Ingo Molnar

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=1181899478.7348.349.camel@twins \
    --to=a.p.zijlstra@chello.nl \
    --cc=aaw@google.com \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@elte.hu \
    --cc=parisc-linux@lists.parisc-linux.org \
    --cc=tony.luck@intel.com \
    /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 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.