Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Fix clone3 crash in glibc 2.34+ #123

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/intercept.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include <sys/mman.h>
#include <stdarg.h>
#include <sys/auxv.h>
#include <linux/sched.h>

#include "intercept.h"
#include "intercept_log.h"
Expand Down Expand Up @@ -675,9 +676,17 @@ intercept_routine(struct context *context)
* the clone_child_intercept_routine instead, executing
* it on the new child threads stack, then returns to libc.
*/
if (desc.nr == SYS_clone && desc.args[1] != 0)
if (desc.nr == SYS_clone && desc.args[1] != 0) {
return (struct wrapper_ret){
.rax = context->rax, .rdx = 2 };
}
#ifdef SYS_clone3
else if (desc.nr == SYS_clone3 &&
((struct clone_args *)desc.args[0])->stack != 0) {
return (struct wrapper_ret){
.rax = context->rax, .rdx = 2 };
}
#endif
else
result = syscall_no_intercept(desc.nr,
desc.args[0],
Expand Down
6 changes: 5 additions & 1 deletion test/hook_test_clone_preload.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include <string.h>
#include <unistd.h>
#include <syscall.h>

#include <linux/sched.h>
#include "libsyscall_intercept_hook_point.h"

static int hook_counter;
Expand All @@ -65,6 +65,10 @@ hook(long syscall_number,

if (syscall_number == SYS_clone)
hook_counter++;
#ifdef SYS_clone3
if (syscall_number == SYS_clone3)
hook_counter++;
#endif

return 1;
}
Expand Down
11 changes: 9 additions & 2 deletions test/test_clone_thread_preload.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <assert.h>
#include <syscall.h>
#include <stdio.h>
#include <linux/sched.h>

static long flags = -1;

Expand Down Expand Up @@ -80,9 +81,15 @@ hook(long syscall_number,
* therefore the return value (the child's pid) can not be observed,
* or modified.
*/
if (syscall_number == SYS_clone && (arg1 != 0))
if (syscall_number == SYS_clone && (arg1 != 0)) {
flags = arg0;

}
#ifdef SYS_clone3
if (syscall_number == SYS_clone3 &&
((struct clone_args *)arg0)->stack != 0) {
flags = arg0;
}
#endif
return 1;
}

Expand Down