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/opensnoop: Bugfix for a full path contains multiple mountpoints #4285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xingfeng2510
Copy link
Contributor

@xingfeng2510 xingfeng2510 commented Oct 19, 2022

For a pathname contains multiple mountpoints, -F option only dumps first mount point, not full path.

For example, an application try to open a.txt (located at /home/app/), while '/home' is a mount point, opensnoop will dump '/app/a.txt' rather than '/home/app/a.txt'.

This patch try to fix it.

@yonghong-song Please have a look, thanks.

int i;

task = (struct task_struct *)bpf_get_current_task_btf();
task = (struct task_struct *)bpf_get_current_task();
Copy link
Collaborator

Choose a reason for hiding this comment

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

We may have some verification with newer kernel. Which kernel did you test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested on kernel 5.4/5.14/5.15. When I switched to bpf_get_current_task_btf(), it failed with such error messages:

84: (85) call bpf_get_current_task_btf#158
85: (b7) r6 = 31
; dentry = task->fs->pwd.dentry;
86: (79) r9 = *(u64 *)(r0 +2768)
; vfsmnt = task->fs->pwd.mnt;
87: (79) r8 = *(u64 *)(r9 +40)
; dentry = task->fs->pwd.dentry;
88: (07) r9 += 48
; mnt_parent = mnt->mnt_parent;
89: (79) r7 = *(u64 *)(r8 -16)
R8 is ptr_vfsmount invalid negative access: off=-16
processed 87 insns (limit 1000000) max_states_per_insn 0 total_states 4 peak_states 4 mark_read 3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

btw, other tools still use bpf_get_current_task(), and bpf_get_current_task_btf() looks not stable, I didn't analyze it yet.

@xingfeng2510
Copy link
Contributor Author

any suggestions or feedback ?

@dennisorlando
Copy link

should be addressed by #5153

@xingfeng2510
Copy link
Contributor Author

xingfeng2510 commented Nov 23, 2024

should be addressed by #5153

#5153 unwind dentry by reading /proc/self/mountinfo frequently is inefficient. This pull request referred to kernel function d_path, which returns the path of a dentry and unwinds in kernel.

for example, when reading such a link file /proc/793073/fd/4, it converts dentry to full path /usr/local/agent/log/agent.log, which contains at least two mountpoints, by invoking kernel functions do_proc_readlink -> d_path -> __prepend_path source link: d_path

# ls -l /proc/793073/fd/4
lrwx------ 1 root root 64 Nov 17 22:41 /proc/793073/fd/4 -> /usr/local/agent/log/agent.log

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.

3 participants