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

bpf: Add open-coded style process file iterator and bpf_fget_task() kfunc #8101

Closed

Conversation

kernel-patches-daemon-bpf[bot]
Copy link

Pull request for series with
subject: bpf: Add open-coded style process file iterator and bpf_fget_task() kfunc
version: 4
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=911034

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 2c8b09a
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=911034
version: 4

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 2c8b09a
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=911034
version: 4

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 2c8b09a
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=911034
version: 4

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: fc39fb5
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=911034
version: 4

This patch adds the open-coded iterator style process file iterator
kfuncs bpf_iter_task_file_{new,next,destroy} that iterates over all
files opened by the specified process.

bpf_iter_task_file_next returns a pointer to bpf_iter_task_file_item,
which currently contains *task, *file, fd. This is an extensible
structure that enables compatibility with different versions
through CO-RE.

The reference to struct file acquired by the previous
bpf_iter_task_file_next() is released in the next
bpf_iter_task_file_next(), and the last reference is released in the
last bpf_iter_task_file_next() that returns NULL.

In the bpf_iter_task_file_destroy(), if the iterator does not iterate to
the end, then the last struct file reference is released at this time.

Signed-off-by: Juntong Deng <[email protected]>
This patch adds test cases for open-coded style process file iterator.

Test cases related to process files are run in the newly created child
process. Close all opened files inherited from the parent process in
the child process to avoid the files opened by the parent process
affecting the test results.

In addition, this patch adds failure test cases where bpf programs
cannot pass the verifier due to uninitialized or untrusted
arguments, or not in RCU CS, etc.

Signed-off-by: Juntong Deng <[email protected]>
This patch adds bpf_fget_task() kfunc.

bpf_fget_task() is used to get a pointer to the struct file
corresponding to the task file descriptor. Note that this function
acquires a reference to struct file.

Signed-off-by: Juntong Deng <[email protected]>
Currently fs kfuncs are only available for LSM program type, but fs
kfuncs are generic and useful for scenarios other than LSM.

This patch makes fs kfuncs available for SYSCALL and TRACING
program types.

Signed-off-by: Juntong Deng <[email protected]>
This patch adds test cases for bpf_fget_task() kfunc.

test_bpf_fget_task is used to test obtaining struct file based on
the file descriptor in the current process.

bpf_fget_task_null_task and bpf_fget_task_untrusted_task are used to
test the failure cases of passing NULL or untrusted pointer as argument.

Signed-off-by: Juntong Deng <[email protected]>
@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: fc39fb5
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=911034
version: 4

@kernel-patches-daemon-bpf
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=911034 expired. Closing PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant