Subject: [RFC PATCH] Return ENOEXEC instead of ENOENT if an ELF binary's interpreter doesn't exist.

From: Geoffrey Thomas <[email-masked]>
Date: Tue, 28 Apr 2009 15:09:00 -0400

If you try to execute a binary compiled for ld-linux.so.1 (libc5) on a machine
with only ld-linux.so.2 (libc6), your shell will claim "mybinary: No such file
or directory", even though the binary exists. The ENOENT actually applies to
the ELF intepreter, not to the file itself. This patch causes it to give a more
helpful and more expected error, "cannot execute binary file".

Signed-off-by: Geoffrey Thomas <[email-masked]>
Tested-by: Anders Kaseorg <[email-masked]>
---
 fs/binfmt_elf.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 33b7235..83bfa14 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -699,8 +699,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
 
 			interpreter = open_exec(elf_interpreter);
 			retval = PTR_ERR(interpreter);
-			if (IS_ERR(interpreter))
+			if (IS_ERR(interpreter)) {
+				if (retval == -ENOENT)
+					retval = -ENOEXEC;
 				goto out_free_interp;
+			}
 
 			/*
 			 * If the binary is not readable then enforce
-- 
1.5.6.5