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

Commit fef1c49

Browse files
authored
Merge pull request #123 from en4bz/fix-clone3
Fix clone3 crash in glibc 2.34+
2 parents fe93e89 + b54c61e commit fef1c49

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/intercept.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include <sys/mman.h>
5353
#include <stdarg.h>
5454
#include <sys/auxv.h>
55+
#include <linux/sched.h>
5556

5657
#include "intercept.h"
5758
#include "intercept_log.h"
@@ -675,9 +676,17 @@ intercept_routine(struct context *context)
675676
* the clone_child_intercept_routine instead, executing
676677
* it on the new child threads stack, then returns to libc.
677678
*/
678-
if (desc.nr == SYS_clone && desc.args[1] != 0)
679+
if (desc.nr == SYS_clone && desc.args[1] != 0) {
679680
return (struct wrapper_ret){
680681
.rax = context->rax, .rdx = 2 };
682+
}
683+
#ifdef SYS_clone3
684+
else if (desc.nr == SYS_clone3 &&
685+
((struct clone_args *)desc.args[0])->stack != 0) {
686+
return (struct wrapper_ret){
687+
.rax = context->rax, .rdx = 2 };
688+
}
689+
#endif
681690
else
682691
result = syscall_no_intercept(desc.nr,
683692
desc.args[0],

test/hook_test_clone_preload.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include <string.h>
4343
#include <unistd.h>
4444
#include <syscall.h>
45-
45+
#include <linux/sched.h>
4646
#include "libsyscall_intercept_hook_point.h"
4747

4848
static int hook_counter;
@@ -65,6 +65,10 @@ hook(long syscall_number,
6565

6666
if (syscall_number == SYS_clone)
6767
hook_counter++;
68+
#ifdef SYS_clone3
69+
if (syscall_number == SYS_clone3)
70+
hook_counter++;
71+
#endif
6872

6973
return 1;
7074
}

test/test_clone_thread_preload.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <assert.h>
4848
#include <syscall.h>
4949
#include <stdio.h>
50+
#include <linux/sched.h>
5051

5152
static long flags = -1;
5253

@@ -80,9 +81,15 @@ hook(long syscall_number,
8081
* therefore the return value (the child's pid) can not be observed,
8182
* or modified.
8283
*/
83-
if (syscall_number == SYS_clone && (arg1 != 0))
84+
if (syscall_number == SYS_clone && (arg1 != 0)) {
8485
flags = arg0;
85-
86+
}
87+
#ifdef SYS_clone3
88+
if (syscall_number == SYS_clone3 &&
89+
((struct clone_args *)arg0)->stack != 0) {
90+
flags = arg0;
91+
}
92+
#endif
8693
return 1;
8794
}
8895

0 commit comments

Comments
 (0)