From: Michalis Pappas Date: Mon, 25 Nov 2024 11:46:17 +0000 (+0100) Subject: lib/syscall-shim: Do not dereference optional clone() parameters X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=4f027f614c818cf9826ef6274faf0f60e3b07531;p=unikraft%2Funikraft.git lib/syscall-shim: Do not dereference optional clone() parameters 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 Approved-by: Sergiu Moga Reviewed-by: Sergiu Moga GitHub-Closes: #1564 --- diff --git a/lib/syscall_shim/uk_prsyscall.c b/lib/syscall_shim/uk_prsyscall.c index 47b7ec05e..09b95dbd5 100644 --- a/lib/syscall_shim/uk_prsyscall.c +++ b/lib/syscall_shim/uk_prsyscall.c @@ -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 */