Skip to content

feat(bpf-lsm): add tty information to telemetry #2029

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
38 changes: 25 additions & 13 deletions KubeArmor/BPF/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ char LICENSE[] SEC("license") = "Dual BSD/GPL";
#define AUDIT_POSTURE 140
#define BLOCK_POSTURE 141
#define CAPABLE_KEY 200
#define TTY_LEN 64

enum {
IPPROTO_ICMPV6 = 58
Expand Down Expand Up @@ -130,6 +131,7 @@ typedef struct {
s64 retval;

u8 comm[TASK_COMM_LEN];
u8 tty[TTY_LEN];

bufs_k data;
} event;
Expand Down Expand Up @@ -324,27 +326,37 @@ static inline void get_outer_key(struct outer_key *pokey,

static __always_inline u32 init_context(event *event_data) {
struct task_struct *task = (struct task_struct *)bpf_get_current_task();
u32 tgid, pid;
u32 uid = bpf_get_current_uid_gid() & 0xffffffff;

event_data->ts = bpf_ktime_get_ns();

event_data->pid_id = get_task_pid_ns_id(task);
event_data->mnt_id = get_task_mnt_ns_id(task);
event_data->host_ppid = get_task_ppid(task);
event_data->host_pid = bpf_get_current_pid_tgid() >> 32;
event_data->ppid = get_task_ns_ppid(task);
event_data->pid = get_task_ns_tgid(task);
event_data->uid = uid;

struct outer_key okey;
get_outer_key(&okey, task);
event_data->pid_id = okey.pid_ns;
event_data->mnt_id = okey.mnt_ns;

event_data->ppid = get_task_ppid(task);
event_data->pid = get_task_ns_tgid(task);
bpf_get_current_comm(&event_data->comm, sizeof(event_data->comm));

event_data->uid = bpf_get_current_uid_gid();
// Get TTY information
struct signal_struct *signal = READ_KERN(task->signal);
if (signal != NULL) {
struct tty_struct *tty = READ_KERN(signal->tty);
if (tty != NULL) {
bpf_probe_read_str(&event_data->tty, TTY_LEN, (void *)tty->name);
} else {
event_data->tty[0] = '\0';
}
} else {
event_data->tty[0] = '\0';
}

// Clearing array to avoid garbage values
__builtin_memset(event_data->comm, 0, sizeof(event_data->comm));
bpf_get_current_comm(&event_data->comm, sizeof(event_data->comm));
struct outer_key okey;
get_outer_key(&okey, task);

return 0;
return okey.pid_ns;
}


Expand Down