All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] linux-user: Fix mincore() with PROT_NONE
@ 2023-04-22 10:03 Thomas Weißschuh
  2023-04-22 10:03 ` [PATCH v2 1/2] linux-user: Add new flag VERIFY_NONE Thomas Weißschuh
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2023-04-22 10:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: Thomas Weißschuh, Laurent Vivier

The kernel does not require PROT_READ for addresses passed to mincore.

v1: https://lore.kernel.org/qemu-devel/20230416195103.607948-1-thomas@t-8ch.de/
v1 -> v2:
* Introduce symbolic flag VERIFY_NONE instead of hardcoding "0"

Thomas Weißschuh (2):
  linux-user: Add new flag VERIFY_NONE
  linux-user: Don't require PROT_READ for mincore

 linux-user/qemu.h    | 1 +
 linux-user/syscall.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)


base-commit: 1cc6e1a20144c0ae360cbeb0e035fdee1bd80609
-- 
2.40.0



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

* [PATCH v2 1/2] linux-user: Add new flag VERIFY_NONE
  2023-04-22 10:03 [PATCH v2 0/2] linux-user: Fix mincore() with PROT_NONE Thomas Weißschuh
@ 2023-04-22 10:03 ` Thomas Weißschuh
  2023-05-01 15:48   ` Laurent Vivier
  2023-05-01 15:54   ` Laurent Vivier
  2023-04-22 10:03 ` [PATCH v2 2/2] linux-user: Don't require PROT_READ for mincore Thomas Weißschuh
  2023-04-23 17:24 ` [PATCH v2 0/2] linux-user: Fix mincore() with PROT_NONE Philippe Mathieu-Daudé
  2 siblings, 2 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2023-04-22 10:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: Thomas Weißschuh, Laurent Vivier

This can be used to validate that an address range is mapped but without
being readable or writable.

It will be used by an updated implementation of mincore().

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

diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index e2e93fbd1d5d..92f9f5af41c7 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -168,6 +168,7 @@ abi_long do_brk(abi_ulong new_brk);
 
 /* user access */
 
+#define VERIFY_NONE  0
 #define VERIFY_READ  PAGE_READ
 #define VERIFY_WRITE (PAGE_READ | PAGE_WRITE)
 
-- 
2.40.0



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

* [PATCH v2 2/2] linux-user: Don't require PROT_READ for mincore
  2023-04-22 10:03 [PATCH v2 0/2] linux-user: Fix mincore() with PROT_NONE Thomas Weißschuh
  2023-04-22 10:03 ` [PATCH v2 1/2] linux-user: Add new flag VERIFY_NONE Thomas Weißschuh
@ 2023-04-22 10:03 ` Thomas Weißschuh
  2023-05-01 15:48   ` Laurent Vivier
  2023-05-01 15:54   ` Laurent Vivier
  2023-04-23 17:24 ` [PATCH v2 0/2] linux-user: Fix mincore() with PROT_NONE Philippe Mathieu-Daudé
  2 siblings, 2 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2023-04-22 10:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: Thomas Weißschuh, Laurent Vivier

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



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

* Re: [PATCH v2 0/2] linux-user: Fix mincore() with PROT_NONE
  2023-04-22 10:03 [PATCH v2 0/2] linux-user: Fix mincore() with PROT_NONE Thomas Weißschuh
  2023-04-22 10:03 ` [PATCH v2 1/2] linux-user: Add new flag VERIFY_NONE Thomas Weißschuh
  2023-04-22 10:03 ` [PATCH v2 2/2] linux-user: Don't require PROT_READ for mincore Thomas Weißschuh
@ 2023-04-23 17:24 ` Philippe Mathieu-Daudé
  2 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-04-23 17:24 UTC (permalink / raw)
  To: Thomas Weißschuh, qemu-devel; +Cc: Laurent Vivier

On 22/4/23 12:03, Thomas Weißschuh wrote:
> The kernel does not require PROT_READ for addresses passed to mincore.
> 
> v1: https://lore.kernel.org/qemu-devel/20230416195103.607948-1-thomas@t-8ch.de/
> v1 -> v2:
> * Introduce symbolic flag VERIFY_NONE instead of hardcoding "0"
> 
> Thomas Weißschuh (2):
>    linux-user: Add new flag VERIFY_NONE
>    linux-user: Don't require PROT_READ for mincore
> 
>   linux-user/qemu.h    | 1 +
>   linux-user/syscall.c | 2 +-
>   2 files changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



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

