Skip to content

Commit 1674767

Browse files
safchainlebauce
andcommitted
fix(security): handle runc CLONE_INTO_CGROUP to fix cgroup ID propagation
Recent versions of runc use clone3(2) with CLONE_INTO_CGROUP when available, placing new container processes directly into the target cgroup at spawn time without writing the PID to cgroup.procs. This eliminates the CgroupWriteEventType event that the security agent was relying on to propagate cgroup context to newly created processes, causing incorrect cgroup ID assignment. Remove the parent cgroup inheritance via fill_cgroup_context during exec event handling. Instead, an empty CGroupContext is passed when inserting the exec entry, which causes the cgroup resolver to fall back to procfs (/proc/<pid>/cgroup) to resolve the correct cgroup ID. Also inline copy_proc_cache into its single call site in trace__cgroup_write. runc reference: opencontainers/runc@5af4dd4 Co-Authored-By: Sylvain Baubeau <sylvain.baubeau@datadoghq.com>
1 parent 377ebbd commit 1674767

File tree

3 files changed

+2
-10
lines changed

3 files changed

+2
-10
lines changed

pkg/security/ebpf/c/include/helpers/process.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ void __attribute__((always_inline)) copy_proc_entry(struct process_entry_t *src,
3636
bpf_probe_read(dst->comm, TASK_COMM_LEN, src->comm);
3737
}
3838

39-
void __attribute__((always_inline)) copy_proc_cache(struct proc_cache_t *src, struct proc_cache_t *dst) {
40-
dst->cgroup = src->cgroup;
41-
copy_proc_entry(&src->entry, &dst->entry);
42-
}
43-
4439
void __attribute__((always_inline)) copy_pid_cache_except_exit_ts(struct pid_cache_t *src, struct pid_cache_t *dst) {
4540
dst->cookie = src->cookie;
4641
dst->user_session_id = src->user_session_id;

pkg/security/ebpf/c/include/hooks/cgroup.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ static __attribute__((always_inline)) int trace__cgroup_write(ctx_t *ctx) {
6060
// Select the old cache entry
6161
old_entry = get_proc_from_cookie(cookie);
6262
if (old_entry) {
63-
// copy cache data
64-
copy_proc_cache(old_entry, &new_entry);
63+
new_entry.cgroup = old_entry->cgroup;
64+
copy_proc_entry(&old_entry->entry, &new_entry.entry);
6565
}
6666
} else {
6767
new_cookie = 1;

pkg/security/ebpf/c/include/hooks/exec.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,6 @@ int __attribute__((always_inline)) send_exec_event(ctx_t *ctx) {
781781
struct proc_cache_t *parent_pc = get_proc_from_cookie(parent_cookie);
782782
if (parent_pc) {
783783
parent_inode = parent_pc->entry.executable.path_key.ino;
784-
785-
// inherit the parent cgroup context
786-
fill_cgroup_context(parent_pc, &pc.cgroup);
787784
}
788785
}
789786

0 commit comments

Comments
 (0)