mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] Add missing __syscall_ret in dl_mmap
@ 2019-02-09 13:34 Ilya Matveychikov
  2019-02-09 14:35 ` Rich Felker
  2019-02-09 14:56 ` [PATCH] Fix the use of syscall result " Ilya Matveychikov
  0 siblings, 2 replies; 4+ messages in thread
From: Ilya Matveychikov @ 2019-02-09 13:34 UTC (permalink / raw)
  To: musl

Signed-off-by: Ilya V. Matveychikov <matvejchikov@gmail.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;
 }

--
2.7.4



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add missing __syscall_ret in dl_mmap
  2019-02-09 13:34 [PATCH] Add missing __syscall_ret in dl_mmap Ilya Matveychikov
@ 2019-02-09 14:35 ` Rich Felker
  2019-02-09 14:56 ` [PATCH] Fix the use of syscall result " Ilya Matveychikov
  1 sibling, 0 replies; 4+ messages in thread
From: Rich Felker @ 2019-02-09 14:35 UTC (permalink / raw)
  To: musl

On Sat, Feb 09, 2019 at 05:34:02PM +0400, Ilya Matveychikov wrote:
> Signed-off-by: Ilya V. Matveychikov <matvejchikov@gmail.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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] Fix the use of syscall result in dl_mmap
  2019-02-09 13:34 [PATCH] Add missing __syscall_ret in dl_mmap Ilya Matveychikov
  2019-02-09 14:35 ` Rich Felker
@ 2019-02-09 14:56 ` Ilya Matveychikov
  2019-04-06 13:40   ` Rich Felker
  1 sibling, 1 reply; 4+ messages in thread
From: Ilya Matveychikov @ 2019-02-09 14:56 UTC (permalink / raw)
  To: musl; +Cc: dalias

Correct version of the change thanks to Rich Felker!

I was not cc-ed, so here is the discussion:
https://www.openwall.com/lists/musl/2019/02/09/2


Signed-off-by: Ilya V. Matveychikov <matvejchikov@gmail.com>
---
 ldso/dynlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index ec921df..76e8c06 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -904,7 +904,7 @@ static void *dl_mmap(size_t n)
 #else
 	p = (void *)__syscall(SYS_mmap, 0, n, prot, flags, -1, 0);
 #endif
-	return p == MAP_FAILED ? 0 : p;
+	return (unsigned long)p > -4096UL ? 0 : p;
 }

 static void makefuncdescs(struct dso *p)
—
2.7.4


> On Feb 9, 2019, at 5:34 PM, Ilya Matveychikov <matvejchikov@gmail.com> wrote:
> 
> Signed-off-by: Ilya V. Matveychikov <matvejchikov@gmail.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;
> }
> 
> --
> 2.7.4
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix the use of syscall result in dl_mmap
  2019-02-09 14:56 ` [PATCH] Fix the use of syscall result " Ilya Matveychikov
@ 2019-04-06 13:40   ` Rich Felker
  0 siblings, 0 replies; 4+ messages in thread
From: Rich Felker @ 2019-04-06 13:40 UTC (permalink / raw)
  To: Ilya Matveychikov; +Cc: musl

On Sat, Feb 09, 2019 at 06:56:17PM +0400, Ilya Matveychikov wrote:
> Correct version of the change thanks to Rich Felker!
> 
> I was not cc-ed, so here is the discussion:
> https://www.openwall.com/lists/musl/2019/02/09/2

Thanks! Sorry I overlooked this before. I'm applying it now.

Rich


> Signed-off-by: Ilya V. Matveychikov <matvejchikov@gmail.com>
> ---
>  ldso/dynlink.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/ldso/dynlink.c b/ldso/dynlink.c
> index ec921df..76e8c06 100644
> --- a/ldso/dynlink.c
> +++ b/ldso/dynlink.c
> @@ -904,7 +904,7 @@ static void *dl_mmap(size_t n)
>  #else
>  	p = (void *)__syscall(SYS_mmap, 0, n, prot, flags, -1, 0);
>  #endif
> -	return p == MAP_FAILED ? 0 : p;
> +	return (unsigned long)p > -4096UL ? 0 : p;
>  }
> 
>  static void makefuncdescs(struct dso *p)
> —
> 2.7.4
> 
> 
> > On Feb 9, 2019, at 5:34 PM, Ilya Matveychikov <matvejchikov@gmail.com> wrote:
> > 
> > Signed-off-by: Ilya V. Matveychikov <matvejchikov@gmail.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;
> > }
> > 
> > --
> > 2.7.4
> > 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-04-06 13:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-09 13:34 [PATCH] Add missing __syscall_ret in dl_mmap Ilya Matveychikov
2019-02-09 14:35 ` Rich Felker
2019-02-09 14:56 ` [PATCH] Fix the use of syscall result " Ilya Matveychikov
2019-04-06 13:40   ` Rich Felker

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).