Skip to contentSkip to conversation

linux-user: prctl follow-ups

PATCH In review Richard Henderson 3 participants 11 messages Jan 6, 2022 – Jan 8, 2022

lore
Share & tools
lore
#0 lore raw

cover linux-user: prctl follow-ups

Hi Laurent, as requested. I did all of the cap_task_prctl options, and fixed a few existing bugs with PR_GET_DEATHSIG.

r~

Richard Henderson (4):
linux-user: Do not special-case NULL for PR_GET_PDEATHSIG
linux-user: Map signal number in PR_GET_PDEATHSIG
linux-user: Implement PR_SET_PDEATHSIG
linux-user: Implement capability prctls

 linux-user/syscall.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/4 linux-user: Do not special-case NULL for PR_GET_PDEATHSIG

The kernel does not special-case arg2 != NULL, so
neither should we.

---
 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +1 -1
index ce9d64896c..e8f9e0643e 100644
@@ -6444,7 +6444,7 @@ static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2,
             int deathsig;
             ret = get_errno(prctl(PR_GET_PDEATHSIG, &deathsig,
                                   arg3, arg4, arg5));
-            if (!is_error(ret) && arg2 && put_user_s32(deathsig, arg2)) {
+            if (!is_error(ret) && put_user_s32(deathsig, arg2)) {
                 return -TARGET_EFAULT;
             }
             return ret;
Signature · 1 line
2.25.1
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] linux-user: Do not special-case NULL for PR_GET_PDEATHSIG

Le 06/01/2022 à 23:57, Richard Henderson a écrit :

Quoted 13 lines

The kernel does not special-case arg2 != NULL, so
neither should we.

---
  linux-user/syscall.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +0 -0
index ce9d64896c..e8f9e0643e 100644

linux-user/syscall.c static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2, · line 6450

Quoted 8 lines
linux-user/syscall.c +1 -1
@@ -6444,7 +6444,7 @@ static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2,
              int deathsig;
              ret = get_errno(prctl(PR_GET_PDEATHSIG, &deathsig,
                                    arg3, arg4, arg5));
-            if (!is_error(ret) && arg2 && put_user_s32(deathsig, arg2)) {
+            if (!is_error(ret) && put_user_s32(deathsig, arg2)) {
                  return -TARGET_EFAULT;
              }
              return ret;
Reviewed-by
#3 lore raw

Re: [PATCH 1/4] linux-user: Do not special-case NULL for PR_GET_PDEATHSIG

Le 08/01/2022 à 18:10, Laurent Vivier a écrit :

Quoted 9 lines

Le 06/01/2022 à 23:57, Richard Henderson a écrit :

Quoted 8 lines

The kernel does not special-case arg2 != NULL, so
neither should we.

---
  linux-user/syscall.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

linux-user/syscall.c static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2, · line 6450

Quoted 13 lines
linux-user/syscall.c +1 -1
index ce9d64896c..e8f9e0643e 100644
@@ -6444,7 +6444,7 @@ static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2,
               int deathsig;
               ret = get_errno(prctl(PR_GET_PDEATHSIG, &deathsig,
                                     arg3, arg4, arg5));
-            if (!is_error(ret) && arg2 && put_user_s32(deathsig, arg2)) {
+            if (!is_error(ret) && put_user_s32(deathsig, arg2)) {
                   return -TARGET_EFAULT;
               }
               return ret;
#4 lore raw

PATCH 2/4 linux-user: Map signal number in PR_GET_PDEATHSIG

In reply to Richard Henderson

Convert the host signal number to guest signal number before returning the value to the guest.

---
 linux-user/syscall.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux-user/syscall.c +2 -1
index e8f9e0643e..9eb2fb2bb2 100644
@@ -6444,7 +6444,8 @@ static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2,
             int deathsig;
             ret = get_errno(prctl(PR_GET_PDEATHSIG, &deathsig,
                                   arg3, arg4, arg5));
-            if (!is_error(ret) && put_user_s32(deathsig, arg2)) {
+            if (!is_error(ret) &&
+                put_user_s32(host_to_target_signal(deathsig), arg2)) {
                 return -TARGET_EFAULT;
             }
             return ret;
Signature · 1 line
2.25.1
#6 lore raw

PATCH 3/4 linux-user: Implement PR_SET_PDEATHSIG

In reply to Richard Henderson
---
 linux-user/syscall.c | 3 +++
 1 file changed, 3 insertions(+)
linux-user/syscall.c +3 -0
index 9eb2fb2bb2..8495f5e08e 100644
@@ -6450,6 +6450,9 @@ static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2,
             }
             return ret;
         }
+    case PR_SET_PDEATHSIG:
+        return get_errno(prctl(PR_SET_PDEATHSIG, target_to_host_signal(arg2),
+                               arg3, arg4, arg5));
     case PR_GET_NAME:
         {
             void *name = lock_user(VERIFY_WRITE, arg2, 16, 1);
Signature · 1 line
2.25.1
Reviewed-by on v1 3/4
#7 lore raw

Re: [PATCH 3/4] linux-user: Implement PR_SET_PDEATHSIG

Le 06/01/2022 à 23:57, Richard Henderson a écrit :

Quoted 10 lines
---
  linux-user/syscall.c | 3 +++
  1 file changed, 3 insertions(+)
linux-user/syscall.c +0 -0
index 9eb2fb2bb2..8495f5e08e 100644

linux-user/syscall.c static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2, · line 6458

Quoted 9 lines
linux-user/syscall.c +3 -0
@@ -6450,6 +6450,9 @@ static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2,
              }
              return ret;
          }
+    case PR_SET_PDEATHSIG:
+        return get_errno(prctl(PR_SET_PDEATHSIG, target_to_host_signal(arg2),
+                               arg3, arg4, arg5));
      case PR_GET_NAME:
          {
              void *name = lock_user(VERIFY_WRITE, arg2, 16, 1);
#8 lore raw

PATCH 4/4 linux-user: Implement capability prctls

In reply to Richard Henderson

This is PR_CAPBSET_READ, PR_CAPBSET_DROP and the "legacy" PR_CAP_AMBIENT PR_GET_SECUREBITS, PR_SET_SECUREBITS.

All of these arguments are integer values only, and do not require mapping of values between host and guest.

---
 linux-user/syscall.c | 5 +++++
 1 file changed, 5 insertions(+)
linux-user/syscall.c +5 -0
index 8495f5e08e..4711afaf8c 100644
@@ -6504,10 +6504,15 @@ static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2,
     case PR_SET_UNALIGN:
         return do_prctl_set_unalign(env, arg2);
 
+    case PR_CAP_AMBIENT:
+    case PR_CAPBSET_READ:
+    case PR_CAPBSET_DROP:
     case PR_GET_DUMPABLE:
     case PR_SET_DUMPABLE:
     case PR_GET_KEEPCAPS:
     case PR_SET_KEEPCAPS:
+    case PR_GET_SECUREBITS:
+    case PR_SET_SECUREBITS:
     case PR_GET_TIMING:
     case PR_SET_TIMING:
     case PR_GET_TIMERSLACK:
Signature · 1 line
2.25.1
Reviewed-by on v1 4/4
#9 lore raw

Re: [PATCH 4/4] linux-user: Implement capability prctls

Le 06/01/2022 à 23:57, Richard Henderson a écrit :

Quoted 21 lines

This is PR_CAPBSET_READ, PR_CAPBSET_DROP and the "legacy" PR_CAP_AMBIENT PR_GET_SECUREBITS, PR_SET_SECUREBITS.

All of these arguments are integer values only, and do not require mapping of values between host and guest.

---
  linux-user/syscall.c | 5 +++++
  1 file changed, 5 insertions(+)
linux-user/syscall.c +2 -0
index 8495f5e08e..4711afaf8c 100644
@@ -6504,10 +6504,15 @@ static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2,
      case PR_SET_UNALIGN:
          return do_prctl_set_unalign(env, arg2);
 
+    case PR_CAP_AMBIENT:
+    case PR_CAPBSET_READ:

linux-user/syscall.c static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2, · line 6518

Quoted 10 lines
linux-user/syscall.c +3 -0
+    case PR_CAPBSET_DROP:
      case PR_GET_DUMPABLE:
      case PR_SET_DUMPABLE:
      case PR_GET_KEEPCAPS:
      case PR_SET_KEEPCAPS:
+    case PR_GET_SECUREBITS:
+    case PR_SET_SECUREBITS:
      case PR_GET_TIMING:
      case PR_SET_TIMING:
      case PR_GET_TIMERSLACK:
#10 lore raw
In reply to Richard Henderson

Le 06/01/2022 à 23:57, Richard Henderson a écrit :

Quoted 5 lines

Hi Laurent, as requested. I did all of the cap_task_prctl options, and fixed a few existing bugs with PR_GET_DEATHSIG.

r~

Quoted 9 lines

Richard Henderson (4):
linux-user: Do not special-case NULL for PR_GET_PDEATHSIG
linux-user: Map signal number in PR_GET_PDEATHSIG
linux-user: Implement PR_SET_PDEATHSIG
linux-user: Implement capability prctls

  linux-user/syscall.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)

Series applied to my linux-user-for-7.0 branch.

Thanks,
Laurent