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 14313 invoked from network); 24 Jan 2021 15:40:48 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 24 Jan 2021 15:40:48 -0000 Received: (qmail 28253 invoked by uid 550); 24 Jan 2021 15:40:41 -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 28235 invoked from network); 24 Jan 2021 15:40:40 -0000 Date: Sun, 24 Jan 2021 10:40:27 -0500 From: Rich Felker To: Andrew Rogers Cc: musl@lists.openwall.com Message-ID: <20210124154026.GR23432@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] Potential DL_NOMMU_SUPPORT bug. On Sat, Jan 23, 2021 at 06:47:00AM +0000, Andrew Rogers wrote: > Hi, > > I was trying a DL_NOMMU_SUPPORT build so I could load binaries from the > sdcard on an android device. I managed to succeed but only after making a > mod which I later realised might apply beyond my application. > > The mmap_fixed() function would return as if successful even when mmap() > call had failed > > Hopefully the link and the patch below help. > > Regards > Andrew > > https://git.musl-libc.org/cgit/musl/tree/ldso/dynlink.c?id=85e0e3519655220688e757b9d5bfd314923548bd#n584 > > diff -Naur musl-1.2.2-orig/ldso/dynlink.c musl-1.2.2-new/ldso/dynlink.c > --- musl-1.2.2-orig/ldso/dynlink.c 2021-01-15 02:26:00.000000000 +0000 > +++ musl-1.2.2-new/ldso/dynlink.c 2021-01-23 06:26:26.861158169 +0000 > @@ -581,7 +581,7 @@ > char *q; > if (!no_map_fixed) { > q = mmap(p, n, prot, flags|MAP_FIXED, fd, off); > - if (!DL_NOMMU_SUPPORT || q != MAP_FAILED || errno != EINVAL) > + if (!DL_NOMMU_SUPPORT && q != MAP_FAILED && errno != EINVAL) > return q; > no_map_fixed = 1; > } > diff -Naur musl-1.2.2-orig/ldso/dynlink.c musl-1.2.2-new/ldso/dynlink.c > --- musl-1.2.2-orig/ldso/dynlink.c 2021-01-15 02:26:00.000000000 +0000 > +++ musl-1.2.2-new/ldso/dynlink.c 2021-01-23 06:26:26.861158169 +0000 > @@ -581,7 +581,7 @@ > char *q; > if (!no_map_fixed) { > q = mmap(p, n, prot, flags|MAP_FIXED, fd, off); > - if (!DL_NOMMU_SUPPORT || q != MAP_FAILED || errno != EINVAL) > + if (!DL_NOMMU_SUPPORT && q != MAP_FAILED && errno != EINVAL) > return q; > no_map_fixed = 1; > } The condition was correct as written. If any of the 3 are true, there is no fallback to be done: - If it's not an arch that could be nommu, mmap can be expected to work. Any error should be reported rather than attempting to emulate. - If the return value isn't failure, it already succeeded, so of course you don't want to emulate on top of that. - If the call failed but errno is something other than EINVAL (the error mmap returns on nommu when it can't do MAP_FIXED) then it's an error to report rather than emulating. Could you clarify what you're trying to do? Android devices are not nommu and loading the binary from SD card vs elsewhere should not be relevant to mmap failure here. Rich