-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bpf: add bpf_execve_bprm_check program
This program allows to run at security_bprm_check and checks the file and its inode attached to bprm. This allows to detect if we are running a program that was deleted or is not linked on the filesystem. Final event result is: { "process_exec": { "process": { "exec_id": "OjI1MTAxMDY5MDQ2NDMxOjIxNjIwMQ==", "pid": 216201, "uid": 1000, "cwd": "/home/tixxdz/work/station/code/src/github.com/tixxdz/tetragon", "binary": "/proc/self/fd/3", "flags": "execve", "start_time": "2022-10-20T16:46:57.085974850Z", "auid": 1000, "parent_exec_id": "OjI1MTAxMDY1OTI5MjE2OjIxNjIwMQ==" "info": { "inode": { "deleted": true } } }, "parent": { "exec_id": "OjI1MTAxMDY1OTI5MjE2OjIxNjIwMQ==", "pid": 216201, "uid": 1000, "cwd": "/home/tixxdz/work/station/code/src/github.com/tixxdz/tetragon", "binary": "/usr/bin/memfdloader", "arguments": "/bin/true", "flags": "execve clone", "start_time": "2022-10-20T16:46:57.082858558Z", "auid": 1000, "parent_exec_id": "Ojc3NzY4MDAwMDAwMDo2MTMx", "refcnt": 2 }, }, "time": "2022-10-20T16:46:57.085975420Z" } The "process_exec.info.inode.deleted" field allows to predict if we are executing a file from a referenced fd that is not linked on the filesystem. Signed-off-by: Djalal Harouni <tixxdz@gmail.com>
- Loading branch information
Showing
4 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Copyright Authors of Cilium */ | ||
|
||
#include "vmlinux.h" | ||
#include "api.h" | ||
#include "bpf_tracing.h" | ||
|
||
#include "bpf_events.h" | ||
|
||
char _license[] __attribute__((section("license"), used)) = "GPL"; | ||
|
||
__attribute__((section("kprobe/security_bprm_check"), used)) int | ||
BPF_KPROBE(tg_kp_bprm_check, struct linux_binprm *bprm, int ret) | ||
{ | ||
__u32 pid, zero = 0; | ||
unsigned int links; | ||
struct execve_map_value *curr; | ||
struct execve_heap *heap; | ||
struct file *file; | ||
|
||
pid = (get_current_pid_tgid() >> 32); | ||
|
||
curr = execve_map_get(pid); | ||
if (!curr) | ||
return 0; | ||
|
||
heap = map_lookup_elem(&execve_heap, &zero); | ||
if (!heap) | ||
return 0; | ||
|
||
probe_read(&file, sizeof(file), _(&bprm->file)); | ||
links = BPF_CORE_READ(file, f_path.dentry, d_inode, __i_nlink); | ||
heap->info.inode.i_nlink = links; | ||
heap->info.inode.initialized = 1; | ||
|
||
execve_info_map_set(pid, &heap->info); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters