-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add library policy for BPF auditing. Signed-off-by: John Fastabend <[email protected]>
- Loading branch information
Showing
2 changed files
with
92 additions
and
27 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 |
---|---|---|
@@ -1,29 +1,93 @@ | ||
apiVersion: cilium.io/v1alpha1 | ||
kind: TracingPolicy | ||
metadata: | ||
name: "bpf" | ||
name: "bpf-library-policy" | ||
spec: | ||
kprobes: | ||
# Bpf verifier check during program loads | ||
# int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr) | ||
- call: "bpf_check" | ||
syscall: false | ||
args: | ||
- index: 1 | ||
type: "bpf_attr" | ||
# First step of kprobe attach process: open perf event | ||
# int security_perf_event_alloc(struct perf_event *event) | ||
- call: "security_perf_event_alloc" | ||
syscall: false | ||
args: | ||
- index: 0 | ||
type: "perf_event" | ||
# Second step of kprobe attach process: attach bpf program to perf event: todo | ||
# Called during bpf map create | ||
# int security_bpf_map_alloc(struct bpf_map *map) | ||
- call: "security_bpf_map_alloc" | ||
syscall: false | ||
args: | ||
- index: 0 | ||
type: "bpf_map" | ||
# Bpf map lookups/updates: todo | ||
kprobes: | ||
- call: "bpf_check" | ||
syscall: false | ||
args: | ||
- index: 1 | ||
type: "bpf_attr" | ||
- call: "security_perf_event_alloc" | ||
syscall: false | ||
args: | ||
- index: 0 | ||
type: "perf_event" | ||
- call: "security_bpf_map_alloc" | ||
syscall: false | ||
args: | ||
- index: 0 | ||
type: "bpf_map" | ||
- call: "security_file_permission" | ||
syscall: false | ||
return: true | ||
args: | ||
- index: 0 | ||
type: "file" # (struct file *) used for getting the path | ||
- index: 1 | ||
type: "int" # 0x04 is MAY_READ, 0x02 is MAY_WRITE | ||
returnArg: | ||
index: 0 | ||
type: "int" | ||
returnArgAction: "Post" | ||
selectors: | ||
- matchArgs: | ||
- index: 0 | ||
operator: "Prefix" | ||
values: | ||
- "/sys/fs/bpf" # Reads to BPFFS | ||
- index: 1 | ||
operator: "Equal" | ||
values: | ||
- "4" # MAY_READ | ||
- matchArgs: | ||
- index: 0 | ||
operator: "Prefix" | ||
values: | ||
- "/sys/fs/bpf" # Reads to BPFFS | ||
- index: 1 | ||
operator: "Equal" | ||
values: | ||
- "2" # MAY_WRITE | ||
- call: "security_mmap_file" | ||
syscall: false | ||
return: true | ||
args: | ||
- index: 0 | ||
type: "file" # (struct file *) used for getting the path | ||
- index: 1 | ||
type: "uint32" # the prot flags PROT_READ(0x01), PROT_WRITE(0x02), PROT_EXEC(0x04) | ||
- index: 2 | ||
type: "uint32" # the mmap flags (i.e. MAP_SHARED, ...) | ||
returnArg: | ||
index: 0 | ||
type: "int" | ||
returnArgAction: "Post" | ||
selectors: | ||
- matchArgs: | ||
- index: 0 | ||
operator: "Prefix" | ||
values: | ||
- "/sys/fs/bpf" # Reads to BPFFS | ||
- index: 1 | ||
operator: "Equal" | ||
values: | ||
- "1" # MAY_READ | ||
- index: 2 | ||
operator: "Mask" | ||
values: | ||
- "1" # MAP_SHARED | ||
- matchArgs: | ||
- index: 0 | ||
operator: "Prefix" | ||
values: | ||
- "/sys/fs/bpf" # Reads to BPFFS | ||
- index: 1 | ||
operator: "Mask" | ||
values: | ||
- "2" # PROT_WRITE | ||
- index: 2 | ||
operator: "Mask" | ||
values: | ||
- "1" # MAP_SHARED |