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

feat(ebpf): remove sys_enter/exit dependency from security_socket_con… #4220

Merged
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
27 changes: 11 additions & 16 deletions pkg/ebpf/c/tracee.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2608,31 +2608,26 @@ int BPF_KPROBE(trace_security_socket_connect)
return 0;
}

// Load args given to the syscall that invoked this function.
syscall_data_t *sys = &p.task_info->syscall_data;
if (!p.task_info->syscall_traced)
return 0;

// Reduce line cols by having a few temp pointers.
int (*stsb)(args_buffer_t *, void *, u32, u8) = save_to_submit_buf;
void *args_buf = &p.event->args_buf;
void *to = (void *) &sys->args.args[0];

if (is_x86_compat(p.event->task)) // only i386 binaries uses socketcall
to = (void *) sys->args.args[1];

// Save the socket fd, depending on the syscall.
switch (sys->id) {
struct pt_regs *task_regs = get_current_task_pt_regs();
int sockfd;
void *arr_addr;
switch (p.event->context.syscall) {
case SYSCALL_CONNECT:
sockfd = get_syscall_arg1(p.event->task, task_regs, false);
stsb(args_buf, &sockfd, sizeof(int), 0);
break;
case SYSCALL_SOCKETCALL:
arr_addr = (void *) get_syscall_arg2(p.event->task, task_regs, false);
bpf_probe_read_user(
&sockfd, sizeof(int), arr_addr); // fd is the first entry in the array
stsb(args_buf, &sockfd, sizeof(int), 0);
break;
default:
return 0;
}

// Save the socket fd argument to the event.
stsb(args_buf, to, sizeof(u32), 0);

// Save the socket type argument to the event.
stsb(args_buf, &type, sizeof(u32), 1);

Expand Down
4 changes: 0 additions & 4 deletions pkg/events/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -11608,10 +11608,6 @@ var CoreEvents = map[ID]Definition{
dependencies: Dependencies{
probes: []Probe{
{handle: probes.SecuritySocketConnect, required: true},
{handle: probes.SyscallEnter__Internal, required: true},
},
tailCalls: []TailCall{
{"sys_enter_init_tail", "sys_enter_init", []uint32{uint32(Connect)}},
},
},
sets: []string{"default", "lsm_hooks", "net", "net_sock"},
Expand Down
Loading