mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Bergner <bergner@vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: linuxppc64-dev@lists.linuxppc.org
Subject: [BUG][PATCH] fs/binfmt_elf.c:load_elf_binary() doesn't verify interpreter arch
Date: Thu, 16 Oct 2003 16:04:58 -0500	[thread overview]
Message-ID: <3F8F07FA.1030006@vnet.ibm.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1000 bytes --]

In fs/binfmt_elf.c:load_elf_binary() (both 2.6 and 2.4), there is some minimal
checking whether the interpreter it's about to load/run is a valid ELF file,
but it fails to check whether the interpreter is of the correct arch.
We ran into this when a borked powerpc64-linux toolchain set the interpreter
on our 64-bit app to our 32-bit ld.so.  Executing the app caused the kernel to
really chew up memory.  I'm assuming x86_64 and sparc64 might possibly see
the same behavior.

A patch against 2.6 is attached below for review (although it applies with some
fuzz on 2.4).  Note I'm not sure of the history behind INTERPRETER_AOUT, so I
added the test for INTERPRETER_ELF so as not to change it's behavior in case
someone still relies on it.

As an aside, it seems the elf_check_arch() macros should really be checking
for more than a valid e_machine value.  I'd think checking one or more of the
e_ident[EI_CLASS], e_ident[EI_DATA] and e_ident[EI_OSABI] values would be
required as well, no?

Peter



[-- Attachment #2: binfmt_elf.diff --]
[-- Type: text/plain, Size: 557 bytes --]

--- linux-2.5-orig/fs/binfmt_elf.c	2003-10-16 13:35:24.000000000 -0500
+++ linux-2.5/fs/binfmt_elf.c	2003-10-16 15:23:34.000000000 -0500
@@ -602,6 +602,10 @@
 			// printk(KERN_WARNING "ELF: Ambiguous type, using ELF\n");
 			interpreter_type = INTERPRETER_ELF;
 		}
+		/* Verify the interpreter has a valid arch */
+		if ((interpreter_type == INTERPRETER_ELF) &&
+		    !elf_check_arch(&interp_elf_ex))
+			goto out_free_dentry;
 	} else {
 		/* Executables without an interpreter also need a personality  */
 		SET_PERSONALITY(elf_ex, ibcs2_interpreter);

             reply	other threads:[~2003-10-16 21:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-16 21:04 Peter Bergner [this message]
2003-10-16 21:30 ` Jesper Juhl

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=3F8F07FA.1030006@vnet.ibm.com \
    --to=bergner@vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc64-dev@lists.linuxppc.org \
    /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

all inboxes | Powered by JetHome®