Loading...
Note: File does not exist in v5.9.
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2024 Google LLC. */
3
4#include <vmlinux.h>
5#include <bpf/bpf_helpers.h>
6#include <bpf/bpf_tracing.h>
7
8#include "bpf_misc.h"
9#include "bpf_experimental.h"
10
11static char buf[64];
12
13SEC("lsm.s/file_open")
14__success
15int BPF_PROG(get_task_exe_file_and_put_kfunc_from_current_sleepable)
16{
17 struct file *acquired;
18
19 acquired = bpf_get_task_exe_file(bpf_get_current_task_btf());
20 if (!acquired)
21 return 0;
22
23 bpf_put_file(acquired);
24 return 0;
25}
26
27SEC("lsm/file_open")
28__success
29int BPF_PROG(get_task_exe_file_and_put_kfunc_from_current_non_sleepable, struct file *file)
30{
31 struct file *acquired;
32
33 acquired = bpf_get_task_exe_file(bpf_get_current_task_btf());
34 if (!acquired)
35 return 0;
36
37 bpf_put_file(acquired);
38 return 0;
39}
40
41SEC("lsm.s/task_alloc")
42__success
43int BPF_PROG(get_task_exe_file_and_put_kfunc_from_argument,
44 struct task_struct *task)
45{
46 struct file *acquired;
47
48 acquired = bpf_get_task_exe_file(task);
49 if (!acquired)
50 return 0;
51
52 bpf_put_file(acquired);
53 return 0;
54}
55
56SEC("lsm.s/inode_getattr")
57__success
58int BPF_PROG(path_d_path_from_path_argument, struct path *path)
59{
60 int ret;
61
62 ret = bpf_path_d_path(path, buf, sizeof(buf));
63 __sink(ret);
64 return 0;
65}
66
67SEC("lsm.s/file_open")
68__success
69int BPF_PROG(path_d_path_from_file_argument, struct file *file)
70{
71 int ret;
72 struct path *path;
73
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.
78 */
79 path = &file->f_path;
80 ret = bpf_path_d_path(path, buf, sizeof(buf));
81 __sink(ret);
82 return 0;
83}
84
85char _license[] SEC("license") = "GPL";