8000 add ctime to security_file_open and fix variable type by AsafEitani · Pull Request #1167 · aquasecurity/tracee · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add ctime to security_file_open and fix variable type #1167

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 < 8000 a class="Link--inTextBlock" href="https://docs.github.com/privacy" target="_blank">privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tracee-ebpf/tracee/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ var EventsIDToParams = map[int32][]external.ArgMeta{
CgroupMkdirEventID: {{Type: "u64", Name: "cgroup_id"}, {Type: "const char*", Name: "cgroup_path"}},
CgroupRmdirEventID: {{Type: "u64", Name: "cgroup_id"}, {Type: "const char*", Name: "cgroup_path"}},
SecurityBprmCheckEventID: {{Type: "const char*", Name: "pathname"}, {Type: "dev_t", Name: "dev"}, {Type: "unsigned long", Name: "inode"}},
SecurityFileOpenEventID: {{Type: "const char*", Name: "pathname"}, {Type: "int", Name: "flags"}, {Type: "dev_t", Name: "dev"}, {Type: "unsigned long", Name: "inode"}, {Type: "int", Name: "syscall"}},
SecurityFileOpenEventID: {{Type: "const char*", Name: "pathname"}, {Type: "int", Name: "flags"}, {Type: "dev_t", Name: "dev"}, {Type: "unsigned long", Name: "inode"}, {Type: "unsigned long", Name: "ctime"}, {Type: "int", Name: "syscall"}},
SecurityInodeUnlinkEventID: {{Type: "const char*", Name: "pathname"}},
SecuritySocketCreateEventID: {{Type: "int", Name: "family"}, {Type: "int", Name: "type"}, {Type: "int", Name: "protocol"}, {Type: "int", Name: "kern"}},
SecuritySocketListenEventID: {{Type: "int", Name: "sockfd"}, {Type: "struct sockaddr*", Name: "local_addr"}, {Type: "int", Name: "backlog"}},
Expand Down
10 changes: 6 additions & 4 deletions tracee-ebpf/tracee/tracee.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ static __always_inline unsigned long get_inode_nr_from_file(struct file *file)
return READ_KERN(f_inode->i_ino);
}

static __always_inline unsigned long get_ctime_nanosec_from_file(struct file *file)
static __always_inline u64 get_ctime_nanosec_from_file(struct file *file)
{
struct inode *f_inode = READ_KERN(file->f_inode);
struct timespec64 ts = READ_KERN(f_inode->i_ctime);
Expand Down Expand Up @@ -2457,7 +2457,7 @@ int tracepoint__sched__sched_process_exec(struct bpf_raw_tracepoint_args *ctx)
struct file* file = get_file_ptr_from_bprm(bprm);
dev_t s_dev = get_dev_from_file(file);
unsigned long inode_nr = get_inode_nr_from_file(file);
unsigned long ctime = get_ctime_nanosec_from_file(file);
u64 ctime = get_ctime_nanosec_from_file(file);

// bprm->mm is null at this point (set by begin_new_exec()), and task->mm is already initialized
struct mm_struct *mm = get_mm_from_task(task);
Expand Down Expand Up @@ -2487,7 +2487,7 @@ int tracepoint__sched__sched_process_exec(struct bpf_raw_tracepoint_args *ctx)
save_to_submit_buf(&data, &s_dev, sizeof(dev_t), 4);
save_to_submit_buf(&data, &inode_nr, sizeof(unsigned long), 5);
save_to_submit_buf(&data, &invoked_from_kernel, sizeof(int), 6);
save_to_submit_buf(&data, &ctime, sizeof(unsigned long), 7);
save_to_submit_buf(&data, &ctime, sizeof(u64), 7);

return events_perf_submit(&data, SCHED_PROCESS_EXEC, 0);
}
Expand Down Expand Up @@ -2684,15 +2684,17 @@ int BPF_KPROBE(trace_security_file_open)
dev_t s_dev = get_dev_from_file(file);
unsigned long inode_nr = get_inode_nr_from_file(file);
void *file_path = get_path_str(GET_FIELD_ADDR(file->f_path));
u64 ctime = get_ctime_nanosec_from_file(file);

save_str_to_buf(&data, file_path, 0);
save_to_submit_buf(&data, (void*)GET_FIELD_ADDR(file->f_flags), sizeof(int), 1);
save_to_submit_buf(&data, &s_dev, sizeof(dev_t), 2);
save_to_submit_buf(&data, &inode_nr, sizeof(unsigned long), 3);
save_to_submit_buf(&data, &ctime, sizeof(u64), 4);
if (get_config(CONFIG_SHOW_SYSCALL)) {
syscall_data_t *sys = bpf_map_lookup_elem(&syscall_data_map, &data.context.host_tid);
if (sys) {
save_to_submit_buf(&data, (void*)&sys->id, sizeof(int), 4);
save_to_submit_buf(&data, (void*)&sys->id, sizeof(int), 5);
}
}

Expand Down
0