Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile-in clone3() crash fix even when the glibc version is < 2.34 #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions include/libsyscall_intercept_hook_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,29 @@ syscall_error_code(long result)
*/
int syscall_hook_in_process_allowed(void);

/*
* glibc has been using clone3() internally since commit d8ea0d0168b190b.
* Make sure recent versions of glibc work properly even when this library
* is built with older verions of glibc.
*/
#ifndef SYS_clone3
#define SYS_clone3 435
#include <linux/types.h>
struct clone_args {
__aligned_u64 flags;
__aligned_u64 pidfd;
__aligned_u64 child_tid;
__aligned_u64 parent_tid;
__aligned_u64 exit_signal;
__aligned_u64 stack;
__aligned_u64 stack_size;
__aligned_u64 tls;
__aligned_u64 set_tid;
__aligned_u64 set_tid_size;
__aligned_u64 cgroup;
};
#endif

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 2 additions & 6 deletions src/intercept.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,15 +679,11 @@ intercept_routine(struct context *context)
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 &&
} 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
} else
result = syscall_no_intercept(desc.nr,
desc.args[0],
desc.args[1],
Expand Down
4 changes: 1 addition & 3 deletions test/hook_test_clone_preload.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ hook(long syscall_number,

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

return 1;
}
Expand Down
4 changes: 2 additions & 2 deletions test/test_clone_thread_preload.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ hook(long syscall_number,
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