Fix the use of syscall result in dl_mmap

Submitted by Ilya Matveychikov on Feb. 9, 2019, 2:56 p.m.

Details

Message ID 915E241F-3931-49F5-88C6-17888CBE5022@gmail.com
State New
Series "Add missing __syscall_ret in dl_mmap"
Headers show

Commit Message

Ilya Matveychikov Feb. 9, 2019, 2:56 p.m.
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(-)

—
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
>

Patch hide | download patch | download mbox

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)

Comments

Rich Felker April 6, 2019, 1:40 p.m.
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
> >