Skip to content

Commit 8f8b515

Browse files
authored
ebpf: fix old pid_ns resolution (#1972) (#1973)
We currently use task->pids to resolve task's old pid_ns when switch namespaces, which is wrong. Use task->nsproxy to get the right old pid_ns_id Signed-off-by: xjas <[email protected]>
1 parent db48b41 commit 8f8b515

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pkg/ebpf/c/tracee.bpf.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ static __always_inline u32 get_mnt_ns_id(struct nsproxy *ns)
760760
return READ_KERN(mntns->ns.inum);
761761
}
762762

763-
static __always_inline u32 get_pid_ns_id(struct nsproxy *ns)
763+
static __always_inline u32 get_pid_ns_for_children_id(struct nsproxy *ns)
764764
{
765765
struct pid_namespace *pidns = READ_KERN(ns->pid_ns_for_children);
766766
return READ_KERN(pidns->ns.inum);
@@ -795,6 +795,11 @@ static __always_inline u32 get_task_mnt_ns_id(struct task_struct *task)
795795
return get_mnt_ns_id(READ_KERN(task->nsproxy));
796796
}
797797

798+
static __always_inline u32 get_task_pid_ns_for_children_id(struct task_struct *task)
799+
{
800+
return get_pid_ns_for_children_id(READ_KERN(task->nsproxy));
801+
}
802+
798803
static __always_inline u32 get_task_pid_ns_id(struct task_struct *task)
799804
{
800805
unsigned int level = 0;
@@ -3528,8 +3533,8 @@ int BPF_KPROBE(trace_switch_task_namespaces)
35283533
pid_t pid = READ_KERN(task->pid);
35293534
u32 old_mnt = data.context.task.mnt_id;
35303535
u32 new_mnt = get_mnt_ns_id(new);
3531-
u32 old_pid = data.context.task.pid_id;
3532-
u32 new_pid = get_pid_ns_id(new);
3536+
u32 old_pid = get_task_pid_ns_for_children_id(task);
3537+
u32 new_pid = get_pid_ns_for_children_id(new);
35333538
u32 old_uts = get_task_uts_ns_id(task);
35343539
u32 new_uts = get_uts_ns_id(new);
35353540
u32 old_ipc = get_task_ipc_ns_id(task);

0 commit comments

Comments
 (0)