-
Notifications
You must be signed in to change notification settings - Fork 165
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
Update(prlimit
&setrlimit
): Add resource
arg for exit event
#1348
Conversation
Please double check driver/API_VERSION file. See versioning. /hold |
b8e9130
to
bef3ef4
Compare
Thank you for this, we will take a look soon! :) |
a630808
to
b5ccaca
Compare
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.
Thank you for this! Left some comments
@Biagio-Dipalma after this PR it would be possible to access the resource
field in setrlimit
and prlimit
syscalls through evt.arg.resource
. Does it sound good to you?
driver/SCHEMA_VERSION
Outdated
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.
Here we need a minor, so 2.13.0
.
Moreover, we need also a major bump in the API_VERSION
since we removed some old fillers
driver/bpf/fillers.h
Outdated
/* | ||
* Copy the user structure and extract cur and max | ||
*/ | ||
if(retval >= 0 || data->state->tail_ctx.evt_type == PPME_SYSCALL_SETRLIMIT_X) |
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.
if(retval >= 0 || data->state->tail_ctx.evt_type == PPME_SYSCALL_SETRLIMIT_X) | |
if(retval >= 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.
Same in the setrlimit
filler, now that we split them there is no more need for this if
driver/bpf/fillers.h
Outdated
max = -1; | ||
} | ||
|
||
/* Parameter 2: cur (type: PT_ERRNO) */ |
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.
/* Parameter 2: cur (type: PT_ERRNO) */ | |
/* Parameter 2: cur (type: PT_INT64) */ |
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.
Same in all other places
driver/bpf/fillers.h
Outdated
CHECK_RES(res); | ||
|
||
/* Parameter 4: resource (type: PT_ERRNO) */ | ||
unsigned long resource = bpf_syscall_get_argument(data, 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.
unsigned long resource = bpf_syscall_get_argument(data, 0); | |
uint32_t resource = bpf_syscall_get_argument(data, 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.
Same in all other drivers
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.
Have a doubt: #1348 (comment)
driver/ppm_fillers.c
Outdated
*/ | ||
if(retval >= 0 || args->event_type == PPME_SYSCALL_SETRLIMIT_X) |
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.
if(retval >= 0 || args->event_type == PPME_SYSCALL_SETRLIMIT_X) | |
if(retval >= 0) |
driver/ppm_fillers.c
Outdated
res = val_to_ring(args, newcur, 0, false, 0); | ||
CHECK_RES(res); | ||
CHECK_RES(res); |
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.
probably we can remove this, same below
@@ -68,6 +68,10 @@ int BPF_PROG(setrlimit_x, | |||
/* Parameter 3: max (type: PT_INT64)*/ | |||
ringbuf__store_s64(&ringbuf, rl.rlim_max); | |||
|
|||
/* Parameter 4: resource (type: PT_ENUMFLAGS8) */ | |||
unsigned long resource = extract__syscall_argument(regs, 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.
unsigned long resource = extract__syscall_argument(regs, 0); | |
uint32_t resource = extract__syscall_argument(regs, 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.
we could add a test both in setrlimit
and prlimit
in which we use a valid resource, for example RLIMIT_MEMLOCK
, and an invalid pointer to a struct rlimit
, so something like syscall(__NR_setrlimit, RLIMIT_MEMLOCK, NULL)
, WDYT?
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.
Yes, Sounds good!!
driver/bpf/fillers.h
Outdated
|
||
val = bpf_syscall_get_argument(data, 1); | ||
if(bpf_probe_read_user(&rl, sizeof(rl), (void *)val)) | ||
return PPM_FAILURE_INVALID_USER_MEMORY; |
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.
Instead of returning this code probably here we want to return cur = 0;
and max = 0;
See the modern bpf implementation. Same for the kmod
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 can do something like this
struct rlimit rl = {0};
val = bpf_syscall_get_argument(data, 1);
bpf_probe_read_user(&rl, sizeof(rl), (void *)val);
cur = rl.rlim_cur;
max = rl.rlim_max;
instead of returning PPM_FAILURE_INVALID_USER_MEMORY
if we fail in bpf_probe_read_user
Signed-off-by: rohith-raju <[email protected]>
Signed-off-by: rohith-raju <[email protected]>
Signed-off-by: rohith-raju <[email protected]>
Signed-off-by: rohith-raju <[email protected]>
Signed-off-by: rohith-raju <[email protected]>
Signed-off-by: Andrea Terzolo <[email protected]>
Signed-off-by: Andrea Terzolo <[email protected]>
The PR is great, thank you! |
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.
unfortunately, due to an inconsistency (#1283) we need a new major API version every time we add a new filler in the old probe
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.
@Andreagit97 Understood!!
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.
/approve
LGTM label has been added. Git tree hash: 1730c644404b29a94e3f7e48a796c58cf6938783
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: FedeDP, jasondellaluce, Rohith-Raju The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/unhold |
What type of PR is this?
/kind feature
Any specific area of the project related to this PR?
/area driver-kmod
/area driver-bpf
/area driver-modern-bpf
/area tests
What this PR does / why we need it:
Adding the
resource
argument to the exit events ofsetrlimit
andprlimit
will detect and provide useful alerts.Which issue(s) this PR fixes:
Fixes #1327
Special notes for your reviewer:
Does this PR introduce a user-facing change?: No