Skip to content

Commit 867bfa4

Browse files
thejhtorvalds
authored andcommitted
fs/binfmt_flat.c: make load_flat_shared_library() work
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/[email protected] Fixes: 287980e ("remove lots of IS_ERR_VALUE abuses") Signed-off-by: Jann Horn <[email protected]> Cc: Alexander Viro <[email protected]> Cc: Kees Cook <[email protected]> Cc: Nicolas Pitre <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Russell King <[email protected]> Cc: Greg Ungerer <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 29b190f commit 867bfa4

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

fs/binfmt_flat.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,14 @@ static int load_flat_file(struct linux_binprm *bprm,
856856

857857
static int load_flat_shared_library(int id, struct lib_info *libs)
858858
{
859+
/*
860+
* This is a fake bprm struct; only the members "buf", "file" and
861+
* "filename" are actually used.
862+
*/
859863
struct linux_binprm bprm;
860864
int res;
861865
char buf[16];
866+
loff_t pos = 0;
862867

863868
memset(&bprm, 0, sizeof(bprm));
864869

@@ -872,25 +877,11 @@ static int load_flat_shared_library(int id, struct lib_info *libs)
872877
if (IS_ERR(bprm.file))
873878
return res;
874879

875-
bprm.cred = prepare_exec_creds();
876-
res = -ENOMEM;
877-
if (!bprm.cred)
878-
goto out;
879-
880-
/* We don't really care about recalculating credentials at this point
881-
* as we're past the point of no return and are dealing with shared
882-
* libraries.
883-
*/
884-
bprm.called_set_creds = 1;
880+
res = kernel_read(bprm.file, bprm.buf, BINPRM_BUF_SIZE, &pos);
885881

886-
res = prepare_binprm(&bprm);
887-
888-
if (!res)
882+
if (res >= 0)
889883
res = load_flat_file(&bprm, libs, id, NULL);
890884

891-
abort_creds(bprm.cred);
892-
893-
out:
894885
allow_write_access(bprm.file);
895886
fput(bprm.file);
896887

0 commit comments

Comments
 (0)