1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
6 #include <bpf/bpf_helpers.h>
7 #include <bpf/bpf_tracing.h>
8 #include "bpf_kfuncs.h"
10 char _license[] SEC("license") = "GPL";
13 __u32 found_xattr_from_file;
14 __u32 found_xattr_from_dentry;
16 static const char expected_value[] = "hello";
20 SEC("lsm.s/file_open")
21 int BPF_PROG(test_file_open, struct file *f)
23 struct bpf_dynptr value_ptr;
27 pid = bpf_get_current_pid_tgid() >> 32;
28 if (pid != monitored_pid)
31 bpf_dynptr_from_mem(value1, sizeof(value1), 0, &value_ptr);
33 ret = bpf_get_file_xattr(f, "user.kfuncs", &value_ptr);
34 if (ret != sizeof(expected_value))
36 if (bpf_strncmp(value1, ret, expected_value))
38 found_xattr_from_file = 1;
42 SEC("lsm.s/inode_getxattr")
43 int BPF_PROG(test_inode_getxattr, struct dentry *dentry, char *name)
45 struct bpf_dynptr value_ptr;
49 pid = bpf_get_current_pid_tgid() >> 32;
50 if (pid != monitored_pid)
53 bpf_dynptr_from_mem(value2, sizeof(value2), 0, &value_ptr);
55 ret = bpf_get_dentry_xattr(dentry, "user.kfuncs", &value_ptr);
56 if (ret != sizeof(expected_value))
58 if (bpf_strncmp(value2, ret, expected_value))
60 found_xattr_from_dentry = 1;
62 /* return non-zero to fail getxattr from user space */