[PATCH v2 2/2] linux-user: Don't require PROT_READ for mincore

Thomas Weißschuh posted 2 patches 2 years, 9 months ago
Maintainers: Laurent Vivier <laurent@vivier.eu>
[PATCH v2 2/2] linux-user: Don't require PROT_READ for mincore
Posted by Thomas Weißschuh 2 years, 9 months ago
The kernel does not require PROT_READ for addresses passed to mincore.
For example the fincore(1) tool from util-linux uses PROT_NONE and
currently does not work under qemu-user.

Example (with fincore(1) from util-linux 2.38):

$ fincore /proc/self/exe
RES PAGES  SIZE FILE
24K     6 22.1K /proc/self/exe

$ qemu-x86_64 /usr/bin/fincore /proc/self/exe
fincore: failed to do mincore: /proc/self/exe: Cannot allocate memory

With this patch:

$ ./build/qemu-x86_64 /usr/bin/fincore /proc/self/exe
RES PAGES  SIZE FILE
24K     6 22.1K /proc/self/exe

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
---
 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 69f740ff98c8..5ec848b459f7 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -11897,7 +11897,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
 #ifdef TARGET_NR_mincore
     case TARGET_NR_mincore:
         {
-            void *a = lock_user(VERIFY_READ, arg1, arg2, 0);
+            void *a = lock_user(VERIFY_NONE, arg1, arg2, 0);
             if (!a) {
                 return -TARGET_ENOMEM;
             }
-- 
2.40.0


Re: [PATCH v2 2/2] linux-user: Don't require PROT_READ for mincore
Posted by Laurent Vivier 2 years, 9 months ago
Le 22/04/2023 à 12:03, Thomas Weißschuh a écrit :
> The kernel does not require PROT_READ for addresses passed to mincore.
> For example the fincore(1) tool from util-linux uses PROT_NONE and
> currently does not work under qemu-user.
> 
> Example (with fincore(1) from util-linux 2.38):
> 
> $ fincore /proc/self/exe
> RES PAGES  SIZE FILE
> 24K     6 22.1K /proc/self/exe
> 
> $ qemu-x86_64 /usr/bin/fincore /proc/self/exe
> fincore: failed to do mincore: /proc/self/exe: Cannot allocate memory
> 
> With this patch:
> 
> $ ./build/qemu-x86_64 /usr/bin/fincore /proc/self/exe
> RES PAGES  SIZE FILE
> 24K     6 22.1K /proc/self/exe
> 
> Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
> ---
>   linux-user/syscall.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 69f740ff98c8..5ec848b459f7 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -11897,7 +11897,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
>   #ifdef TARGET_NR_mincore
>       case TARGET_NR_mincore:
>           {
> -            void *a = lock_user(VERIFY_READ, arg1, arg2, 0);
> +            void *a = lock_user(VERIFY_NONE, arg1, arg2, 0);
>               if (!a) {
>                   return -TARGET_ENOMEM;
>               }

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

Thanks,
Laurent

Re: [PATCH v2 2/2] linux-user: Don't require PROT_READ for mincore
Posted by Laurent Vivier 2 years, 9 months ago
Le 22/04/2023 à 12:03, Thomas Weißschuh a écrit :
> The kernel does not require PROT_READ for addresses passed to mincore.
> For example the fincore(1) tool from util-linux uses PROT_NONE and
> currently does not work under qemu-user.
> 
> Example (with fincore(1) from util-linux 2.38):
> 
> $ fincore /proc/self/exe
> RES PAGES  SIZE FILE
> 24K     6 22.1K /proc/self/exe
> 
> $ qemu-x86_64 /usr/bin/fincore /proc/self/exe
> fincore: failed to do mincore: /proc/self/exe: Cannot allocate memory
> 
> With this patch:
> 
> $ ./build/qemu-x86_64 /usr/bin/fincore /proc/self/exe
> RES PAGES  SIZE FILE
> 24K     6 22.1K /proc/self/exe
> 
> Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
> ---
>   linux-user/syscall.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 69f740ff98c8..5ec848b459f7 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -11897,7 +11897,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
>   #ifdef TARGET_NR_mincore
>       case TARGET_NR_mincore:
>           {
> -            void *a = lock_user(VERIFY_READ, arg1, arg2, 0);
> +            void *a = lock_user(VERIFY_NONE, arg1, arg2, 0);
>               if (!a) {
>                   return -TARGET_ENOMEM;
>               }

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