Skip to content

fix: misalignment in execve_map #206

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

Merged
merged 2 commits into from
Jun 30, 2022
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
1 change: 1 addition & 0 deletions bpf/alignchecker/bpf_alignchecker.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ int main(void)

// from maps
DECLARE(struct, event, iter);
DECLARE(struct, msg_execve_key, iter);
DECLARE(struct, execve_map_value, iter);

return 0;
Expand Down
1 change: 1 addition & 0 deletions pkg/alignchecker/alignchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func CheckStructAlignments(path string) error {
// from perf_event_output
"msg_exit": {reflect.TypeOf(processapi.MsgExitEvent{})},
"msg_test": {reflect.TypeOf(testapi.MsgTestEvent{})},
"msg_execve_key": {reflect.TypeOf(processapi.MsgExecveKey{})},
"execve_map_value": {reflect.TypeOf(execvemap.ExecveValue{})},
}
return check.CheckStructAlignments(path, toCheck, true)
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/processapi/processapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ type MsgExec struct {
}

type MsgExecveKey struct {
Pid uint32
Pad uint32
Ktime uint64
Pid uint32 `align:"pid"`
Pad uint32 `align:"pad"`
Ktime uint64 `align:"ktime"`
}

// API between Kernel BPF and Userspace tetragon Golang agent
Expand Down
21 changes: 8 additions & 13 deletions pkg/sensors/exec/execvemap/execve.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,15 @@ type ExecveKey struct {
Pid uint32
}

type ExecveValueL struct {
Common processapi.MsgCommon
Kube processapi.MsgK8s
Parent processapi.MsgExecveKey
ParentFlags uint64
Capabilities processapi.MsgCapabilities
}

type ExecveValue struct {
Process processapi.MsgExecveKey
Parent processapi.MsgExecveKey
Flags uint32
Nspid uint32
Buffer uint64
Process processapi.MsgExecveKey `align:"key"`
Parent processapi.MsgExecveKey `align:"pkey"`
Flags uint32 `align:"flags"`
Nspid uint32 `align:"nspid"`
Binary uint32 `align:"binary"`
Pad uint32 `align:"pad"`
Namespaces processapi.MsgNamespaces `align:"ns"`
Capabilities processapi.MsgCapabilities `align:"caps"`
}

func (k *ExecveKey) String() string { return fmt.Sprintf("key=%d", k.Pid) }
Expand Down
17 changes: 13 additions & 4 deletions pkg/sensors/exec/procevents/proc_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,19 @@ func writeExecveMap(procs []Procs) {
v.Process.Ktime = p.ktime
v.Flags = 0
v.Nspid = p.nspid
v.Buffer = 0
v.Capabilities.Permitted = p.permitted
v.Capabilities.Effective = p.effective
v.Capabilities.Inheritable = p.inheritable
v.Namespaces.UtsInum = p.uts_ns
v.Namespaces.IpcInum = p.ipc_ns
v.Namespaces.MntInum = p.mnt_ns
v.Namespaces.PidInum = p.pid_ns
v.Namespaces.PidChildInum = p.pid_for_children_ns
v.Namespaces.NetInum = p.net_ns
v.Namespaces.TimeInum = p.time_ns
v.Namespaces.TimeChildInum = p.time_for_children_ns
v.Namespaces.CgroupInum = p.cgroup_ns
v.Namespaces.UserInum = p.user_ns

m.Update(k, v)
}
Expand All @@ -222,9 +234,6 @@ func writeExecveMap(procs []Procs) {
Pid: kernelPid,
Ktime: 1,
},
Flags: 0,
Nspid: 0,
Buffer: 0,
})
m.Close()
}
Expand Down