public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: Justin Forbes <jmforbes@linuxtx.org>,
	Zwane Mwaikambo <zwane@arm.linux.org.uk>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Randy Dunlap <rdunlap@xenotime.net>,
	Dave Jones <davej@redhat.com>,
	Chuck Wolber <chuckw@quantumlinux.com>,
	Chris Wedgwood <reviews@ml.cw.f00f.org>,
	torvalds@osdl.org, akpm@osdl.org, alan@lxorguk.ukuu.org.uk,
	Ernie Petrides <petrides@redhat.com>,
	Chuck Ebbert <76306.1226@compuserve.com>,
	Greg Kroah-Hartman <gregkh@suse.de>
Subject: [patch 23/37] binfmt_elf: fix checks for bad address
Date: Wed, 6 Sep 2006 15:57:08 -0700	[thread overview]
Message-ID: <20060906225708.GX15922@kroah.com> (raw)
In-Reply-To: <20060906225444.GA15922@kroah.com>

[-- Attachment #1: binfmt_elf-fix-checks-for-bad-address.patch --]
[-- Type: text/plain, Size: 4473 bytes --]

-stable review patch.  If anyone has any objections, please let us know.

------------------
From: Ernie Petrides <petrides@redhat.com>

[PATCH] binfmt_elf: fix checks for bad address

Fix check for bad address; use macro instead of open-coding two checks.

Taken from RHEL4 kernel update.

  For background, the BAD_ADDR() macro should return TRUE if the address is
  TASK_SIZE, because that's the lowest address that is *not* valid for
  user-space mappings.  The macro was correct in binfmt_aout.c but was wrong
  for the "equal to" case in binfmt_elf.c.  There were two in-line validations
  of user-space addresses in binfmt_elf.c, which have been appropriately
  converted to use the corrected BAD_ADDR() macro in the patch you posted
  yesterday.  Note that the size checks against TASK_SIZE are okay as coded.

  The additional changes that I propose are below.  These are in the error
  paths for bad ELF entry addresses once load_elf_binary() has already
  committed to exec'ing the new image (following the tearing down of the
  task's original address space).

  The 1st hunk deals with the interp-side of the outer "if".  There were two
  problems here.  The printk() should be removed because this path can be
  triggered at will by a bogus interpreter image created and used by a
  malicious user.  Further, the error code should not be ENOEXEC, because that
  causes the loop in search_binary_handler() to continue trying other exec
  handlers (twice, in fact).  But it's too late for this to work correctly,
  because the user address space has already been torn down, and an exec()
  failure cannot be returned to the user code because the code no longer
  exists.  The only recovery is to force a SIGSEGV, but it's best to terminate
  the search loop immediately.  I somewhat arbitrarily chose EINVAL as a
  fallback error code, but any error returned by load_elf_interp() will
  override that (but this value will never be seen by user-space).

  The 2nd hunk deals with the non-interp-side of the outer "if".  There were
  two problems here as well.  The SIGSEGV needs to be forced, because a prior
  sigaction() syscall might have set the associated disposition to SIG_IGN.
  And the ENOEXEC should be changed to EINVAL as described above.

Signed-off-by: Chuck Ebbert <76306.1226@compuserve.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 fs/binfmt_elf.c |   15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

--- linux-2.6.17.11.orig/fs/binfmt_elf.c
+++ linux-2.6.17.11/fs/binfmt_elf.c
@@ -86,7 +86,7 @@ static struct linux_binfmt elf_format = 
 		.min_coredump	= ELF_EXEC_PAGESIZE
 };
 