* Re: [PATCH v2 1/2] linux-user: Add new flag VERIFY_NONE
  2023-04-22 10:03 ` [PATCH v2 1/2] linux-user: Add new flag VERIFY_NONE Thomas Weißschuh
@ 2023-05-01 15:48   ` Laurent Vivier
  2023-05-01 15:54   ` Laurent Vivier
  1 sibling, 0 replies; 8+ messages in thread
From: Laurent Vivier @ 2023-05-01 15:48 UTC (permalink / raw)
  To: Thomas Weißschuh, qemu-devel

Le 22/04/2023 à 12:03, Thomas Weißschuh a écrit :
> This can be used to validate that an address range is mapped but without
> being readable or writable.
> 
> It will be used by an updated implementation of mincore().
> 
> Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
> ---
>   linux-user/qemu.h | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/linux-user/qemu.h b/linux-user/qemu.h
> index e2e93fbd1d5d..92f9f5af41c7 100644
> --- a/linux-user/qemu.h
> +++ b/linux-user/qemu.h
> @@ -168,6 +168,7 @@ abi_long do_brk(abi_ulong new_brk);
>   
>   /* user access */
>   
> +#define VERIFY_NONE  0
>   #define VERIFY_READ  PAGE_READ
>   #define VERIFY_WRITE (PAGE_READ | PAGE_WRITE)
>   

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



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

* Re: [PATCH v2 2/2] linux-user: Don't require PROT_READ for mincore
  2023-04-22 10:03 ` [PATCH v2 2/2] linux-user: Don't require PROT_READ for mincore Thomas Weißschuh
@ 2023-05-01 15:48   ` Laurent Vivier
  2023-05-01 15:54   ` Laurent Vivier
  1 sibling, 0 replies; 8+ messages in thread
From: Laurent Vivier @ 2023-05-01 15:48 UTC (permalink / raw)
  To: Thomas Weißschuh, qemu-devel

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>



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

* Re: [PATCH v2 1/2] linux-user: Add new flag VERIFY_NONE
  2023-04-22 10:03 ` [PATCH v2 1/2] linux-user: Add new flag VERIFY_NONE Thomas Weißschuh
  2023-05-01 15:48   ` Laurent Vivier
@ 2023-05-01 15:54   ` Laurent Vivier
  1 sibling, 0 replies; 8+ messages in thread
From: Laurent Vivier @ 2023-05-01 15:54 UTC (permalink / raw)
  To: Thomas Weißschuh, qemu-devel

Le 22/04/2023 à 12:03, Thomas Weißschuh a écrit :
> This can be used to validate that an address range is mapped but without
> being readable or writable.
> 
> It will be used by an updated implementation of mincore().
> 
> Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
> ---
>   linux-user/qemu.h | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/linux-user/qemu.h b/linux-user/qemu.h
> index e2e93fbd1d5d..92f9f5af41c7 100644
> --- a/linux-user/qemu.h
> +++ b/linux-user/qemu.h
> @@ -168,6 +168,7 @@ abi_long do_brk(abi_ulong new_brk);
>   
>   /* user access */
>   
> +#define VERIFY_NONE  0
>   #define VERIFY_READ  PAGE_READ
>   #define VERIFY_WRITE (PAGE_READ | PAGE_WRITE)
>   

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

Thanks,
Laurent



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

* Re: [PATCH v2 2/2] linux-user: Don't require PROT_READ for mincore
  2023-04-22 10:03 ` [PATCH v2 2/2] linux-user: Don't require PROT_READ for mincore Thomas Weißschuh
  2023-05-01 15:48   ` Laurent Vivier
@ 2023-05-01 15:54   ` Laurent Vivier
  1 sibling, 0 replies; 8+ messages in thread
From: Laurent Vivier @ 2023-05-01 15:54 UTC (permalink / raw)
  To: Thomas Weißschuh, qemu-devel

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


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

end of thread, other threads:[~2023-05-01 15:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-22 10:03 [PATCH v2 0/2] linux-user: Fix mincore() with PROT_NONE Thomas Weißschuh
2023-04-22 10:03 ` [PATCH v2 1/2] linux-user: Add new flag VERIFY_NONE Thomas Weißschuh
2023-05-01 15:48   ` Laurent Vivier
2023-05-01 15:54   ` Laurent Vivier
2023-04-22 10:03 ` [PATCH v2 2/2] linux-user: Don't require PROT_READ for mincore Thomas Weißschuh
2023-05-01 15:48   ` Laurent Vivier
2023-05-01 15:54   ` Laurent Vivier
2023-04-23 17:24 ` [PATCH v2 0/2] linux-user: Fix mincore() with PROT_NONE Philippe Mathieu-Daudé

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.