Date: Wed, 5 Jan 2022 10:00:35 -0500 From: Rich Felker <dalias@...c.org> To: Florian Weimer <fweimer@...hat.com> Cc: Nihal Jere <nihal@...aljere.xyz>, musl@...ts.openwall.com Subject: Re: Dynamic linker segfault On Wed, Jan 05, 2022 at 03:00:53PM +0100, Florian Weimer wrote: > * Rich Felker: > > > On Wed, Jan 05, 2022 at 09:56:25AM +0100, Florian Weimer wrote: > >> * Rich Felker: > >> > >> > This is a malformed program file not compatible with the machine page > >> > size (4k). Arguably it should be detected as p_align < PAGESIZE -- in > >> > a sense, p_align for LOAD segments is the maximum supported page size > >> > for the program file, and machines not capable of providing a page > >> > size that small can't map/run it. In theory the loader could allow > >> > this if all the differences between segments satisfy the right > >> > congruences and have matching permissions where the maps would > >> > overlap, but I'm not sure that's useful. > >> > >> We've been looking at this on the glibc side recently. The use case is > >> supporting large data alignments (greater than the kernel page size) > >> while not pessimizing multi-page-size targets such as POWER and AArch64. > > > > I'm not clear how it pessimizes these targets (beyond what's > > fundamentally necessary) unless you're artificially aligning segment > > contents on disk to a large alignment boundary to prevent over-mapping > > (undermining separate-code for example). And if you're doing that, you > > need the full alignment anyway to support machines with larger > > hardware pagesize. Otherwise you'd get back the overmapping (and > > unwanted perission exposure). > > Hmm. Maybe I should rephrase: > > With a p_align < PAGESIZE check in place, portable binaries need to use > the value 65536. When running with page size 4096, the loader cannot > know whether p_align was set to this value merely to satisfy the p_align > < PAGESIZE check, or because there is actually some section alignment > that requires 65536 byte alignment. There is no kernel interface to > request 65536 byte alignment, so the loader has to do extra work to > satisfy this request. And in the first case (no actual 65536 byte > alignment requirement), that work is unnecessary. Unfortunately it's impossible to distinguish between such an alignment requirement and __attribute__((__aligned__(65536))) appearing in section contents that went into the segment, so disregarding it is a bug (one musl also has) I think. > > In any case, do you know if this test file is somehow related to that > > work, or is it just a guess? It doesn't seem to be related to me since > > it's essentially a "pageless" mapping setup. > > The glibc test seems to be just buggy: First we verify p_align against > the page size, then we use that p_align value to check the alignment of > the PT_LOAD segment (mainly file offset congruency). The p_align check > against the page size looks completely optional to me if we check file > offset congruency directly against the run-time page size. > > The ELF specification explicitly describes the p_align values 0 and 1 as > valid, indicating no alignment constraint. So a p_align < PAGESIZE > check is buggy in that regard as well. This also conflicts with your > interpretation as p_align as the maximum supported page size. The ELF specification describes syntax not semantic requirements on the platform to support anything the syntax can represent. The semantics of the above can't be honored (without memcpy instead of mmap, which is really something you don't want to support) if they produce congruences incompatible with the layout, and they can't be honored at all if they're incompatible with the permissions requirements. Even when they don't conflict with the permissions requirements, they may expose unintended mapped data (which for users wanting separate-code is problematic, since it introduces gadgets). So I'm not convinced it should be supported even when it "can". Note also that segments (PT_LOAD) are not the only type of program headers, and p_align of 0 or 1 may make more sense for other types. Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.