]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/syscall-shim: Do not dereference optional clone() parameters
authorMichalis Pappas <michalis@unikraft.io>
Mon, 25 Nov 2024 11:46:17 +0000 (12:46 +0100)
committerUnikraft Bot <monkey@unikraft.io>
Fri, 2 May 2025 13:39:15 +0000 (13:39 +0000)
The parent_tid parameter of clone() is used to instruct the kernel
where to store the child TID in parent's memory. Similarly, the
child_tid is used to instruct the kernel where to store the child
TID in the child's memory. Both parameters are optional, and are
interpreted conditionally to whether the CLONE_CHILD_SETTID and
CLONE_PARENT_SETTID flags are set, respectively.

Do not interpret these options as PT_REF, as the pointer will not
be valid if the caller does not set corresponding flags.

Checkpatch-Ignore: LONG_LINE
Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1564

lib/syscall_shim/uk_prsyscall.c

index 47b7ec05ed67a94dbc48373612eece7ca9bc6b3c..09b95dbd538c80c98cc21d83dfb99ba834aa96b3 100644 (file)
@@ -1220,21 +1220,39 @@ static void pr_syscall(struct uk_streambuf *sb, int fmtf,
 
 #ifdef HAVE_uk_syscall_clone
        case SYS_clone:
+               do {
+                       unsigned long pt_tid_parent_ref;
+                       unsigned long pt_tid_child_ref;
+                       unsigned long flags;
+
+                       flags = (unsigned long)va_arg(args, long);
+
+                       if (flags & CLONE_PARENT_SETTID)
+                               pt_tid_parent_ref = PT_VADDR | PT_REF;
+                       else
+                               pt_tid_parent_ref = PT_VADDR;
+
+                       if (flags & CLONE_CHILD_SETTID)
+                               pt_tid_child_ref = PT_VADDR | PT_REF;
+                       else
+                               pt_tid_child_ref = PT_VADDR;
+
 #if CONFIG_ARCH_X86_64
-               VPR_SYSCALL(sb, fmtf, syscall_num, args, rc >= 0,
-                           PT_CLONEFLAGS,
-                           PT_VADDR, /* sp */
-                           PT_TID | PT_REF, /* ref to parent tid */
-                           PT_TID | PT_REF, /* ref to child tid */
-                           PT_VADDR /* tlsp */);
+                       VPR_SYSCALL(sb, fmtf, syscall_num, args, rc >= 0,
+                                   PT_CLONEFLAGS,
+                                   PT_VADDR, /* sp */
+                                   pt_tid_parent_ref, /* ref to parent tid */
+                                   pt_tid_child_ref,  /* ref to child tid */
+                                   PT_VADDR /* tlsp */);
 #else /* !CONFIG_ARCH_X86_64 */
-               VPR_SYSCALL(sb, fmtf, syscall_num, args, rc >= 0,
-                           PT_CLONEFLAGS,
-                           PT_VADDR, /* sp */
-                           PT_TID | PT_REF, /* ref to parent tid */
-                           PT_VADDR, /* tlsp */
-                           PT_TID | PT_REF /* ref to child tid */);
+                       VPR_SYSCALL(sb, fmtf, syscall_num, args, rc >= 0,
+                                   PT_CLONEFLAGS,
+                                   PT_VADDR, /* sp */
+                                   pt_tid_parent_ref, /* ref to parent tid */
+                                   PT_VADDR, /* tlsp */
+                                   pt_tid_child_ref); /* ref to child tid */
 #endif /* !CONFIG_ARCH_X86_64 */
+               } while (0);
                PR_SYSRET(sb, fmtf, PT_TID, rc);
                break;
 #endif /* HAVE_uk_syscall_clone */