[PATCH v3 0/4] binfmt_elf: Support segments with 0 filesz and misaligned starts

Kees Cook posted 4 patches 2 years, 4 months ago
There is a newer version of this series
fs/binfmt_elf.c | 192 ++++++++++++++++++------------------------------
1 file changed, 71 insertions(+), 121 deletions(-)
[PATCH v3 0/4] binfmt_elf: Support segments with 0 filesz and misaligned starts
Posted by Kees Cook 2 years, 4 months ago
Hi,

This is the continuation of the work Eric started for handling
"p_memsz > p_filesz" in arbitrary segments (rather than just the last,
BSS, segment). I've added the suggested changes:

 - drop unused "elf_bss" variable
 - report padzero() errors when PROT_WRITE is present
 - refactor load_elf_interp() to use elf_load()

This passes my quick smoke tests, but I'm still trying to construct some
more complete tests...

-Kees

Eric W. Biederman (1):
  binfmt_elf: Support segments with 0 filesz and misaligned starts

Kees Cook (3):
  binfmt_elf: elf_bss no longer used by load_elf_binary()
  binfmt_elf: Provide prot bits as context for padzero() errors
  binfmt_elf: Use elf_load() for interpreter

 fs/binfmt_elf.c | 192 ++++++++++++++++++------------------------------
 1 file changed, 71 insertions(+), 121 deletions(-)

-- 
2.34.1
Re: [PATCH v3 0/4] binfmt_elf: Support segments with 0 filesz and misaligned starts
Posted by Sebastian Ott 2 years, 4 months ago
On Tue, 26 Sep 2023, Kees Cook wrote:
> This is the continuation of the work Eric started for handling
> "p_memsz > p_filesz" in arbitrary segments (rather than just the last,
> BSS, segment). I've added the suggested changes:
>
> - drop unused "elf_bss" variable
> - report padzero() errors when PROT_WRITE is present
> - refactor load_elf_interp() to use elf_load()
>
> This passes my quick smoke tests, but I'm still trying to construct some
> more complete tests...

I've repeated all my tests with this one - no issues found.

Thanks,
Sebastian
Re: [PATCH v3 0/4] binfmt_elf: Support segments with 0 filesz and misaligned starts
Posted by Eric W. Biederman 2 years, 4 months ago
Kees Cook <keescook@chromium.org> writes:

> Hi,
>
> This is the continuation of the work Eric started for handling
> "p_memsz > p_filesz" in arbitrary segments (rather than just the last,
> BSS, segment). I've added the suggested changes:
>
>  - drop unused "elf_bss" variable
>  - report padzero() errors when PROT_WRITE is present
>  - refactor load_elf_interp() to use elf_load()
>
> This passes my quick smoke tests, but I'm still trying to construct some
> more complete tests...

Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>

You might also consider using elf_load in load_elf_library.

The code in load_elf_library only supports files with a single program
header, and I think is only needed for libc5.

The advantage is that load_elf_library would be using well tested code,
vm_brk would have no callers, and padzero would only be called by
elf_load, and load_elf_library would do little more than just call
load_elf_library.

Eric

>
> -Kees
>
> Eric W. Biederman (1):
>   binfmt_elf: Support segments with 0 filesz and misaligned starts
>
> Kees Cook (3):
>   binfmt_elf: elf_bss no longer used by load_elf_binary()
>   binfmt_elf: Provide prot bits as context for padzero() errors
>   binfmt_elf: Use elf_load() for interpreter
>
>  fs/binfmt_elf.c | 192 ++++++++++++++++++------------------------------
>  1 file changed, 71 insertions(+), 121 deletions(-)