-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
add helper: convert FD to pathname #2544
Conversation
[buildbot, test this please] |
[buildbot, ok to test] |
struct task_struct *curr = (struct task_struct *)bpf_get_current_task(); | ||
|
||
bpf_probe_read(&files, sizeof(files), &curr->files); | ||
bpf_probe_read(&fdt, sizeof(fdt), &files->fdt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If bpf_probe_read() has issues (e.g., page fault) to read the contents, it will zero'ing the buffer and returns a negative value. With address of zero, all subsequent bpf_probe_read() will return -EFAULT, so eventually, dn.name will 0. I guess it is okay not to check bpf_probe_read() return value since we optimize for common case where bpf_probe_read() unlikely to fail. But could you add comments about why this mechanism works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add a test case to use this helper?
This doesn't provide fd2path -- it's providing fd2filename. I'll update the original ticket, as we've discussed this several times since then. It may be ok to merge this PR after changing it to fd2filename. In addition, we'd really like an fd2path -- I'd use it more often than fd2filename. I'll follow up in #237 with more detail. |
Thanks, I'll add it later |
Thanks, I'll change this, and do some work with real fd2path. |
fd2path is indeed more helpful. I have seen people using bpf_probe_read to traverse 2 or 3 level of path hierarchy to get an idea of the path signature. A helper returning the whole path to a buffer will be more efficient and complete than such a hack. |
Your newly included header files
caused test failures as new headers bring in new definitions conflicting some tests existing function/type definitions. |
Get it, I'll do some research like https://www.kernel.org/doc/html/latest/filesystems/path-lookup.html#introduction-to-pathname-lookup then get a way to implement this. |
Update: I've implemented a real
With the test code:
I will commit this as soon as possible. |
I have committed to http://patchwork.ozlabs.org/patch/1179287/ PTAL |
Fixes: #237