From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 10494 invoked from network); 4 Jan 2022 21:42:29 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 4 Jan 2022 21:42:29 -0000 Received: (qmail 3301 invoked by uid 550); 4 Jan 2022 21:42:27 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 3263 invoked from network); 4 Jan 2022 21:42:26 -0000 Date: Tue, 4 Jan 2022 16:42:12 -0500 From: Rich Felker To: Nihal Jere Cc: musl@lists.openwall.com Message-ID: <20220104214211.GC7074@brightrain.aerifal.cx> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] Dynamic linker segfault On Tue, Jan 04, 2022 at 03:27:10PM -0600, Nihal Jere wrote: > Hi, > > ldd from master segfaults when run on [1] and [2]. It happens on > this[3] line. It seems to happen due to the intersection of a few > factors: > > 1. The segment at the lowest address is read-only. > 2. A segment on the the same page is read/write. > 3. The read/write segment has memsz > filesz. 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. What tooling generated this file? > This results in a segfault, as it tries to memset[3] on the mmap > created here[4], which has the same protection as the segment at > the lowest address (i.e. read-only). > > As far as I can see, the options are to either: > > a. detect this and throw an error. > b. 'or' together the protection flags of all the segments on the page. > > I'm not sure what the right behavior is, but I don't think segfaulting > is right, and I'm sure there are people here what's correct. There is a huge range of "syntactically valid but not correct" things ELF can represent, and musl has never attempted to catch or diagnose all such errors. It might be desirable to increase the level to which we catch common ones, but proceeding on this probably depends on how this file came to be. If it was made by intentionally passing bad options to the linker or with a custom linker that's not honoring the semantic requirements for an executable for the platform, I think there's a lot of lower-hanging fruit if we wanted to start diagnosing this sort of thing. Of course diagnosing p_align < PAGESIZE as an error might make sense in general. Rich