Messages in this thread | | | Date | Fri, 28 Jan 2022 20:10:34 +0900 | From | Akira Kawata <> | Subject | Re: [PATCH v4 1/2] fs/binfmt_elf: Fix AT_PHDR for unusual ELF files |
| |
On Thu, Jan 27, 2022 at 08:23:51AM -0800, Kees Cook wrote: > On Thu, Jan 27, 2022 at 09:56:43PM +0900, Akira Kawata wrote: > > On Wed, Jan 26, 2022 at 09:01:30PM -0800, Kees Cook wrote: > > > [...] > > > 1) The ELF spec says e_phoff is 0 if there's no program header table. > > > > > > The old code would just pass the load_addr as a result. This patch will > > > now retain the same result (phdr_addr defaults to 0). I wonder if there > > > is a bug in this behavior, though? (To be addressed in a different patch > > > if needed...) > > > > > > > It is better to return NULL from load_elf_phdrs when e_phoff == 0, I > > think. > > Yeah, right now it just returns a pointer to file offset 0. > > I also wonder if we should sanity-check e_phoff vs PT_PHDR? Right now > Linux ignores PT_PHDR. Should we reject loading when e_phoff != PT_PHDR > file offset? (And I wonder if there are "broken" binaries right now that > have bad PT_PHDR segments that have gone unnoticed...)
I agree that unnoticed broken binaries exist. I checked glibc rtld and there is no check of e_phoff != PT_PHDR file offset.
> > And now I'm thinking about the excellent ELF loading analysis at: > https://nathanotterness.com/2021/10/tiny_elf_modernized.html > > ;)
I think you have interested in https://shinh.skr.jp/obf/bingolf.html also.
> > -- > Kees Cook
Akira Kawata
| |