Return ENOEXEC, not ENOENT, if a binary's or script's interpreter doesn't exist.
Subsystems (2)
PATCH 1/1 Return ENOEXEC, not ENOENT, if a binary's or script's interpreter doesn't exist.
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. The same happens if you have a nonexistent interpreter in a shell script's shebang line.
Give a more helpful and more expected error, "cannot execute binary file", in these cases.
--- fs/binfmt_elf.c | 5 ++++- fs/binfmt_elf_fdpic.c | 2 ++ fs/binfmt_em86.c | 8 ++++++-- fs/binfmt_misc.c | 5 ++++- fs/binfmt_script.c | 8 ++++++-- 5 files changed, 22 insertions(+), 6 deletions(-)
fs/binfmt_elf.c +4 -1
@@ -685,8 +685,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
fs/binfmt_elf_fdpic.c +2 -0
@@ -232,6 +232,8 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm, interpreter =open_exec (interpreter_name); retval =PTR_ERR (interpreter);if (IS_ERR (interpreter)) { +if (retval == -ENOENT ) + retval = -ENOEXEC ; interpreter =NULL ; goto error; }
fs/binfmt_em86.c +6 -2
@@ -82,8 +82,12 @@ static int load_em86(struct linux_binprm *bprm,struct pt_regs *regs)* space, and we don't need to copy it. */ file =open_exec (interp); -if (IS_ERR (file)) -return PTR_ERR (file); +if (IS_ERR (file)) { +if (PTR_ERR (file) == -ENOENT ) +return -ENOEXEC ; +else +return PTR_ERR (file); + } bprm->file = file;
fs/binfmt_misc.c +4 -1
@@ -180,8 +180,11 @@ static int load_misc_binary(struct linux_binprm *bprm, struct pt_regs *regs) interp_file =open_exec (iname); retval =PTR_ERR (interp_file); -if (IS_ERR (interp_file)) +if (IS_ERR (interp_file)) { +if (retval == -ENOENT ) + retval = -ENOEXEC ; goto _error; + } bprm->file = interp_file;if (fmt->flags &MISC_FMT_CREDENTIALS ) {
fs/binfmt_script.c +6 -2
@@ -88,8 +88,12 @@ static int load_script(struct linux_binprm *bprm,struct pt_regs *regs)* OK, now restart the process with the interpreter's dentry. */ file =open_exec (interp); -if (IS_ERR (file)) -return PTR_ERR (file); +if (IS_ERR (file)) { +if (PTR_ERR (file) == -ENOENT ) +return -ENOEXEC ; +else +return PTR_ERR (file); + } bprm->file = file; retval =prepare_binprm (bprm);
Signature · 1 line
1.5.6.5
Quoted 11 lines · Geoffrey Thomas
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. The same happens if you have a nonexistent interpreter in a shell script's shebang line.
Give a more helpful and more expected error, "cannot execute binary file", in these cases.
Signed-off-by Geoffrey Thomas <[email protected]>Tested-by Anders Kaseorg <[email protected]>
Well, this is arguable... ENOEXEC and ENOENT are hard to choose here, but *personally* I agree with you according to your description.
And according to execve(2), this change breaks that documentation. If you really want to fix this, please also update the man page.
/me is also wondering if this change will break any user-space programs?
Thank you!
Quoted 101 lines
---
fs/binfmt_elf.c | 5 ++++- fs/binfmt_elf_fdpic.c | 2 ++ fs/binfmt_em86.c | 8 ++++++-- fs/binfmt_misc.c | 5 ++++- fs/binfmt_script.c | 8 ++++++-- 5 files changed, 22 insertions(+), 6 deletions(-)fs/binfmt_elf.c +4
-1@@ -685,8 +685,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 fs/binfmt_elf_fdpic.c +2
-0@@ -232,6 +232,8 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm, interpreter =open_exec (interpreter_name); retval =PTR_ERR (interpreter);if (IS_ERR (interpreter)) { +if (retval == -ENOENT ) + retval = -ENOEXEC ; interpreter =NULL ; goto error; }fs/binfmt_em86.c +6
-2@@ -82,8 +82,12 @@ static int load_em86(struct linux_binprm *bprm,struct pt_regs *regs)* space, and we don't need to copy it. */ file =open_exec (interp); -if (IS_ERR (file)) -return PTR_ERR (file); +if (IS_ERR (file)) { +if (PTR_ERR (file) == -ENOENT ) +return -ENOEXEC ; +else +return PTR_ERR (file); + } bprm->file = file;fs/binfmt_misc.c +4
-1@@ -180,8 +180,11 @@ static int load_misc_binary(struct linux_binprm *bprm, struct pt_regs *regs) interp_file =open_exec (iname); retval =PTR_ERR (interp_file); -if (IS_ERR (interp_file)) +if (IS_ERR (interp_file)) { +if (retval == -ENOENT ) + retval = -ENOEXEC ; goto _error; + } bprm->file = interp_file;if (fmt->flags &MISC_FMT_CREDENTIALS ) {fs/binfmt_script.c +6
-2@@ -88,8 +88,12 @@ static int load_script(struct linux_binprm *bprm,struct pt_regs *regs)* OK, now restart the process with the interpreter's dentry. */ file =open_exec (interp); -if (IS_ERR (file)) -return PTR_ERR (file); +if (IS_ERR (file)) { +if (PTR_ERR (file) == -ENOENT ) +return -ENOEXEC ; +else +return PTR_ERR (file); + } bprm->file = file; retval =prepare_binprm (bprm);Signature · 7 lines
1.5.6.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Quoted 8 lines · Geoffrey Thomas
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. The same happens if you have a nonexistent interpreter in a shell script's shebang line.
Give a more helpful and more expected error, "cannot execute binary file", in these cases.
NAK. Current behaviour is useful -- and it is really file thats missing.
Please improve manpage instead.
(chmod 000 /lib also produces 'interesting' error messages. Better
document those, too). Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html