Commit ecace842 authored by Jann Horn's avatar Jann Horn Committed by Greg Kroah-Hartman

fs/binfmt_flat.c: make load_flat_shared_library() work

commit 867bfa4a upstream.

load_flat_shared_library() is broken: It only calls load_flat_file() if
prepare_binprm() returns zero, but prepare_binprm() returns the number of
bytes read - so this only happens if the file is empty.

Instead, call into load_flat_file() if the number of bytes read is
non-negative. (Even if the number of bytes is zero - in that case,
load_flat_file() will see nullbytes and return a nice -ENOEXEC.)

In addition, remove the code related to bprm creds and stop using
prepare_binprm() - this code is loading a library, not a main executable,
and it only actually uses the members "buf", "file" and "filename" of the
linux_binprm struct. Instead, call kernel_read() directly.

Link: http://lkml.kernel.org/r/20190524201817.16509-1-jannh@google.com
Fixes: 287980e4 ("remove lots of IS_ERR_VALUE abuses")
Signed-off-by: default avatarJann Horn <jannh@google.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Kees Cook <keescook@chromium.org>
Cc: Nicolas Pitre <nicolas.pitre@linaro.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Greg Ungerer <gerg@linux-m68k.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 41ceb21b
...@@ -856,9 +856,14 @@ static int load_flat_file(struct linux_binprm *bprm, ...@@ -856,9 +856,14 @@ static int load_flat_file(struct linux_binprm *bprm,
static int load_flat_shared_library(int id, struct lib_info *libs) static int load_flat_shared_library(int id, struct lib_info *libs)
{ {
/*
* This is a fake bprm struct; only the members "buf", "file" and
* "filename" are actually used.
*/
struct linux_binprm bprm; struct linux_binprm bprm;
int res; int res;
char buf[16]; char buf[16];
loff_t pos = 0;
memset(&bprm, 0, sizeof(bprm)); memset(&bprm, 0, sizeof(bprm));
...@@ -872,25 +877,11 @@ static int load_flat_shared_library(int id, struct lib_info *libs) ...@@ -872,25 +877,11 @@ static int load_flat_shared_library(int id, struct lib_info *libs)
if (IS_ERR(bprm.file)) if (IS_ERR(bprm.file))
return res; return res;
bprm.cred = prepare_exec_creds(); res = kernel_read(bprm.file, bprm.buf, BINPRM_BUF_SIZE, &pos);
res = -ENOMEM;
if (!bprm.cred)
goto out;
/* We don't really care about recalculating credentials at this point
* as we're past the point of no return and are dealing with shared
* libraries.
*/
bprm.called_set_creds = 1;
res = prepare_binprm(&bprm); if (res >= 0)
if (!res)
res = load_flat_file(&bprm, libs, id, NULL); res = load_flat_file(&bprm, libs, id, NULL);
abort_creds(bprm.cred);
out:
allow_write_access(bprm.file); allow_write_access(bprm.file);
fput(bprm.file); fput(bprm.file);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment