-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
Feature:Prevent segmentation fault & update new example:syscall_hijack #366
Conversation
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.
- Please split the example and fix into 2 different pr.
- All comments should be in English
- Avoid comment code without any explanation.
- Please add more tests if possible.
- The example should be added into ci for testing.
SEC("tracepoint/syscalls/sys_enter_open") | ||
int tracepoint__syscalls__sys_enter_open(struct trace_event_raw_sys_enter *ctx) | ||
{ | ||
// spdlog::info("tracepoint__syscalls__sys_enter_open"); |
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.
remove these comments
example/syscall_hijack/dummy.c
Outdated
printf("pending until input\n"); | ||
int c = getchar(); | ||
|
||
// 设置要执行的victim程序路径 |
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.
All comments should be in English
runtime/src/bpf_helper.cpp
Outdated
(size_t)(uint32_t)(size)); | ||
return 0; | ||
spdlog::debug("probe_read: dst={}, src={}, len={}", dst, ptr, size); |
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.
Use trace log here
runtime/src/bpf_helper.cpp
Outdated
uint64_t ret = 0; | ||
|
||
sa.sa_handler = segv_handler; // set signal handler | ||
sigemptyset(&sa.sa_mask); // clear signal set |
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.
Can we further optimize the code here?
runtime/src/bpf_helper.cpp
Outdated
uint64_t bpftime_probe_read(uint64_t dst, uint64_t size, uint64_t ptr, uint64_t, | ||
uint64_t) | ||
{ | ||
memcpy((void *)(uintptr_t)dst, (void *)(uintptr_t)ptr, | ||
if(size<=0) { |
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.
Please format your code with vendored clang format file
runtime/src/bpf_helper.cpp
Outdated
return 0; | ||
spdlog::debug("probe_read: dst={}, src={}, len={}", dst, ptr, size); | ||
} else { | ||
spdlog::error("probe_read: failed to read from src={}", ptr); |
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.
Please use macros to log, so we can control log level at compile time. For example, SPDLOG_ERROR(...)
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.
@yunwei37 suggested we use SPDLOG_TRACE here, I modify it by SPDLOG_TRACE. Thanks!
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.
No, for error here, you should use SPDLOG_ERROR.
For debug purposes, change to SPDLOG_DEBUG or SPDLOG_TRACE
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.
I got it, thanks.
runtime/src/bpf_helper.cpp
Outdated
sa.sa_flags = 0; | ||
|
||
if (sigaction(SIGSEGV, &sa, &old_sa) == -1) { | ||
perror("sigaction"); |
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.
We should print errors in logs, not to console
As comment below, I will split it into two individual PRs. |
Description
Fixes # (issue)
Type of change
How Has This Been Tested?
Test Configuration:
Checklist