Skip to content

Commit d5ca24f

Browse files
committed
binfmt_elf: Use elf_load() for library
While load_elf_library() is a libc5-ism, we can still replace most of its contents with elf_load() as well, further simplifying the code. Some historical context: - libc4 was a.out and used uselib (a.out support has been removed) - libc5 was ELF and used uselib (there may still be users) - libc6 is ELF and has never used uselib Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Christian Brauner <brauner@kernel.org> Cc: linux-fsdevel@vger.kernel.org Cc: linux-mm@kvack.org Suggested-by: Eric Biederman <ebiederm@xmission.com> Tested-by: Pedro Falcato <pedro.falcato@gmail.com> Signed-off-by: Sebastian Ott <sebott@redhat.com> Link: https://lore.kernel.org/r/20230929032435.2391507-4-keescook@chromium.org Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent 8b04d32 commit d5ca24f

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

fs/binfmt_elf.c

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,6 @@ static int load_elf_library(struct file *file)
13061306
{
13071307
struct elf_phdr *elf_phdata;
13081308
struct elf_phdr *eppnt;
1309-
unsigned long elf_bss, bss, len;
13101309
int retval, error, i, j;
13111310
struct elfhdr elf_ex;
13121311

@@ -1351,30 +1350,15 @@ static int load_elf_library(struct file *file)
13511350
eppnt++;
13521351

13531352
/* Now use mmap to map the library into memory. */
1354-
error = vm_mmap(file,
1355-
ELF_PAGESTART(eppnt->p_vaddr),
1356-
(eppnt->p_filesz +
1357-
ELF_PAGEOFFSET(eppnt->p_vaddr)),
1353+
error = elf_load(file, ELF_PAGESTART(eppnt->p_vaddr),
1354+
eppnt,
13581355
PROT_READ | PROT_WRITE | PROT_EXEC,
13591356
MAP_FIXED_NOREPLACE | MAP_PRIVATE,
1360-
(eppnt->p_offset -
1361-
ELF_PAGEOFFSET(eppnt->p_vaddr)));
1362-
if (error != ELF_PAGESTART(eppnt->p_vaddr))
1363-
goto out_free_ph;
1357+
0);
13641358

1365-
elf_bss = eppnt->p_vaddr + eppnt->p_filesz;
1366-
if (padzero(elf_bss)) {
1367-
error = -EFAULT;
1359+
if (error != ELF_PAGESTART(eppnt->p_vaddr))
13681360
goto out_free_ph;
1369-
}
13701361

1371-
len = ELF_PAGEALIGN(eppnt->p_filesz + eppnt->p_vaddr);
1372-
bss = ELF_PAGEALIGN(eppnt->p_memsz + eppnt->p_vaddr);
1373-
if (bss > len) {
1374-
error = vm_brk(len, bss - len);
1375-
if (error)
1376-
goto out_free_ph;
1377-
}
13781362
error = 0;
13791363

13801364
out_free_ph:

0 commit comments

Comments
 (0)