-#define BAD_ADDR(x)	((unsigned long)(x) > TASK_SIZE)
+#define BAD_ADDR(x)	((unsigned long)(x) >= TASK_SIZE)
 
 static int set_brk(unsigned long start, unsigned long end)
 {
@@ -389,7 +389,7 @@ static unsigned long load_elf_interp(str
 	     * <= p_memsize so it is only necessary to check p_memsz.
 	     */
 	    k = load_addr + eppnt->p_vaddr;
-	    if (k > TASK_SIZE || eppnt->p_filesz > eppnt->p_memsz ||
+	    if (BAD_ADDR(k) || eppnt->p_filesz > eppnt->p_memsz ||
 		eppnt->p_memsz > TASK_SIZE || TASK_SIZE - eppnt->p_memsz < k) {
 	        error = -ENOMEM;
 		goto out_close;
@@ -876,7 +876,7 @@ static int load_elf_binary(struct linux_
 		 * allowed task size. Note that p_filesz must always be
 		 * <= p_memsz so it is only necessary to check p_memsz.
 		 */
-		if (k > TASK_SIZE || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
+		if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
 		    elf_ppnt->p_memsz > TASK_SIZE ||
 		    TASK_SIZE - elf_ppnt->p_memsz < k) {
 			/* set_brk can never work.  Avoid overflows.  */
@@ -930,10 +930,9 @@ static int load_elf_binary(struct linux_
 						    interpreter,
 						    &interp_load_addr);
 		if (BAD_ADDR(elf_entry)) {
-			printk(KERN_ERR "Unable to load interpreter %.128s\n",
-				elf_interpreter);
 			force_sig(SIGSEGV, current);
-			retval = -ENOEXEC; /* Nobody gets to see this, but.. */
+			retval = IS_ERR((void *)elf_entry) ?
+					(int)elf_entry : -EINVAL;
 			goto out_free_dentry;
 		}
 		reloc_func_desc = interp_load_addr;
@@ -944,8 +943,8 @@ static int load_elf_binary(struct linux_
 	} else {
 		elf_entry = loc->elf_ex.e_entry;
 		if (BAD_ADDR(elf_entry)) {
-			send_sig(SIGSEGV, current, 0);
-			retval = -ENOEXEC; /* Nobody gets to see this, but.. */
+			force_sig(SIGSEGV, current);
+			retval = -EINVAL;
 			goto out_free_dentry;
 		}
 	}

--

  parent reply	other threads:[~2006-09-06 23:02 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20060906224631.999046890@quad.kroah.org>
2006-09-06 22:54 ` [patch 00/37] -stable review Greg KH
2006-09-06 22:54   ` [patch 01/37] TEXTSEARCH: Fix Boyer Moore initialization bug Greg KH
2006-09-06 22:55   ` [patch 02/37] spectrum_cs: Fix firmware uploading errors Greg KH
2006-09-06 22:55   ` [patch 03/37] Fix output framentation of paged-skbs Greg KH
2006-09-06 22:55   ` [patch 04/37] fix compilation error on IA64 Greg KH
2006-09-07  8:45     ` Kirill Korotaev
2006-09-06 22:55   ` [patch 05/37] bridge-netfilter: dont overwrite memory outside of skb Greg KH
2006-09-06 22:55   ` [patch 06/37] Allow per-route window scale limiting Greg KH
2006-09-06 22:55   ` [patch 07/37] Have ext2 reject file handles with bad inode numbers early Greg KH
2006-09-06 22:55   ` [patch 08/37] dm snapshot: unify chunk_size Greg KH
2006-09-06 22:55   ` [patch 09/37] dm: fix idr minor allocation Greg KH
2006-09-06 22:55   ` [patch 10/37] dm: move idr_pre_get Greg KH
2006-09-06 22:55   ` [patch 11/37] dm: change minor_lock to spinlock Greg KH
2006-09-06 22:55   ` [patch 12/37] dm: add DMF_FREEING Greg KH
2006-09-06 22:56   ` [patch 13/37] dm: fix mapped device ref counting Greg KH
2006-09-06 22:56   ` [patch 14/37] dm: add module " Greg KH
2006-09-06 22:56   ` [patch 15/37] dm: fix block device initialisation Greg KH
2006-09-06 22:56   ` [patch 16/37] dm: mirror sector offset fix Greg KH
2006-09-06 22:56   ` [patch 17/37] TG3: Disable TSO by default Greg KH
2006-09-06 22:56   ` [patch 18/37] SPARC64: Fix X server crashes on sparc64 Greg KH
2006-09-06 22:56   ` [patch 19/37] SCTP: Fix sctp_primitive_ABORT() call in sctp_close() Greg KH
2006-09-06 22:56   ` [patch 20/37] IPV6 OOPSer triggerable by any user Greg KH
2006-09-06 22:56   ` [patch 21/37] fcntl(F_SETSIG) fix Greg KH
2006-09-06 22:57   ` [patch 22/37] bug in futex unqueue_me Greg KH
2006-09-06 22:57   ` Greg KH [this message]
2006-09-06 22:57   ` [patch 24/37] uhci-hcd: fix list access bug Greg KH
2006-09-06 22:57   ` [patch 25/37] Silent data corruption caused by XPC Greg KH
2006-09-06 22:57   ` [patch 26/37] PKTGEN: Make sure skb->{nh,h} are initialized in fill_packet_ipv6() too Greg KH
2006-09-06 22:57   ` [patch 27/37] PKTGEN: Fix oops when used with balance-tlb bonding Greg KH
2006-09-06 22:57   ` [patch 28/37] Missing PCI id update for VIA IDE Greg KH
2006-09-06 23:33     ` [-stable patch] pci_ids.h: add some VIA IDE identifiers Adrian Bunk
2006-09-06 22:57   ` [patch 29/37] dvb-core: Proper handling ULE SNDU length of 0 Greg KH
2006-09-07 12:57     ` Marcel Holtmann
2006-09-07 15:39       ` [stable] " Greg KH
2006-09-08 11:31         ` Marcel Holtmann
2006-09-08 12:58     ` Michael Krufky
2006-09-08 13:11       ` Ang Way Chuang
2006-09-08 17:29       ` Greg KH
2006-09-15 16:11         ` Michael Krufky
2006-09-15 16:15           ` Marcel Siegert
2006-09-15 16:36           ` Marcel Holtmann
2006-09-15 18:07             ` Michael Krufky
2006-09-15 18:18               ` Marcel Holtmann
2006-09-20  9:38                 ` Ang Way Chuang
2006-09-06 22:57   ` [patch 30/37] Remove redundant up() in stop_machine() Greg KH
2006-09-06 22:57   ` [patch 31/37] dm: Fix deadlock under high i/o load in raid1 setup Greg KH
2006-09-06 22:57   ` [patch 32/37] sky2: accept flow control Greg KH
2006-09-06 22:57   ` [patch 33/37] sky2: clear status IRQ after empty Greg KH
2006-09-06 22:57   ` [patch 34/37] sky2: use dev_alloc_skb for receive buffers Greg KH
2006-09-06 22:58   ` [patch 35/37] sky2: MSI test timing Greg KH
2006-09-06 22:58   ` [patch 36/37] sky2: fix fiber support Greg KH
2006-09-06 22:58   ` [patch 37/37] sky2: version 1.6.1 Greg KH
2006-09-07 19:25     ` Pavel Machek
2006-09-07 20:34       ` Greg KH
2006-09-07 21:03         ` Pavel Machek
2006-09-07 21:50           ` Stephen Hemminger
2006-09-06 23:33   ` [patch 00/37] -stable review Adrian Bunk
2006-09-07  2:08     ` Greg KH

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=20060906225708.GX15922@kroah.com \
    --to=gregkh@suse.de \
    --cc=76306.1226@compuserve.com \
    --cc=akpm@osdl.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=chuckw@quantumlinux.com \
    --cc=davej@redhat.com \
    --cc=jmforbes@linuxtx.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=petrides@redhat.com \
    --cc=rdunlap@xenotime.net \
    --cc=reviews@ml.cw.f00f.org \
    --cc=stable@kernel.org \
    --cc=torvalds@osdl.org \
    --cc=tytso@mit.edu \
    --cc=zwane@arm.linux.org.uk \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox