Skip to contentSkip to conversation

linux-user: fix pidfd_send_signal()

PATCH Applied Laurent Vivier 2 participants 3 messages Oct 5, 2022 – Oct 21, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: fix pidfd_send_signal()

According to pidfd_send_signal(2), info argument can be a NULL pointer. Fix strace to correctly manage ending comma in parameters.

Fixes cc054c6f13 ("linux-user: Add pidfd_open(), pidfd_send_signal() and pidfd_getfd() syscalls")
cc Helge Deller <[email protected]>
---
 linux-user/strace.c  |  4 ++--
 linux-user/syscall.c | 19 ++++++++++++-------
 2 files changed, 14 insertions(+), 9 deletions(-)
linux-user/strace.c +2 -2
index 37bc96df9bb6..86c081c83f74 100644
@@ -3383,10 +3383,10 @@ print_pidfd_send_signal(CPUArchState *cpu_env, const struct syscallname *name,
 
         unlock_user(p, arg2, 0);
     } else {
-        print_pointer(arg2, 1);
+        print_pointer(arg2, 0);
     }
 
-    print_raw_param("%u", arg3, 0);
+    print_raw_param("%u", arg3, 1);
     print_syscall_epilogue(name);
 }
 #endif
linux-user/syscall.c +12 -7
index 2e954d8dbd9e..b1493917ee07 100644
@@ -8679,16 +8679,21 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
 #if defined(__NR_pidfd_send_signal) && defined(TARGET_NR_pidfd_send_signal)
     case TARGET_NR_pidfd_send_signal:
         {
-            siginfo_t uinfo;
+            siginfo_t uinfo, *puinfo;
 
-            p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
-            if (!p) {
-                return -TARGET_EFAULT;
+            if (arg3) {
+                p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
+                if (!p) {
+                    return -TARGET_EFAULT;
+                 }
+                 target_to_host_siginfo(&uinfo, p);
+                 unlock_user(p, arg3, 0);
+                 puinfo = &uinfo;
+            } else {
+                 puinfo = NULL;
             }
-            target_to_host_siginfo(&uinfo, p);
-            unlock_user(p, arg3, 0);
             ret = get_errno(pidfd_send_signal(arg1, target_to_host_signal(arg2),
-                &uinfo, arg4));
+                                              puinfo, arg4));
         }
         return ret;
 #endif
Signature · 1 line
2.37.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Laurent Vivier

According to pidfd_send_signal(2), info argument can be a NULL pointer. Fix strace to correctly manage ending comma in parameters.

Fixes cc054c6f13 ("linux-user: Add pidfd_open(), pidfd_send_signal() and pidfd_getfd() syscalls")
cc Helge Deller <[email protected]>
Quoted 55 lines
---
  linux-user/strace.c  |  4 ++--
  linux-user/syscall.c | 19 ++++++++++++-------
  2 files changed, 14 insertions(+), 9 deletions(-)
linux-user/strace.c +2 -2
index 37bc96df9bb6..86c081c83f74 100644
@@ -3383,10 +3383,10 @@ print_pidfd_send_signal(CPUArchState *cpu_env, const struct syscallname *name,
 
          unlock_user(p, arg2, 0);
      } else {
-        print_pointer(arg2, 1);
+        print_pointer(arg2, 0);
      }
 
-    print_raw_param("%u", arg3, 0);
+    print_raw_param("%u", arg3, 1);
      print_syscall_epilogue(name);
  }
  #endif
linux-user/syscall.c +12 -7
index 2e954d8dbd9e..b1493917ee07 100644
@@ -8679,16 +8679,21 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
  #if defined(__NR_pidfd_send_signal) && defined(TARGET_NR_pidfd_send_signal)
      case TARGET_NR_pidfd_send_signal:
          {
-            siginfo_t uinfo;
+            siginfo_t uinfo, *puinfo;
 
-            p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
-            if (!p) {
-                return -TARGET_EFAULT;
+            if (arg3) {
+                p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
+                if (!p) {
+                    return -TARGET_EFAULT;
+                 }
+                 target_to_host_siginfo(&uinfo, p);
+                 unlock_user(p, arg3, 0);
+                 puinfo = &uinfo;
+            } else {
+                 puinfo = NULL;
              }
-            target_to_host_siginfo(&uinfo, p);
-            unlock_user(p, arg3, 0);
              ret = get_errno(pidfd_send_signal(arg1, target_to_host_signal(arg2),
-                &uinfo, arg4));
+                                              puinfo, arg4));
          }
          return ret;
  #endif
author Applied
#2 lore raw
In reply to Laurent Vivier

Le 05/10/2022 à 18:38, Laurent Vivier a écrit :

Quoted 51 lines

According to pidfd_send_signal(2), info argument can be a NULL pointer. Fix strace to correctly manage ending comma in parameters.

Fixes cc054c6f13 ("linux-user: Add pidfd_open(), pidfd_send_signal() and pidfd_getfd() syscalls")
cc Helge Deller <[email protected]>
---
  linux-user/strace.c  |  4 ++--
  linux-user/syscall.c | 19 ++++++++++++-------
  2 files changed, 14 insertions(+), 9 deletions(-)
linux-user/strace.c +2 -2
index 37bc96df9bb6..86c081c83f74 100644
@@ -3383,10 +3383,10 @@ print_pidfd_send_signal(CPUArchState *cpu_env, const struct syscallname *name,
 
          unlock_user(p, arg2, 0);
      } else {
-        print_pointer(arg2, 1);
+        print_pointer(arg2, 0);
      }
 
-    print_raw_param("%u", arg3, 0);
+    print_raw_param("%u", arg3, 1);
      print_syscall_epilogue(name);
  }
  #endif
linux-user/syscall.c +10 -4
index 2e954d8dbd9e..b1493917ee07 100644
@@ -8679,16 +8679,21 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
  #if defined(__NR_pidfd_send_signal) && defined(TARGET_NR_pidfd_send_signal)
      case TARGET_NR_pidfd_send_signal:
          {
-            siginfo_t uinfo;
+            siginfo_t uinfo, *puinfo;
 
-            p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
-            if (!p) {
-                return -TARGET_EFAULT;
+            if (arg3) {
+                p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
+                if (!p) {
+                    return -TARGET_EFAULT;
+                 }
+                 target_to_host_siginfo(&uinfo, p);
+                 unlock_user(p, arg3, 0);
+                 puinfo = &uinfo;
+            } else {

linux-user/syscall.c static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, · line 8699

Quoted 10 lines
linux-user/syscall.c +2 -3
+                 puinfo = NULL;
              }
-            target_to_host_siginfo(&uinfo, p);
-            unlock_user(p, arg3, 0);
              ret = get_errno(pidfd_send_signal(arg1, target_to_host_signal(arg2),
-                &uinfo, arg4));
+                                              puinfo, arg4));
          }
          return ret;
  #endif

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

Thanks,
Laurent