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

[tools/execsnoop] Try to get parent PID from current task's real parent. #1885

Merged
merged 4 commits into from
Jul 16, 2018

Conversation

calavera
Copy link
Contributor

Fallback to read the PPid from /proc if the real parent's TGID is 0.

Related to #1883

Signed-off-by: David Calavera [email protected]

@palmtenor
Copy link
Member

Given what you said in #1883 , have you tested in another Kernel to make sure the BPF part works?

Also, please update the TODO comment at def get_ppid(pid): (my inline comment somehow doesn't work...)

@palmtenor
Copy link
Member

[buildbot, ok to test]

Copy link
Contributor

@pchaigno pchaigno left a comment

Choose a reason for hiding this comment

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

There's a couple of bpf_probe_read you can remove.

I'll try your changes with a 4.13 kernel when I get a chance.

task = (struct task_struct *)bpf_get_current_task();
bpf_probe_read(&real_parent_task, sizeof(real_parent_task), &task->real_parent);
bpf_probe_read(&ppid, sizeof(ppid), &real_parent_task->tgid);
data.ppid = ppid;
Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldn't need explicit calls to bpf_probe_read here:

daat.ppid = task->real_parent->tgid;

bcc will handle the rewrite.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, good to know, I tried that too and got similar results.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, that wouldn't change the issue with the parent PID. It translates to the same bytecode.

task = (struct task_struct *)bpf_get_current_task();
bpf_probe_read(&real_parent_task, sizeof(real_parent_task), &task->real_parent);
bpf_probe_read(&ppid, sizeof(ppid), &real_parent_task->tgid);
data.ppid = ppid;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

Fallback to read the PPid from /proc if the real parent's TGID is 0.

Signed-off-by: David Calavera <[email protected]>
Signed-off-by: David Calavera <[email protected]>
@brendangregg
Copy link
Member

Thanks for getting this done. Any further info on the kernel versions where task->real_parent->tgip sometimes returns zero? Just want to understand that caveat as I'm sure I'll run into it in the future too.

@calavera
Copy link
Contributor Author

I know for sure that 4.13.0-46-generic returns 0. I just tested 4.17.5 and it returns the real parent PID

@calavera
Copy link
Contributor Author

If you want to wait before merging this, I can test 4.14, 4.15 and 4.16 to have the minimum version that works. It might be good to have that information in the docs. I can also open an new PR with docs if you point me to the best place to have that kind of information.

@brendangregg
Copy link
Member

Since you're the first person to do ppid properly, I think people will copy-n-paste your code everywhere. So I'd put a comment with the code at least. :-)

@palmtenor
Copy link
Member

palmtenor commented Jul 12, 2018

@calavera Thanks! I think it is not a minimum version, only 4.13 (and maybe 4.14) would have the problem and earlier Kernels should be fine as well. Is your Kernel the Ubuntu mainline 4.13? I will try debug see why the temporary fix didn't work~

@calavera
Copy link
Contributor Author

calavera commented Jul 13, 2018

@brendangregg I've added an inline comment referencing the original issue I opened.

@calavera
Copy link
Contributor Author

It looks like the kernel that Jenkins use for tests in Xenial is too old and doesn't include bpf_get_current_task

27: 
27: HINT: bpf_get_current_task missing (added in Linux 4.8).

@pchaigno
Copy link
Contributor

It looks like the kernel that Jenkins use for tests in Xenial is too old and doesn't include bpf_get_current_task

@calavera You'll have to add a precondition to the test in the same way as test_mountsnoop.

bpf_get_current_task is only available in 4.8 and above.

Signed-off-by: David Calavera <[email protected]>
@calavera
Copy link
Contributor Author

Updated, thanks @pchaigno

@brendangregg
Copy link
Member

LGTM, thanks

@brendangregg brendangregg merged commit 5965fdc into iovisor:master Jul 16, 2018
@calavera calavera deleted the execsnoop_real_parent branch July 17, 2018 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants