mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Andrew Rogers <andrew.rogerstech@gmail.com>
Cc: musl@lists.openwall.com
Subject: Re: [musl] Potential DL_NOMMU_SUPPORT bug.
Date: Sun, 24 Jan 2021 10:40:27 -0500	[thread overview]
Message-ID: <20210124154026.GR23432@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAFrSoMyOzH1xy9HeGMczpog5PmhhRQUB-J+gs9RpcTz-EvPdDw@mail.gmail.com>

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

  reply	other threads:[~2021-01-24 15:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-23  6:47 Andrew Rogers
2021-01-24 15:40 ` Rich Felker [this message]
2021-01-24 15:58   ` Alexander Monakov
2021-01-24 18:10     ` Rich Felker
2021-01-24 18:48       ` Alexander Monakov
2021-01-24 18:55         ` Rich Felker
2021-01-30 17:44           ` Andrew Rogers
2021-01-30 19:01             ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210124154026.GR23432@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=andrew.rogerstech@gmail.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).