1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2024 Google LLC. */
5 #include <bpf/bpf_helpers.h>
6 #include <bpf/bpf_tracing.h>
9 #include "bpf_experimental.h"
13 SEC("lsm.s/file_open")
15 int BPF_PROG(get_task_exe_file_and_put_kfunc_from_current_sleepable)
17 struct file *acquired;
19 acquired = bpf_get_task_exe_file(bpf_get_current_task_btf());
23 bpf_put_file(acquired);
29 int BPF_PROG(get_task_exe_file_and_put_kfunc_from_current_non_sleepable, struct file *file)
31 struct file *acquired;
33 acquired = bpf_get_task_exe_file(bpf_get_current_task_btf());
37 bpf_put_file(acquired);
41 SEC("lsm.s/task_alloc")
43 int BPF_PROG(get_task_exe_file_and_put_kfunc_from_argument,
44 struct task_struct *task)
46 struct file *acquired;
48 acquired = bpf_get_task_exe_file(task);
52 bpf_put_file(acquired);
56 SEC("lsm.s/inode_getattr")
58 int BPF_PROG(path_d_path_from_path_argument, struct path *path)
62 ret = bpf_path_d_path(path, buf, sizeof(buf));
67 SEC("lsm.s/file_open")
69 int BPF_PROG(path_d_path_from_file_argument, struct file *file)
74 /* The f_path member is a path which is embedded directly within a
75 * file. Therefore, a pointer to such embedded members are still
76 * recognized by the BPF verifier as being PTR_TRUSTED as it's
77 * essentially PTR_TRUSTED w/ a non-zero fixed offset.
80 ret = bpf_path_d_path(path, buf, sizeof(buf));
85 char _license[] SEC("license") = "GPL";