-
Notifications
You must be signed in to change notification settings - Fork 4
ROX-30258: Track file ownership changes #156
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
Changes from 5 commits
8fb3a4b
29b8c6e
dc4e601
16cc780
b3e20ca
b381565
22dcedb
615b751
678033e
f591a99
c3ca7c4
0fb43a3
9091d76
576e81d
9774830
fc392f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -173,3 +173,58 @@ int BPF_PROG(trace_path_chmod, struct path* path, umode_t mode) { | |
|
|
||
| return 0; | ||
| } | ||
|
|
||
| SEC("lsm/path_chown") | ||
| int BPF_PROG(trace_path_chown, struct path* path, unsigned long long uid, unsigned long long gid) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] It'd be nice to have a small comment here explaining why uid and gid are
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a comment in b381565 . I hope it makes sense.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's fine, maybe we can mention the verifier does not allow struct types as arguments, so we do this instead. |
||
| struct metrics_t* m = get_metrics(); | ||
| if (m == NULL) { | ||
| return 0; | ||
| } | ||
|
|
||
| m->path_chown.total++; | ||
|
|
||
| struct bound_path_t* bound_path = NULL; | ||
| if (path_hooks_support_bpf_d_path) { | ||
| bound_path = path_read(path); | ||
| } else { | ||
| bound_path = path_read_no_d_path(path); | ||
| } | ||
|
|
||
| if (bound_path == NULL) { | ||
| bpf_printk("Failed to read path"); | ||
| m->path_chown.error++; | ||
| return 0; | ||
| } | ||
|
|
||
| inode_key_t inode_key = inode_to_key(path->dentry->d_inode); | ||
| const inode_value_t* inode = inode_get(&inode_key); | ||
|
|
||
| switch (inode_is_monitored(inode)) { | ||
| case NOT_MONITORED: | ||
| if (!is_monitored(bound_path)) { | ||
| m->path_chown.ignored++; | ||
| return 0; | ||
| } | ||
| break; | ||
|
|
||
| case MONITORED: | ||
| break; | ||
| } | ||
|
|
||
| struct dentry* d = BPF_CORE_READ(path, dentry); | ||
| kuid_t kuid = BPF_CORE_READ(d, d_inode, i_uid); | ||
| kgid_t kgid = BPF_CORE_READ(d, d_inode, i_gid); | ||
| unsigned long long old_uid = BPF_CORE_READ(&kuid, val); | ||
| unsigned long long old_gid = BPF_CORE_READ(&kgid, val); | ||
|
Molter73 marked this conversation as resolved.
Outdated
|
||
|
|
||
| submit_owner_event(&m->path_chown, | ||
| bound_path->path, | ||
| &inode_key, | ||
| uid, | ||
| gid, | ||
| old_uid, | ||
| old_gid, | ||
| path_hooks_support_bpf_d_path); | ||
|
|
||
| return 0; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.