[Mesa-stable] [PATCH] gallium/rtasm: handle mmap failures appropriately

Brian Paul brianp at vmware.com
Mon Jan 20 06:24:43 PST 2014


On 01/19/2014 03:53 PM, Emil Velikov wrote:
> For a variety of reasons mmap (selinux and pax to name
> a few) and can fail and with current code. This will
> result in a crash in the driver, if not worse.
>
> This has been the case since the inception of the
> gallium copy of rtasm.
>
> Cc: 9.1 9.2 10.0 <mesa-stable at lists.freedesktop.org>
> Bugzilla: https://urldefense.proofpoint.com/v1/url?u=https://bugs.freedesktop.org/show_bug.cgi?id%3D73473&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=lGQMzzTgII0I7jefp2FHq7WtZ%2BTLs8wadB%2BiIj9xpBY%3D%0A&m=HPJqceRvrkWAvMEdeyzPPcbd%2FcPbXTxpGUq0SGYEZK8%3D%0A&s=0d66626c4c519d8deb5a2f0ca3de1c2c74a29664641e14ba228ec317eb03240e
> Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
> ---
> v2: droped the selinux part, leaving only the crucial mmap check
>
> Gents can someone take a look at this trivial patch.
>
> Cheers,
> Emil
> ---
>   src/gallium/auxiliary/rtasm/rtasm_execmem.c | 10 +++++++---
>   1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/src/gallium/auxiliary/rtasm/rtasm_execmem.c b/src/gallium/auxiliary/rtasm/rtasm_execmem.c
> index edc1b66..8c3dbef 100644
> --- a/src/gallium/auxiliary/rtasm/rtasm_execmem.c
> +++ b/src/gallium/auxiliary/rtasm/rtasm_execmem.c
> @@ -69,7 +69,7 @@ static struct mem_block *exec_heap = NULL;
>   static unsigned char *exec_mem = NULL;
>
>
> -static void
> +static int

return boolean


>   init_heap(void)
>   {
>      if (!exec_heap)
> @@ -79,6 +79,8 @@ init_heap(void)
>         exec_mem = (unsigned char *) mmap(0, EXEC_HEAP_SIZE,
>   					PROT_EXEC | PROT_READ | PROT_WRITE,
>   					MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +
> +   return (exec_mem != MAP_FAILED);

Parens aren't really needed.


>   }
>
>
> @@ -90,7 +92,8 @@ rtasm_exec_malloc(size_t size)
>
>      pipe_mutex_lock(exec_mutex);
>
> -   init_heap();
> +   if (!init_heap())
> +      goto bail;
>
>      if (exec_heap) {
>         size = (size + 31) & ~31;  /* next multiple of 32 bytes */
> @@ -101,7 +104,8 @@ rtasm_exec_malloc(size_t size)
>         addr = exec_mem + block->ofs;
>      else
>         debug_printf("rtasm_exec_malloc failed\n");
> -
> +
> +bail:
>      pipe_mutex_unlock(exec_mutex);
>
>      return addr;
>

With those minor fixes:  Reviewed-by: Brian Paul <brianp at vmware.com>



More information about the mesa-stable mailing list