1 | // SPDX-License-Identifier: GPL-2.0 |
2 | |
3 | /* |
4 | * Copyright (C) 2022 Huawei Technologies Duesseldorf GmbH |
5 | * |
6 | * Author: Roberto Sassu <roberto.sassu@huawei.com> |
7 | */ |
8 | |
9 | #include "vmlinux.h" |
10 | #include <errno.h> |
11 | #include <bpf/bpf_helpers.h> |
12 | #include <bpf/bpf_tracing.h> |
13 | |
14 | /* From include/linux/mm.h. */ |
15 | #define FMODE_WRITE 0x2 |
16 | |
17 | struct { |
18 | __uint(type, BPF_MAP_TYPE_ARRAY); |
19 | __uint(max_entries, 1); |
20 | __type(key, __u32); |
21 | __type(value, __u32); |
22 | } data_input SEC(".maps" ); |
23 | |
24 | char _license[] SEC("license" ) = "GPL" ; |
25 | |
26 | SEC("lsm/bpf_map" ) |
27 | int BPF_PROG(check_access, struct bpf_map *map, fmode_t fmode) |
28 | { |
29 | if (map != (struct bpf_map *)&data_input) |
30 | return 0; |
31 | |
32 | if (fmode & FMODE_WRITE) |
33 | return -EACCES; |
34 | |
35 | return 0; |
36 | } |
37 | |