Re: [PATCH v3] fs/binfmt_elf: Fix memsz > filesz handling

From: Kees Cook
Date: Thu Nov 10 2022 - 22:38:53 EST


On Tue, Nov 08, 2022 at 11:07:15AM +0000, Pedro Falcato wrote:
> [...]
> + * This tail logic is skippable if we're the last phdr, as
> + * nothing can map an address >= our p_vaddr, since ELF phdr
> + * PT_LOAD segments are required to be sorted in an increasing
> + * order.

I'm still looking through the patch, but I do want to call this bit out
as a problem. The kernel cannot, unfortunately, make this assumption. See:
https://lore.kernel.org/linux-fsdevel/YfOooXQ2ScpZLhmD@fractal.localdomain/

"It turns out that almost all native Linux games published by the Virtual
Programming company have this kind of weird PT_LOAD ordering including
the famous Bioshock Infinite ... Someone should probably ask Virtual
Programming, what kind of tooling they use to create such convoluted
ELF binaries."

So, even though it's in violation of the spec, these binaries exist in
the real world, and we cannot break them. :(

--
Kees Cook