Skip to content
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

tetragon: clone namespace improvements #2370

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 7 additions & 0 deletions bpf/process/bpf_fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ BPF_KPROBE(event_wake_up_new_task, struct task_struct *task)
struct execve_map_value *curr, *parent;
struct msg_clone_event msg;
struct msg_capabilities caps;
struct msg_ns ns;
u64 msg_size = sizeof(struct msg_clone_event);
u32 tgid = 0;

Expand Down Expand Up @@ -66,6 +67,12 @@ BPF_KPROBE(event_wake_up_new_task, struct task_struct *task)
curr->caps.effective = caps.effective;
curr->caps.inheritable = caps.inheritable;

/* Store the thread leader namespaces so we can check later
* before the execve hook point if they changed or not.
*/
get_namespaces(&ns, task);
memcpy(&curr->ns, &ns, sizeof(struct msg_ns));

/* Setup the msg_clone_event and sent to the user. */
msg.common.op = MSG_OP_CLONE;
msg.common.size = msg_size;
Expand Down
11 changes: 8 additions & 3 deletions pkg/sensors/tracing/kprobe_threads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
sm "github.com/cilium/tetragon/pkg/matchers/stringmatcher"
"github.com/cilium/tetragon/pkg/observer/observertesthelper"
"github.com/cilium/tetragon/pkg/reader/caps"
"github.com/cilium/tetragon/pkg/reader/namespace"
"github.com/cilium/tetragon/pkg/testutils"
tus "github.com/cilium/tetragon/pkg/testutils/sensors"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -92,12 +93,14 @@ spec:
cti.AssertPidsTids(t)

myCaps := ec.NewCapabilitiesChecker().FromCapabilities(caps.GetCurrentCapabilities())
myNs := ec.NewNamespacesChecker().FromNamespaces(namespace.GetCurrentNamespace())

parentCheck := ec.NewProcessChecker().
WithBinary(sm.Suffix("threads-tester")).
WithPid(cti.ParentPid).
WithTid(cti.ParentTid).
WithCap(myCaps)
WithCap(myCaps).
WithNs(myNs)

execCheck := ec.NewProcessExecChecker("").
WithProcess(parentCheck)
Expand All @@ -109,7 +112,8 @@ spec:
WithBinary(sm.Suffix("threads-tester")).
WithPid(cti.Child1Pid).
WithTid(cti.Child1Tid).
WithCap(myCaps)
WithCap(myCaps).
WithNs(myNs)

child1KpChecker := ec.NewProcessKprobeChecker("").
WithProcess(child1Checker).WithParent(parentCheck)
Expand All @@ -118,7 +122,8 @@ spec:
WithBinary(sm.Suffix("threads-tester")).
WithPid(cti.Thread1Pid).
WithTid(cti.Thread1Tid).
WithCap(myCaps)
WithCap(myCaps).
WithNs(myNs)

thread1KpChecker := ec.NewProcessKprobeChecker("").
WithProcess(thread1Checker).WithParent(parentCheck)
Expand Down
Loading