diff mbox series

[2/2] linux-user: Adjust guest page protection for the host

Message ID 20200519185645.3915-3-richard.henderson@linaro.org
State Superseded
Headers show
Series linux-user: mmap/mprotect prot values | expand

Commit Message

Richard Henderson May 19, 2020, 6:56 p.m. UTC
Executable guest pages are never directly executed by
the host, but do need to be readable for translation.

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

---
 linux-user/mmap.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

-- 
2.20.1

Comments

Philippe Mathieu-Daudé May 20, 2020, 5:54 a.m. UTC | #1
On 5/19/20 8:56 PM, Richard Henderson wrote:
> Executable guest pages are never directly executed by

> the host, but do need to be readable for translation.

> 

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

> ---

>   linux-user/mmap.c | 6 +++++-

>   1 file changed, 5 insertions(+), 1 deletion(-)

> 

> diff --git a/linux-user/mmap.c b/linux-user/mmap.c

> index 36fd1e2250..84662c3311 100644

> --- a/linux-user/mmap.c

> +++ b/linux-user/mmap.c

> @@ -76,8 +76,12 @@ static int validate_prot_to_pageflags(int *host_prot, int prot)

>        * don't bother transforming guest bit to host bit.  Any other

>        * target-specific prot bits will not be understood by the host

>        * and will need to be encoded into page_flags for qemu emulation.

> +     *

> +     * Pages that are executable by the guest will never be executed

> +     * by the host, but the host will need to be able to read them.

>        */

> -    *host_prot = prot & (PROT_READ | PROT_WRITE | PROT_EXEC);

> +    *host_prot = (prot & (PROT_READ | PROT_WRITE))

> +               | (prot & PROT_EXEC ? PROT_READ : 0);

>   

>       return prot & ~valid ? 0 : page_flags;

>   }

> 


Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Peter Maydell July 6, 2020, 11:34 a.m. UTC | #2
On Tue, 19 May 2020 at 19:57, Richard Henderson
<richard.henderson@linaro.org> wrote:
>

> Executable guest pages are never directly executed by

> the host, but do need to be readable for translation.

>

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

> ---

>  linux-user/mmap.c | 6 +++++-

>  1 file changed, 5 insertions(+), 1 deletion(-)

>


Reviewed-by: Peter Maydell <peter.maydell@linaro.org>


thanks
-- PMM
Laurent Vivier Aug. 7, 2020, 9:44 a.m. UTC | #3
Le 19/05/2020 à 20:56, Richard Henderson a écrit :
> Executable guest pages are never directly executed by

> the host, but do need to be readable for translation.

> 

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

> ---

>  linux-user/mmap.c | 6 +++++-

>  1 file changed, 5 insertions(+), 1 deletion(-)

> 

> diff --git a/linux-user/mmap.c b/linux-user/mmap.c

> index 36fd1e2250..84662c3311 100644

> --- a/linux-user/mmap.c

> +++ b/linux-user/mmap.c

> @@ -76,8 +76,12 @@ static int validate_prot_to_pageflags(int *host_prot, int prot)

>       * don't bother transforming guest bit to host bit.  Any other

>       * target-specific prot bits will not be understood by the host

>       * and will need to be encoded into page_flags for qemu emulation.

> +     *

> +     * Pages that are executable by the guest will never be executed

> +     * by the host, but the host will need to be able to read them.

>       */

> -    *host_prot = prot & (PROT_READ | PROT_WRITE | PROT_EXEC);

> +    *host_prot = (prot & (PROT_READ | PROT_WRITE))

> +               | (prot & PROT_EXEC ? PROT_READ : 0);

>  

>      return prot & ~valid ? 0 : page_flags;

>  }

> 


Applied to my linux-user-for-5.2 branch.

Thanks,
Laurent
diff mbox series

Patch

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 36fd1e2250..84662c3311 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -76,8 +76,12 @@  static int validate_prot_to_pageflags(int *host_prot, int prot)
      * don't bother transforming guest bit to host bit.  Any other
      * target-specific prot bits will not be understood by the host
      * and will need to be encoded into page_flags for qemu emulation.
+     *
+     * Pages that are executable by the guest will never be executed
+     * by the host, but the host will need to be able to read them.
      */
-    *host_prot = prot & (PROT_READ | PROT_WRITE | PROT_EXEC);
+    *host_prot = (prot & (PROT_READ | PROT_WRITE))
+               | (prot & PROT_EXEC ? PROT_READ : 0);
 
     return prot & ~valid ? 0 : page_flags;
 }