blob: a7c0a553aa50160f6212b1bc5c9fd20f51bba61b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2024 Google LLC. */
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include "bpf_misc.h"
#include "bpf_experimental.h"
static char buf[64];
SEC("lsm.s/file_open")
__success
int BPF_PROG(get_task_exe_file_and_put_kfunc_from_current_sleepable)
{
struct file *acquired;
acquired = bpf_get_task_exe_file(bpf_get_current_task_btf());
if (!acquired)
return 0;
bpf_put_file(acquired);
return 0;
}
SEC("lsm/file_open")
__success
int BPF_PROG(get_task_exe_file_and_put_kfunc_from_current_non_sleepable, struct file *file)
{
struct file *acquired;
acquired = bpf_get_task_exe_file(bpf_get_current_task_btf());
if (!acquired)
return 0;
bpf_put_file(acquired);
return 0;
}
SEC("lsm.s/task_alloc")
__success
int BPF_PROG(get_task_exe_file_and_put_kfunc_from_argument,
struct task_struct *task)
{
struct file *acquired;
acquired = bpf_get_task_exe_file(task);
if (!acquired)
return 0;
bpf_put_file(acquired);
return 0;
}
SEC("lsm.s/inode_getattr")
__success
int BPF_PROG(path_d_path_from_path_argument, struct path *path)
{
int ret;
ret = bpf_path_d_path(path, buf, sizeof(buf));
__sink(ret);
return 0;
}
SEC("lsm.s/file_open")
__success
int BPF_PROG(path_d_path_from_file_argument, struct file *file)
{
int ret;
struct path *path;
/* The f_path member is a path which is embedded directly within a
* file. Therefore, a pointer to such embedded members are still
* recognized by the BPF verifier as being PTR_TRUSTED as it's
* essentially PTR_TRUSTED w/ a non-zero fixed offset.
*/
path = &file->f_path;
ret = bpf_path_d_path(path, buf, sizeof(buf));
__sink(ret);
return 0;
}
char _license[] SEC("license") = "GPL";
|