mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@linux-mips.org>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: Ralf Baechle <ralf@linux-mips.org>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] binfmt_elf: Don't clobber passed executable's file header
Date: Sun, 6 Sep 2015 23:26:44 +0100 (BST)	[thread overview]
Message-ID: <alpine.LFD.2.20.1509062059400.10227@eddie.linux-mips.org> (raw)

Do not clobber the buffer space passed from `search_binary_handler' and 
originally preloaded by `prepare_binprm' with the executable's file 
header by overwriting it with its interpreter's file header.  Instead 
keep the buffer space intact and directly use the data structure locally 
allocated for the interpreter's file header, fixing a bug introduced in 
2.1.14 with loadable module support (linux-mips.org commit beb11695 
[Import of Linux/MIPS 2.1.14], predating kernel.org repo's history).  
Adjust the amount of data read from the interpreter's file accordingly.

This was not an issue before loadable module support, because back then 
`load_elf_binary' was executed only once for a given ELF executable, 
whether the function succeeded or failed.

With loadable module support supported and enabled, upon a failure of 
`load_elf_binary' -- which may for example be caused by architecture 
code rejecting an executable due to a missing hardware feature requested 
in the file header -- a module load is attempted and then the function 
reexecuted by `search_binary_handler'.  With the executable's file 
header replaced with its interpreter's file header the executable can 
then be erroneously accepted in this subsequent attempt.

Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org>
---
Al,

 The bug (which has already reached its adulthood) was discovered with 
an upcoming MIPS feature which this fix is a prerequisite for.

 Please apply.

  Maciej

linux-load-elf-binary-interp-buf-fix.diff
Index: linux-org-test/fs/binfmt_elf.c
===================================================================
--- linux-org-test.orig/fs/binfmt_elf.c	2015-07-18 00:11:13.000000000 +0100
+++ linux-org-test/fs/binfmt_elf.c	2015-07-18 00:32:41.509841000 +0100
@@ -759,16 +759,16 @@ static int load_elf_binary(struct linux_
 			 */
 			would_dump(bprm, interpreter);
 
-			retval = kernel_read(interpreter, 0, bprm->buf,
-					     BINPRM_BUF_SIZE);
-			if (retval != BINPRM_BUF_SIZE) {
+			/* Get the exec headers */
+			retval = kernel_read(interpreter, 0,
+					     &loc->interp_elf_ex,
+					     sizeof(loc->interp_elf_ex));
+			if (retval != sizeof(loc->interp_elf_ex)) {
 				if (retval >= 0)
 					retval = -EIO;
 				goto out_free_dentry;
 			}
 
-			/* Get the exec headers */
-			loc->interp_elf_ex = *((struct elfhdr *)bprm->buf);
 			break;
 		}
 		elf_ppnt++;

                 reply	other threads:[~2015-09-06 22:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=alpine.LFD.2.20.1509062059400.10227@eddie.linux-mips.org \
    --to=macro@linux-mips.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ralf@linux-mips.org \
    --cc=viro@zeniv.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

all inboxes | Powered by JetHome®