Skip to content

Commit

Permalink
bpf: read the task real parent
Browse files Browse the repository at this point in the history
Use real_parent instead of parent in case parent is overwritten.

Signed-off-by: Djalal Harouni <tixxdz@gmail.com>
  • Loading branch information
tixxdz authored and jrfastab committed Oct 6, 2023
1 parent 5c9523f commit a2251c1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions bpf/lib/bpf_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ get_parent(struct task_struct *t)
{
struct task_struct *task;

probe_read(&task, sizeof(task), _(&t->parent));
/* Read the real parent */
probe_read(&task, sizeof(task), _(&t->real_parent));
if (!task)
return 0;
return task;
Expand Down Expand Up @@ -115,7 +116,7 @@ __event_find_parent(struct task_struct *task)

#pragma unroll
for (i = 0; i < 4; i++) {
probe_read(&task, sizeof(task), _(&task->parent));
probe_read(&task, sizeof(task), _(&task->real_parent));
if (!task)
break;
probe_read(&pid, sizeof(pid), _(&task->tgid));
Expand Down Expand Up @@ -165,7 +166,7 @@ event_find_curr(__u32 *ppid, bool *walked)
break;
value = 0;
*walked = 1;
probe_read(&task, sizeof(task), _(&task->parent));
probe_read(&task, sizeof(task), _(&task->real_parent));
if (!task)
break;
probe_read(&pid, sizeof(pid), _(&task->tgid));
Expand Down

0 comments on commit a2251c1

Please sign in to comment.