linux-user: Fix mincore() with PROT_NONE
v2 cover linux-user: Fix mincore() with PROT_NONE
The kernel does not require PROT_READ for addresses passed to mincore.
v1: https://lore.kernel.org/qemu-devel/[email protected]/
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
Signature · 1 line
2.40.0
PATCH v2 1/2 linux-user: Add new flag VERIFY_NONE
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().
--- linux-user/qemu.h | 1 + 1 file changed, 1 insertion(+)
linux-user/qemu.h +1 -0
@@ -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)
Signature · 1 line
2.40.0
Re: [PATCH v2 1/2] linux-user: Add new flag VERIFY_NONE
Le 22/04/2023 à 12:03, Thomas Weißschuh a écrit :
Quoted 15 lines
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 <[email protected]>--- linux-user/qemu.h | 1 + 1 file changed, 1 insertion(+)linux-user/qemu.h +0
-0
linux-user/qemu.h abi_long do_brk(abi_ulong new_brk); · line 174
Quoted 7 lines
linux-user/qemu.h +1
-0@@ -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)
Laurent Vivier
AppliedRe: [PATCH v2 1/2] linux-user: Add new flag VERIFY_NONE
In reply to Thomas WeißschuhLe 22/04/2023 à 12:03, Thomas Weißschuh a écrit :
Quoted 15 lines
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 <[email protected]>--- linux-user/qemu.h | 1 + 1 file changed, 1 insertion(+)linux-user/qemu.h +0
-0
linux-user/qemu.h abi_long do_brk(abi_ulong new_brk); · line 174
Quoted 7 lines
linux-user/qemu.h +1
-0@@ -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
PATCH v2 2/2 linux-user: Don't require PROT_READ for mincore
In reply to Thomas WeißschuhThe 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
--- linux-user/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +1 -1
@@ -11897,7 +11897,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,#ifdef TARGET_NR_mincorecase 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 ; }
Signature · 1 line
2.40.0
Re: [PATCH v2 2/2] linux-user: Don't require PROT_READ for mincore
Le 22/04/2023 à 12:03, Thomas Weißschuh a écrit :
Quoted 29 lines
The kernel does not require
PROT_READfor addresses passed to mincore. For example the fincore(1) tool from util-linux usesPROT_NONEand 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 memoryWith this patch:
$ ./build/qemu-x86_64 /usr/bin/fincore /proc/self/exe RES PAGES SIZE FILE 24K 6 22.1K /proc/self/exeSigned-off-by Thomas Weißschuh <[email protected]>--- linux-user/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linux-user/syscall.c +0
-0
linux-user/syscall.c static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, · line 11903
Quoted 8 lines
linux-user/syscall.c +1
-1@@ -11897,7 +11897,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,#ifdef TARGET_NR_mincorecase 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 ; }
Laurent Vivier
AppliedRe: [PATCH v2 2/2] linux-user: Don't require PROT_READ for mincore
In reply to Thomas WeißschuhLe 22/04/2023 à 12:03, Thomas Weißschuh a écrit :
Quoted 29 lines
The kernel does not require
PROT_READfor addresses passed to mincore. For example the fincore(1) tool from util-linux usesPROT_NONEand 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 memoryWith this patch:
$ ./build/qemu-x86_64 /usr/bin/fincore /proc/self/exe RES PAGES SIZE FILE 24K 6 22.1K /proc/self/exeSigned-off-by Thomas Weißschuh <[email protected]>--- linux-user/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linux-user/syscall.c +0
-0
linux-user/syscall.c static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, · line 11903
Quoted 8 lines
linux-user/syscall.c +1
-1@@ -11897,7 +11897,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,#ifdef TARGET_NR_mincorecase 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
Quoted 6 lines · Thomas Weißschuh
The kernel does not require
PROT_READfor addresses passed to mincore.v1: https://lore.kernel.org/qemu-devel/[email protected]/
v1 -> v2:
* Introduce symbolic flagVERIFY_NONEinstead of hardcoding "0"
Quoted 7 lines
Thomas Weißschuh (2):
linux-user: Add new flagVERIFY_NONE
linux-user: Don't requirePROT_READfor mincorelinux-user/qemu.h | 1 + linux-user/syscall.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)