-
Notifications
You must be signed in to change notification settings - Fork 4
Moves glob/wildcard matching into Fact. #323
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
base: main
Are you sure you want to change the base?
Changes from all commits
6c94e6b
1c6a8e4
7946408
c65e6a5
cf3a711
d960eca
a316313
caaf860
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,17 +46,21 @@ int BPF_PROG(trace_file_open, struct file* file) { | |
|
|
||
| inode_key_t inode_key = inode_to_key(file->f_inode); | ||
| const inode_value_t* inode = inode_get(&inode_key); | ||
| inode_key_t* inode_to_submit = &inode_key; | ||
| switch (inode_is_monitored(inode)) { | ||
| case NOT_MONITORED: | ||
| if (!is_monitored(path)) { | ||
| goto ignored; | ||
| } | ||
| // Matched by path prefix only, not by inode. | ||
| // Set inode to NULL so userspace knows to do glob matching. | ||
| inode_to_submit = NULL; | ||
| break; | ||
| case MONITORED: | ||
| break; | ||
| } | ||
|
|
||
| submit_event(&m->file_open, event_type, path->path, &inode_key, true); | ||
| submit_event(&m->file_open, event_type, path->path, inode_to_submit, true); | ||
|
Comment on lines
47
to
+63
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. I didn't want to use a map because the
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. Anyways, I don't want to block the PR on this, we can do it in a follow up. |
||
|
|
||
| return 0; | ||
|
|
||
|
|
@@ -100,13 +104,17 @@ int BPF_PROG(trace_path_unlink, struct path* dir, struct dentry* dentry) { | |
|
|
||
| inode_key_t inode_key = inode_to_key(dentry->d_inode); | ||
| const inode_value_t* inode = inode_get(&inode_key); | ||
| inode_key_t* inode_to_submit = &inode_key; | ||
|
|
||
| switch (inode_is_monitored(inode)) { | ||
| case NOT_MONITORED: | ||
| if (!is_monitored(path)) { | ||
| m->path_unlink.ignored++; | ||
| return 0; | ||
| } | ||
| // Matched by path prefix only, not by inode. | ||
| // Set inode to NULL so userspace knows to do glob matching. | ||
| inode_to_submit = NULL; | ||
| break; | ||
|
|
||
| case MONITORED: | ||
|
|
@@ -117,7 +125,7 @@ int BPF_PROG(trace_path_unlink, struct path* dir, struct dentry* dentry) { | |
| submit_event(&m->path_unlink, | ||
| FILE_ACTIVITY_UNLINK, | ||
| path->path, | ||
| &inode_key, | ||
| inode_to_submit, | ||
| path_hooks_support_bpf_d_path); | ||
| return 0; | ||
|
|
||
|
|
@@ -150,13 +158,17 @@ int BPF_PROG(trace_path_chmod, struct path* path, umode_t mode) { | |
|
|
||
| inode_key_t inode_key = inode_to_key(path->dentry->d_inode); | ||
| const inode_value_t* inode = inode_get(&inode_key); | ||
| inode_key_t* inode_to_submit = &inode_key; | ||
|
|
||
| switch (inode_is_monitored(inode)) { | ||
| case NOT_MONITORED: | ||
| if (!is_monitored(bound_path)) { | ||
| m->path_chmod.ignored++; | ||
| return 0; | ||
| } | ||
| // Matched by path prefix only, not by inode. | ||
| // Set inode to NULL so userspace knows to do glob matching. | ||
| inode_to_submit = NULL; | ||
| break; | ||
|
|
||
| case MONITORED: | ||
|
|
@@ -166,7 +178,7 @@ int BPF_PROG(trace_path_chmod, struct path* path, umode_t mode) { | |
| umode_t old_mode = BPF_CORE_READ(path, dentry, d_inode, i_mode); | ||
| submit_mode_event(&m->path_chmod, | ||
| bound_path->path, | ||
| &inode_key, | ||
| inode_to_submit, | ||
| mode, | ||
| old_mode, | ||
| path_hooks_support_bpf_d_path); | ||
|
|
@@ -201,13 +213,17 @@ int BPF_PROG(trace_path_chown, struct path* path, unsigned long long uid, unsign | |
|
|
||
| inode_key_t inode_key = inode_to_key(path->dentry->d_inode); | ||
| const inode_value_t* inode = inode_get(&inode_key); | ||
| inode_key_t* inode_to_submit = &inode_key; | ||
|
|
||
| switch (inode_is_monitored(inode)) { | ||
| case NOT_MONITORED: | ||
| if (!is_monitored(bound_path)) { | ||
| m->path_chown.ignored++; | ||
| return 0; | ||
| } | ||
| // Matched by path prefix only, not by inode. | ||
| // Set inode to NULL so userspace knows to do glob matching. | ||
| inode_to_submit = NULL; | ||
| break; | ||
|
|
||
| case MONITORED: | ||
|
|
@@ -220,7 +236,7 @@ int BPF_PROG(trace_path_chown, struct path* path, unsigned long long uid, unsign | |
|
|
||
| submit_ownership_event(&m->path_chown, | ||
| bound_path->path, | ||
| &inode_key, | ||
| inode_to_submit, | ||
| uid, | ||
| gid, | ||
| old_uid, | ||
|
|
||
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.
Thanks for this one!