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): make security_socket_setsockopt not rely on sys_enter/exit #4224

Merged
merged 1 commit into from
Aug 12, 2024
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
20 changes: 8 additions & 12 deletions pkg/ebpf/c/tracee.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2815,22 +2815,18 @@ int BPF_KPROBE(trace_security_socket_setsockopt)
int level = (int) PT_REGS_PARM2(ctx);
int optname = (int) PT_REGS_PARM3(ctx);

// Load the arguments given to the setsockopt syscall (which eventually invokes this function)
syscall_data_t *sys = &p.task_info->syscall_data;
if (sys == NULL) {
return -1;
}

if (!p.task_info->syscall_traced)
return 0;

switch (sys->id) {
struct pt_regs *task_regs = get_current_task_pt_regs();
int sockfd;
u32 sockfd_addr;
switch (p.event->context.syscall) {
case SYSCALL_SETSOCKOPT:
save_to_submit_buf(&p.event->args_buf, (void *) &sys->args.args[0], sizeof(u32), 0);
sockfd = get_syscall_arg1(p.event->task, task_regs, false);
save_to_submit_buf(&p.event->args_buf, (void *) &sockfd, sizeof(u32), 0);
break;
#if defined(bpf_target_x86) // armhf makes use of SYSCALL_SETSOCKOPT
case SYSCALL_SOCKETCALL:
save_to_submit_buf(&p.event->args_buf, (void *) sys->args.args[1], sizeof(u32), 0);
sockfd_addr = get_syscall_arg2(p.event->task, task_regs, false);
save_to_submit_buf(&p.event->args_buf, (void *) sockfd_addr, sizeof(u32), 0);
geyslan marked this conversation as resolved.
Show resolved Hide resolved
break;
#endif
default:
Expand Down
4 changes: 0 additions & 4 deletions pkg/events/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -11688,10 +11688,6 @@ var CoreEvents = map[ID]Definition{
dependencies: Dependencies{
probes: []Probe{
{handle: probes.SecuritySocketSetsockopt, required: true},
{handle: probes.SyscallEnter__Internal, required: true},
},
tailCalls: []TailCall{
{"sys_enter_init_tail", "sys_enter_init", []uint32{uint32(Setsockopt)}},
},
},
sets: []string{"lsm_hooks", "net", "net_sock"},
Expand Down
Loading