All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] linux-user/mmap.c: Avoid choosing NULL as start address
@ 2018-01-07  1:01 Maximilian Riemensberger
  2018-01-07 12:39 ` Laurent Vivier
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Maximilian Riemensberger @ 2018-01-07  1:01 UTC (permalink / raw)
  To: qemu-devel
  Cc: Maximilian Riemensberger, Riku Voipio, Laurent Vivier, Peter Maydell

mmap() is required by the linux kernel ABI and POSIX to return a
non-NULL address when the implementation chooses a start address for the
mapping.

The current implementation of mmap_find_vma_reserved() can return NULL
as start address of a mapping which leads to subsequent crashes inside
the guests glibc, e.g. output of qemu-arm-static --strace executing a
test binary stx_test:

    1879 mmap2(NULL,8388608,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|0x20000,-1,0) = 0x00000000
    1879 write(2,0xf6fd39d0,79) stx_test: allocatestack.c:514: allocate_stack: Assertion `mem != NULL' failed.

This patch fixes mmap_find_vma_reserved() by skipping NULL as start
address while searching for a suitable mapping start address.

CC: Riku Voipio <riku.voipio@iki.fi>
CC: Laurent Vivier <laurent@vivier.eu>
CC: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Maximilian Riemensberger <riemensberger@cadami.net>
---
Changes since v1:
    - Applied feedback from Laurent Vivier

 linux-user/mmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 4888f53..0fbfd6d 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -234,7 +234,7 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size)
         if (prot) {
             end_addr = addr;
         }
