Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190209143545.GY23599@brightrain.aerifal.cx>
Date: Sat, 9 Feb 2019 09:35:45 -0500
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: [PATCH] Add missing __syscall_ret in dl_mmap

On Sat, Feb 09, 2019 at 05:34:02PM +0400, Ilya Matveychikov wrote:
> Signed-off-by: Ilya V. Matveychikov <matvejchikov@...il.com>
> ---
>  ldso/dynlink.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/ldso/dynlink.c b/ldso/dynlink.c
> index ec921df..329b42a 100644
> --- a/ldso/dynlink.c
> +++ b/ldso/dynlink.c
> @@ -904,6 +904,7 @@ static void *dl_mmap(size_t n)
>  #else
>  	p = (void *)__syscall(SYS_mmap, 0, n, prot, flags, -1, 0);
>  #endif
> +	p = (void *)__syscall_ret((unsigned long)p);
>  	return p == MAP_FAILED ? 0 : p;
>  }

I think you're right that the calling code expects dl_mmap to return
0, not a negative error code cast to an invalid pointer, on failure.
However the change above is wrong. The whole reason the dl_mmap
function exists is that it's used at a point at which non-static
function calls can't be made (technically, calls to hidden functions
probably work but it's not a property that we rely on), and at which
accessing TLS (and thus errno in the error path) is not yet possible.

The right fix would probably be something like:

	return (uintptr_t)p > -4096 ? 0 : p;

Out of curiousity, how did you come across this?

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.