SeaBee
Loading...
Searching...
No Matches
seabee_log.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2#ifndef SEABEE_ENFORCE_LOG_H_
3#define SEABEE_ENFORCE_LOG_H_
8#include "logging.h"
9#include "seabee_utils.h"
10#include "shared_rust_types.h"
11
12static inline void log_sb_umount(enum LogLevel level, enum LogReason reason,
13 unsigned long target_dev)
14{
15 struct sb_umount_log *log;
16 log = log_buf(level, reason, EVENT_TYPE_SB_UMOUNT, sizeof(*log), NO_POL_ID);
17 if (log) {
19 bpf_ringbuf_submit(log, 0);
20 }
21}
22
23static inline void log_bpf_map(enum LogLevel level, enum LogReason reason,
24 struct bpf_map *map, unsigned int pol_id)
25{
26 struct bpf_map_log *log;
27 log = log_buf(level, reason, EVENT_TYPE_BPF_MAP, sizeof(*log), pol_id);
28 if (log) {
29 log->map_id = map->id;
30 BPF_CORE_READ_STR_INTO(&log->name, map, name);
31 bpf_ringbuf_submit(log, 0);
32 }
33}
34
35static inline void log_kernel_module_request(enum LogLevel level,
36 enum LogReason reason,
37 const unsigned char *kmod_name)
38{
39 struct kernel_module_request_log *log;
40 log = log_buf(level, reason, EVENT_TYPE_KERNEL_MODULE_REQUEST, sizeof(*log),
41 NO_POL_ID);
42 if (log) {
43 bpf_probe_read_str(log->kmod_name, sizeof(log->kmod_name), kmod_name);
44 bpf_ringbuf_submit(log, 0);
45 }
46}
47
48static inline void log_task_kill(enum LogLevel level, enum LogReason reason,
49 struct task_struct *t, int signum,
50 unsigned int pol_id)
51{
52 struct task_kill_log *log;
53 log = log_buf(level, reason, EVENT_TYPE_TASK_KILL, sizeof(*log), pol_id);
54 if (log) {
55 log->target_pid = t->tgid;
56 bpf_probe_read_str(log->target_comm, sizeof(log->target_comm), t->comm);
57 log->signum = signum;
58 bpf_ringbuf_submit(log, 0);
59 }
60}
61
62static inline void log_kernel_read_file(enum LogLevel level,
63 enum LogReason reason, unsigned int id,
64 const unsigned char *filename)
65{
66 struct kernel_read_file_log *log;
67 log = log_buf(level, reason, EVENT_TYPE_KERNEL_READ_FILE, sizeof(*log),
68 NO_POL_ID);
69 if (log) {
70 log->id = id;
71 bpf_probe_read_str(log->filename, sizeof(log->filename), filename);
72 bpf_ringbuf_submit(log, 0);
73 }
74}
75
76static inline void log_kernel_load_data(enum LogLevel level,
77 enum LogReason reason, unsigned int id)
78{
79 struct kernel_load_data_log *log;
80 log = log_buf(level, reason, EVENT_TYPE_KERNEL_LOAD_DATA, sizeof(*log),
81 NO_POL_ID);
82 if (log) {
83 log->id = id;
84 bpf_ringbuf_submit(log, 0);
85 }
86}
87
88static inline void log_ptrace_access_check(enum LogLevel level,
89 enum LogReason reason,
90 struct task_struct *tracee, u32 mode,
91 u32 pol_id)
92{
93 struct ptrace_access_check_log *log;
94 log = log_buf(level, reason, EVENT_TYPE_PTRACE_ACCESS_CHECK, sizeof(*log),
95 pol_id);
96 if (log) {
97 log->target_pid = tracee->tgid;
98 log->mode = mode;
99 bpf_probe_read_str(log->target_comm, sizeof(log->target_comm),
100 tracee->comm);
101 bpf_ringbuf_submit(log, 0);
102 }
103}
104
105static inline void log_inode_access(enum LogLevel level, enum LogReason reason,
106 enum InodeAction action,
107 const unsigned char *file_name,
108 unsigned int pol_id)
109{
110 struct inode_access_log *log;
111 log = log_buf(level, reason, EVENT_TYPE_FILE_ACCESS, sizeof(*log), pol_id);
112 if (log) {
113 log->action = action;
114 bpf_probe_read_str(log->name, sizeof(log->name), file_name);
115 bpf_ringbuf_submit(log, 0);
116 }
117}
118
119#endif // SEABEE_ENFORCE_LOG_H_
LogReason
Standard reasons as to why a log is being output.
Definition logging_types.h:36
InodeAction
Identifies a type of action taken on an inode.
Definition logging_types.h:71
LogLevel
Standard log levels indicating the severity of the message.
Definition logging_types.h:21
Log for a eBPF map access via a bpf() syscall.
Definition logging_types.h:124
unsigned char name[MAX_STR_LEN]
the name of the map
Definition logging_types.h:128
unsigned int map_id
id number of eBPF map being accessed
Definition logging_types.h:130
Log for various events that access a dentry or and inode(file_open, inode_permission)
Definition logging_types.h:186
unsigned int action
the action being taken on the inode, alias for InodeAction
Definition logging_types.h:190
unsigned char name[MAX_STR_LEN]
the first 128 characters of file name, if known
Definition logging_types.h:192
Log for a kernel_load_data() LSM hook event.
Definition logging_types.h:165
unsigned int id
the type of data being loaded into the kernel
Definition logging_types.h:170
Log for a kernel_module_request() LSM hook event.
Definition logging_types.h:146
unsigned char kmod_name[MODULE_NAME_LEN]
the name of the kernel module being requested to load
Definition logging_types.h:150
Log for a kernel_read_file() LSM hook event.
Definition logging_types.h:154
unsigned int id
the type of data being loaded into the kernel
Definition logging_types.h:159
unsigned char filename[MAX_STR_LEN]
the name of the file being loaded
Definition logging_types.h:161
Log for a ptrace_access_check() LSM hook event.
Definition logging_types.h:174
unsigned char target_comm[COMM_LEN]
same as /proc/{pid}/comm for traced process
Definition logging_types.h:182
int target_pid
The process ID to be traced.
Definition logging_types.h:178
unsigned int mode
The ptrace mode used.
Definition logging_types.h:180
Log a sb_umount() syscall.
Definition logging_types.h:116
unsigned long target_dev
device number of the superblock being unmounted
Definition logging_types.h:120
Log a task_kill() LSM hook event.
Definition logging_types.h:134
int target_pid
process id of the PID receiving the signal
Definition logging_types.h:140
int signum
id of the signal being sent
Definition logging_types.h:142
unsigned char target_comm[COMM_LEN]
same as /proc/{pid}/comm
Definition logging_types.h:138