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

fix: nspid assign is not correct #3267

Merged
merged 1 commit into from
Jan 9, 2025
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
2 changes: 1 addition & 1 deletion bpf/cgroup/bpf_cgroup_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ send_cgrp_event(struct bpf_raw_tracepoint_args *ctx,
}
msg->cgrp_op = op;
msg->pid = pid;
msg->nspid = get_task_pid_vnr();
msg->nspid = get_task_pid_vnr_curr();
msg->cgrpid = cgrpid;
/* It is same as we are not tracking nested cgroups */
msg->cgrpid_tracker = cgrpid;
Expand Down
10 changes: 8 additions & 2 deletions bpf/lib/bpf_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ FUNC_INLINE struct task_struct *get_task_from_pid(__u32 pid)
return task;
}

FUNC_INLINE __u32 get_task_pid_vnr(void)
FUNC_INLINE __u32 get_task_pid_vnr_by_task(struct task_struct *task)
{
struct task_struct *task = (struct task_struct *)get_current_task();
int thread_pid_exists;
unsigned int level;
struct upid upid;
Expand Down Expand Up @@ -96,6 +95,13 @@ FUNC_INLINE __u32 get_task_pid_vnr(void)
return upid.nr;
}

FUNC_INLINE __u32 get_task_pid_vnr_curr(void)
{
struct task_struct *task = (struct task_struct *)get_current_task();

return get_task_pid_vnr_by_task(task);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please put extra line after declaration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there needs to be empty line after declrations, so something like:

--- a/bpf/lib/bpf_task.h
+++ b/bpf/lib/bpf_task.h
@@ -98,6 +98,7 @@ FUNC_INLINE __u32 get_task_pid_vnr_by_task(struct task_struct *task)
 FUNC_INLINE __u32 get_task_pid_vnr_curr(void)
 {
        struct task_struct *task = (struct task_struct *)get_current_task();
+
        return get_task_pid_vnr_by_task(task);
 }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done modify

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, also please add the missing changelog, thanks

}

FUNC_INLINE __u32 event_find_parent_pid(struct task_struct *t)
{
struct task_struct *task = get_parent(t);
Expand Down
2 changes: 1 addition & 1 deletion bpf/process/bpf_execve_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ event_execve(struct trace_event_raw_sched_process_exec *ctx)
*/
p->pid = pid >> 32;
p->tid = (__u32)pid;
p->nspid = get_task_pid_vnr();
p->nspid = get_task_pid_vnr_curr();
p->ktime = ktime_get_ns();
p->size = offsetof(struct msg_process, args);
p->auid = get_auid();
Expand Down
2 changes: 1 addition & 1 deletion bpf/process/bpf_fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ BPF_KPROBE(event_wake_up_new_task, struct task_struct *task)
curr->flags = EVENT_COMMON_FLAG_CLONE;
curr->key.pid = tgid;
curr->key.ktime = ktime_get_ns();
curr->nspid = get_task_pid_vnr();
curr->nspid = get_task_pid_vnr_by_task(task);
memcpy(&curr->bin, &parent->bin, sizeof(curr->bin));
curr->pkey = parent->key;

Expand Down
Loading