Skip to contentSkip to conversation

linux-user: check read permissions before how

PATCH Superseded Patrick Venture 2 participants 6 messages Jan 26, 2022

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 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

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
#1 lore raw

PATCH v2 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.

c.f. https://github.com/torvalds/linux/blob/9539ba4308ad5bdca6cb41c7b73cbb9f796dcdd7/kernel/signal.c#L3147

---
 linux-user/syscall.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
linux-user/syscall.c +7 -5
index 5950222a77..34bd819e38 100644
@@ -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
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] linux-user: rt_sigprocmask, check read perms first

Le 26/01/2022 à 18:58, Patrick Venture a écrit :

Quoted 9 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's AddressIsReadable() depends on this behavior.

c.f. https://github.com/torvalds/linux/blob/9539ba4308ad5bdca6cb41c7b73cbb9f796dcdd7/kernel/signal.c#L3147

but you must resend the patch: you are not the author, but you have to add your Signed-off-by. (and now you can add my reviewed-by)

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/SubmittingPatches?id=f6f94e2ab1b33f0082ac22d71f66385a60d8157f#n296

Thanks,
Laurent

Quoted 34 lines
---
  linux-user/syscall.c | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
linux-user/syscall.c +7 -5
index 5950222a77..34bd819e38 100644
@@ -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;
#3 lore raw

Re: [PATCH v2 1/2] linux-user: rt_sigprocmask, check read perms first

Quoted 13 lines · Laurent Vivier
Quoted 3 lines · Patrick Venture

From: Shu-Chun Weng <[email protected]>

Linux kernel does it this way (checks read permission before validating

how)

Quoted 4 lines

and the latest version of ABSL's AddressIsReadable() depends on this behavior.

c.f.

https://github.com/torvalds/linux/blob/9539ba4308ad5bdca6cb41c7b73cbb9f796dcdd7/kernel/signal.c#L3147

Quoted 2 lines
Quoted 8 lines

but you must resend the patch: you are not the author, but you have to add your Signed-off-by.
(and now you can add my reviewed-by)

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/SubmittingPatches?id=f6f94e2ab1b33f0082ac22d71f66385a60d8157f#n296

Thanks! I definitely forgot to sign the patches I wasn't the author -- but you're right and thanks for pointing me to the guide.

Quoted 45 lines

Thanks,
Laurent

linux-user/syscall.c static abi_long do_syscall1(void *cpu_env, int

Quoted 9 lines
---
  linux-user/syscall.c | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
linux-user/syscall.c +0 -0
index 5950222a77..34bd819e38 100644
@@ -9508,6 +9508,13 @@ static abi_long do_syscall1(void *cpu_env, int

num, abi_long arg1,

linux-user/syscall.c static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,

Quoted 4 lines
linux-user/syscall.c +1 -0
              }
 
              if (arg2) {
+                p = lock_user(VERIFY_READ, arg2,

sizeof(target_sigset_t), 1);

linux-user/syscall.c static abi_long do_syscall1(void *cpu_env, int

Quoted 10 lines
linux-user/syscall.c +6 -0
+                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,

linux-user/syscall.c static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,

Quoted 4 lines
linux-user/syscall.c +0 -1
                  default:
                      return -TARGET_EINVAL;
                  }
-                if (!(p = lock_user(VERIFY_READ, arg2,

sizeof(target_sigset_t), 1)))

Quoted 7 lines
linux-user/syscall.c +0 -4
-                    return -TARGET_EFAULT;
-                target_to_host_sigset(&set, p);
-                unlock_user(p, arg2, 0);
-                set_ptr = &set;
              } else {
                  how = 0;
                  set_ptr = NULL;
#4 lore raw

PATCH v2 2/2 linux-user: sigprocmask check read perms first

In reply to Patrick Venture

Linux 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
index 34bd819e38..210483d4e4 100644
@@ -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
Reviewed-by on v2 2/2
#5 lore raw

Re: [PATCH v2 2/2] linux-user: sigprocmask check read perms first

Le 26/01/2022 à 18:58, Patrick Venture a écrit :

Quoted 4 lines

Linux kernel now checks the read permissions before validating how

Quoted 34 lines
---
  linux-user/syscall.c | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
linux-user/syscall.c +7 -5
index 34bd819e38..210483d4e4 100644
@@ -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;