-
Notifications
You must be signed in to change notification settings - Fork 431
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(events): add stack_pivot event #4403
Conversation
c8de2ac
to
b578701
Compare
9c9abd0
to
b10db98
Compare
pkg/ebpf/c/tracee.bpf.c
Outdated
const char *vma_type_str = get_vma_type_str(get_vma_type(task, vma)); | ||
unsigned long vma_start = BPF_CORE_READ(vma, vm_start); | ||
unsigned long vma_size = BPF_CORE_READ(vma, vm_end) - vma_start; | ||
unsigned long vma_flags = BPF_CORE_READ(vma, vm_flags); | ||
|
||
switch (vma_type) { | ||
case VMA_STACK: | ||
vma_type_str = "main stack"; | ||
break; | ||
case VMA_THREAD_STACK: | ||
vma_type_str = "thread stack"; | ||
break; | ||
case VMA_HEAP: | ||
vma_type_str = "heap"; | ||
break; | ||
case VMA_GOLANG_HEAP: | ||
// Goroutine stacks are allocated on the golang heap | ||
vma_type_str = "golang heap/stack"; | ||
break; | ||
case VMA_ANON: | ||
vma_type_str = "anonymous"; | ||
break; | ||
case VMA_VDSO: | ||
vma_type_str = "vdso"; | ||
break; | ||
default: | ||
vma_type_str = "unknown"; | ||
break; | ||
} | ||
save_to_submit_buf(&p.event->args_buf, &syscall, sizeof(syscall), 0); | ||
save_to_submit_buf(&p.event->args_buf, &ip, sizeof(ip), 1); | ||
save_str_to_buf(&p.event->args_buf, (void *) vma_type_str, 2); | ||
save_to_submit_buf(&p.event->args_buf, &vma_start, sizeof(vma_start), 3); | ||
save_to_submit_buf(&p.event->args_buf, &vma_size, sizeof(vma_size), 4); | ||
save_to_submit_buf(&p.event->args_buf, &vma_flags, sizeof(vma_flags), 5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your commits are mixing stack_pivot and suspicious_syscalls events.
This commit states it adds the stack pivot event, however, it also modifies logic of the suspicious syscall event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing I changed is moving the logic to get vma_type_str
into a separate function (because it's used by check_stack_pivot
as well).
912719f
to
8e06ee3
Compare
Convert `check_syscall_source` to use this probe instead of having a dedicated probe. The attachment mechansim is also generic and supports the registration of future syscall checkers.
Golang heaps can be determined by a pattern in the address, dictated by address hints supplied to mmap while allocating memory for them. Thread stacks can be identified by tracking the stack VMA for all newly created threads.
This event detects usage of the stack pivot technique used during ROP exploits by checking the user's stack pointer at selected syscalls. If the stack pointer does not point to the stack, an event is triggered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Closes #4404
1. Explain what the PR does
Add
stack_pivot
event, which detects usage of the stack pivoting technique as part of a ROP exploit, by monitoring selected syscalls and verifying the location of the stack pointer.2. Explain how to test it
Run tracee as follows:
Compile and run the tester program:
After 15 seconds a stack pivot event should be triggered.
3. Other comments
Like
suspicious_syscall_source
, this event makes use of event parameters to determine which syscalls should be monitored. The new probe group created forsuspicious_syscall_source
was made generic for "syscall checker" events, and each time a probe is triggered only the "checkers" which selected that syscall are run.