-        if (addr + size == end_addr) {
+        if (addr && addr + size == end_addr) {
             break;
         }
         addr -= qemu_host_page_size;
-- 
2.7.4

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

* Re: [Qemu-devel] [PATCH v2] linux-user/mmap.c: Avoid choosing NULL as start address
  2018-01-07  1:01 [Qemu-devel] [PATCH v2] linux-user/mmap.c: Avoid choosing NULL as start address Maximilian Riemensberger
@ 2018-01-07 12:39 ` Laurent Vivier
  2018-01-08 20:28 ` Richard Henderson
  2018-01-19 16:34 ` Laurent Vivier
  2 siblings, 0 replies; 4+ messages in thread
From: Laurent Vivier @ 2018-01-07 12:39 UTC (permalink / raw)
  To: Maximilian Riemensberger, qemu-devel; +Cc: Riku Voipio, Peter Maydell

Le 07/01/2018 à 02:01, Maximilian Riemensberger a écrit :
> mmap() is required by the linux kernel ABI and POSIX to return a
> non-NULL address when the implementation chooses a start address for the
> mapping.
> 
> The current implementation of mmap_find_vma_reserved() can return NULL
> as start address of a mapping which leads to subsequent crashes inside
> the guests glibc, e.g. output of qemu-arm-static --strace executing a
> test binary stx_test:
> 
>     1879 mmap2(NULL,8388608,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|0x20000,-1,0) = 0x00000000
>     1879 write(2,0xf6fd39d0,79) stx_test: allocatestack.c:514: allocate_stack: Assertion `mem != NULL' failed.
> 
> This patch fixes mmap_find_vma_reserved() by skipping NULL as start
> address while searching for a suitable mapping start address.
> 
> CC: Riku Voipio <riku.voipio@iki.fi>
> CC: Laurent Vivier <laurent@vivier.eu>
> CC: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Maximilian Riemensberger <riemensberger@cadami.net>
> ---
> Changes since v1:
>     - Applied feedback from Laurent Vivier
> 
>  linux-user/mmap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/linux-user/mmap.c b/linux-user/mmap.c
> index 4888f53..0fbfd6d 100644
> --- a/linux-user/mmap.c
> +++ b/linux-user/mmap.c
> @@ -234,7 +234,7 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size)
>          if (prot) {
>              end_addr = addr;
>          }
> -        if (addr + size == end_addr) {
> +        if (addr && addr + size == end_addr) {
>              break;
>          }
>          addr -= qemu_host_page_size;
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>

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

* Re: [Qemu-devel] [PATCH v2] linux-user/mmap.c: Avoid choosing NULL as start address
  2018-01-07  1:01 [Qemu-devel] [PATCH v2] linux-user/mmap.c: Avoid choosing NULL as start address Maximilian Riemensberger
  2018-01-07 12:39 ` Laurent Vivier
@ 2018-01-08 20:28 ` Richard Henderson
  2018-01-19 16:34 ` Laurent Vivier
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2018-01-08 20:28 UTC (permalink / raw)
  To: Maximilian Riemensberger, qemu-devel
  Cc: Peter Maydell, Riku Voipio, Laurent Vivier

On 01/06/2018 05:01 PM, Maximilian Riemensberger wrote:
> mmap() is required by the linux kernel ABI and POSIX to return a
> non-NULL address when the implementation chooses a start address for the
> mapping.
> 
> The current implementation of mmap_find_vma_reserved() can return NULL
> as start address of a mapping which leads to subsequent crashes inside
> the guests glibc, e.g. output of qemu-arm-static --strace executing a
> test binary stx_test:
> 
>     1879 mmap2(NULL,8388608,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|0x20000,-1,0) = 0x00000000
>     1879 write(2,0xf6fd39d0,79) stx_test: allocatestack.c:514: allocate_stack: Assertion `mem != NULL' failed.
> 
> This patch fixes mmap_find_vma_reserved() by skipping NULL as start
> address while searching for a suitable mapping start address.
> 
> CC: Riku Voipio <riku.voipio@iki.fi>
> CC: Laurent Vivier <laurent@vivier.eu>
> CC: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Maximilian Riemensberger <riemensberger@cadami.net>
> ---
> Changes since v1:
>     - Applied feedback from Laurent Vivier

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

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

* Re: [Qemu-devel] [PATCH v2] linux-user/mmap.c: Avoid choosing NULL as start address
  2018-01-07  1:01 [Qemu-devel] [PATCH v2] linux-user/mmap.c: Avoid choosing NULL as start address Maximilian Riemensberger
  2018-01-07 12:39 ` Laurent Vivier
  2018-01-08 20:28 ` Richard Henderson
@ 2018-01-19 16:34 ` Laurent Vivier
  2 siblings, 0 replies; 4+ messages in thread
From: Laurent Vivier @ 2018-01-19 16:34 UTC (permalink / raw)
  To: Maximilian Riemensberger, qemu-devel; +Cc: Peter Maydell, Riku Voipio

Le 07/01/2018 à 02:01, Maximilian Riemensberger a écrit :
> mmap() is required by the linux kernel ABI and POSIX to return a
> non-NULL address when the implementation chooses a start address for the
> mapping.
> 
> The current implementation of mmap_find_vma_reserved() can return NULL
> as start address of a mapping which leads to subsequent crashes inside
> the guests glibc, e.g. output of qemu-arm-static --strace executing a
> test binary stx_test:
> 
>     1879 mmap2(NULL,8388608,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|0x20000,-1,0) = 0x00000000
>     1879 write(2,0xf6fd39d0,79) stx_test: allocatestack.c:514: allocate_stack: Assertion `mem != NULL' failed.
> 
> This patch fixes mmap_find_vma_reserved() by skipping NULL as start
> address while searching for a suitable mapping start address.
> 
> CC: Riku Voipio <riku.voipio@iki.fi>
> CC: Laurent Vivier <laurent@vivier.eu>
> CC: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Maximilian Riemensberger <riemensberger@cadami.net>
> ---
> Changes since v1:
>     - Applied feedback from Laurent Vivier
> 
>  linux-user/mmap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/linux-user/mmap.c b/linux-user/mmap.c
> index 4888f53..0fbfd6d 100644
> --- a/linux-user/mmap.c
> +++ b/linux-user/mmap.c
> @@ -234,7 +234,7 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size)
>          if (prot) {
>              end_addr = addr;
>          }
> -        if (addr + size == end_addr) {
> +        if (addr && addr + size == end_addr) {
>              break;
>          }
>          addr -= qemu_host_page_size;
> 

Applied to my linux-user branch.

Thanks,
Laurent

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

end of thread, other threads:[~2018-01-19 16:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-07  1:01 [Qemu-devel] [PATCH v2] linux-user/mmap.c: Avoid choosing NULL as start address Maximilian Riemensberger
2018-01-07 12:39 ` Laurent Vivier
2018-01-08 20:28 ` Richard Henderson
2018-01-19 16:34 ` Laurent Vivier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.