Skip to content

Commit a7852fc

Browse files
OriGlassmanrandomname21
authored andcommitted
feat(ebpf): make mem_prot_alert not rely on sys_enter/exit
1 parent b55f889 commit a7852fc

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

pkg/ebpf/c/tracee.bpf.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3420,18 +3420,16 @@ int BPF_KPROBE(trace_mmap_alert)
34203420
if (!evaluate_scope_filters(&p))
34213421
return 0;
34223422

3423-
// Load the arguments given to the mmap syscall (which eventually invokes this function)
3424-
syscall_data_t *sys = &p.task_info->syscall_data;
3425-
if (!p.task_info->syscall_traced || sys->id != SYSCALL_MMAP)
3423+
if (p.event->context.syscall != SYSCALL_MMAP)
34263424
return 0;
34273425

3428-
int prot = sys->args.args[2];
3429-
3426+
struct pt_regs *task_regs = get_current_task_pt_regs();
3427+
int prot = get_syscall_arg3(p.event->task, task_regs, false);
34303428
if ((prot & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
34313429
u32 alert = ALERT_MMAP_W_X;
3432-
int fd = sys->args.args[4];
3433-
void *addr = (void *) sys->args.args[0];
3434-
size_t len = sys->args.args[1];
3430+
void *addr = (void *) get_syscall_arg1(p.event->task, task_regs, false);
3431+
size_t len = get_syscall_arg2(p.event->task, task_regs, false);
3432+
int fd = get_syscall_arg5(p.event->task, task_regs, false);
34353433
int prev_prot = 0;
34363434
file_info_t file_info = {.pathname_p = NULL};
34373435
if (fd >= 0) {
@@ -3566,18 +3564,18 @@ int BPF_KPROBE(trace_security_file_mprotect)
35663564
if (!init_program_data(&p, ctx, SECURITY_FILE_MPROTECT))
35673565
return 0;
35683566

3569-
// Load the arguments given to the mprotect syscall (which eventually invokes this function)
3570-
syscall_data_t *sys = &p.task_info->syscall_data;
3571-
if (!p.task_info->syscall_traced ||
3572-
(sys->id != SYSCALL_MPROTECT && sys->id != SYSCALL_PKEY_MPROTECT))
3567+
if (p.event->context.syscall != SYSCALL_MPROTECT &&
3568+
p.event->context.syscall != SYSCALL_PKEY_MPROTECT)
35733569
return 0;
35743570

35753571
struct vm_area_struct *vma = (struct vm_area_struct *) PT_REGS_PARM1(ctx);
35763572
unsigned long reqprot = PT_REGS_PARM2(ctx);
35773573
unsigned long prev_prot = get_vma_flags(vma);
35783574
struct file *file = (struct file *) BPF_CORE_READ(vma, vm_file);
3579-
void *addr = (void *) sys->args.args[0];
3580-
size_t len = sys->args.args[1];
3575+
3576+
struct pt_regs *task_regs = get_current_task_pt_regs();
3577+
void *addr = (void *) get_syscall_arg1(p.event->task, task_regs, false);
3578+
size_t len = get_syscall_arg2(p.event->task, task_regs, false);
35813579

35823580
if (evaluate_scope_filters(&p)) {
35833581
file_info = get_file_info(file);
@@ -3589,8 +3587,8 @@ int BPF_KPROBE(trace_security_file_mprotect)
35893587
save_to_submit_buf(&p.event->args_buf, &addr, sizeof(void *), 4);
35903588
save_to_submit_buf(&p.event->args_buf, &len, sizeof(size_t), 5);
35913589

3592-
if (sys->id == SYSCALL_PKEY_MPROTECT) {
3593-
int pkey = sys->args.args[3];
3590+
if (p.event->context.syscall == SYSCALL_PKEY_MPROTECT) {
3591+
int pkey = get_syscall_arg4(p.event->task, task_regs, false);
35943592
save_to_submit_buf(&p.event->args_buf, &pkey, sizeof(int), 6);
35953593
}
35963594

pkg/events/core.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11347,14 +11347,6 @@ var CoreEvents = map[ID]Definition{
1134711347
probes: []Probe{
1134811348
{handle: probes.SecurityMmapAddr, required: true},
1134911349
{handle: probes.SecurityFileMProtect, required: true},
11350-
{handle: probes.SyscallEnter__Internal, required: true},
11351-
},
11352-
tailCalls: []TailCall{
11353-
{
11354-
"sys_enter_init_tail",
11355-
"sys_enter_init",
11356-
[]uint32{uint32(Mmap), uint32(Mprotect), uint32(PkeyMprotect)},
11357-
},
1135811350
},
1135911351
},
1136011352
sets: []string{},

0 commit comments

Comments
 (0)