linux-user: check read permissions before how
v3 cover linux-user: check read permissions before how
In sigprocmask check the read permissions first before checking the how.
This is done for both: TARGET_NR_sigprocmask and TARGET_NR_rt_sigprocmask
v3:
* Added missing signature from venture
v2:
* Update code style during code change
* Also update check order for TARGET_NR_sigprocmask
Patrick Venture (1):
linux-user: sigprocmask check read perms first
Shu-Chun Weng (1):
linux-user: rt_sigprocmask, check read perms first
linux-user/syscall.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
Signature · 1 line
2.35.0.rc0.227.g00780c9af4-goog
PATCH v3 1/2 linux-user: rt_sigprocmask, check read perms first
From: Shu-Chun Weng <[email protected]>
Linux kernel does it this way (checks read permission before validating how) and the latest version of ABSL's AddressIsReadable() depends on this behavior.
--- linux-user/syscall.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
linux-user/syscall.c +7 -5
@@ -9508,6 +9508,13 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, }if (arg2) { + p =lock_user (VERIFY_READ , arg2,sizeof (target_sigset_t),1 ); +if (!p) { +return -TARGET_EFAULT ; + } +target_to_host_sigset (&set, p); +unlock_user (p, arg2,0 ); + set_ptr = &set;switch (how) {case TARGET_SIG_BLOCK : how =SIG_BLOCK ;
@@ -9521,11 +9528,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,default :return -TARGET_EINVAL ; } -if (!(p =lock_user (VERIFY_READ , arg2,sizeof (target_sigset_t),1 ))) -return -TARGET_EFAULT ; -target_to_host_sigset (&set, p); -unlock_user (p, arg2,0 ); - set_ptr = &set; }else { how =0 ; set_ptr =NULL ;
Signature · 1 line
2.35.0.rc0.227.g00780c9af4-goog
Laurent Vivier
AppliedRe: [PATCH v3 1/2] linux-user: rt_sigprocmask, check read perms first
Le 26/01/2022 à 22:25, Patrick Venture a écrit :
Quoted 35 lines
From: Shu-Chun Weng <[email protected]>
Linux kernel does it this way (checks read permission before validating
how) and the latest version of ABSL'sAddressIsReadable()depends on this behavior.Reviewed-by Patrick Venture <[email protected]>Signed-off-by Shu-Chun Weng <[email protected]>Reviewed-by Laurent Vivier <[email protected]>Signed-off-by Patrick Venture <[email protected]>--- linux-user/syscall.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)linux-user/syscall.c +7
-0@@ -9508,6 +9508,13 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, }if (arg2) { + p =lock_user (VERIFY_READ , arg2,sizeof (target_sigset_t),1 ); +if (!p) { +return -TARGET_EFAULT ; + } +target_to_host_sigset (&set, p); +unlock_user (p, arg2,0 ); + set_ptr = &set;switch (how) {case TARGET_SIG_BLOCK : how =SIG_BLOCK ;@@ -9521,11 +9528,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,default :
linux-user/syscall.c static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, · line 9533
Quoted 10 lines
linux-user/syscall.c +0
-5return -TARGET_EINVAL ; } -if (!(p =lock_user (VERIFY_READ , arg2,sizeof (target_sigset_t),1 ))) -return -TARGET_EFAULT ; -target_to_host_sigset (&set, p); -unlock_user (p, arg2,0 ); - set_ptr = &set; }else { how =0 ; set_ptr =NULL ;
Applied to my linux-user-for-7.0 branch.
Thanks,
Laurent
PATCH v3 2/2 linux-user: sigprocmask check read perms first
In reply to Patrick VentureLinux kernel now checks the read permissions before validating how
--- linux-user/syscall.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
linux-user/syscall.c +7 -5
@@ -9465,6 +9465,13 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,int how;if (arg2) { + p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1)); +if (!p) { +return -TARGET_EFAULT ; + } +target_to_host_old_sigset (&set, p); +unlock_user (p, arg2,0 ); + set_ptr = &set;switch (arg1) {case TARGET_SIG_BLOCK : how =SIG_BLOCK ;
@@ -9478,11 +9485,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,default :return -TARGET_EINVAL ; } -if (!(p =lock_user (VERIFY_READ , arg2,sizeof (target_sigset_t),1 ))) -return -TARGET_EFAULT ; -target_to_host_old_sigset (&set, p); -unlock_user (p, arg2,0 ); - set_ptr = &set; }else { how =0 ; set_ptr =NULL ;
Signature · 1 line
2.35.0.rc0.227.g00780c9af4-goog
Laurent Vivier
AppliedRe: [PATCH v3 2/2] linux-user: sigprocmask check read perms first
Le 26/01/2022 à 22:25, Patrick Venture a écrit :
Quoted 29 lines
Linux kernel now checks the read permissions before validating
howSuggested-by Laurent Vivier <[email protected]>Signed-off-by Patrick Venture <[email protected]>Reviewed-by Laurent Vivier <[email protected]>--- linux-user/syscall.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)linux-user/syscall.c +7
-0@@ -9465,6 +9465,13 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,int how;if (arg2) { + p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1)); +if (!p) { +return -TARGET_EFAULT ; + } +target_to_host_old_sigset (&set, p); +unlock_user (p, arg2,0 ); + set_ptr = &set;switch (arg1) {case TARGET_SIG_BLOCK : how =SIG_BLOCK ;@@ -9478,11 +9485,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,default :
linux-user/syscall.c static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, · line 9490
Quoted 10 lines
linux-user/syscall.c +0
-5return -TARGET_EINVAL ; } -if (!(p =lock_user (VERIFY_READ , arg2,sizeof (target_sigset_t),1 ))) -return -TARGET_EFAULT ; -target_to_host_old_sigset (&set, p); -unlock_user (p, arg2,0 ); - set_ptr = &set; }else { how =0 ; set_ptr =NULL ;
Applied to my linux-user-for-7.0 branch.
Thanks,
Laurent