Commit a8a71796 authored by Jiri Olsa's avatar Jiri Olsa Committed by Alexei Starovoitov

selftests/bpf: Fix stat probe in d_path test

Some kernels builds might inline vfs_getattr call within fstat
syscall code path, so fentry/vfs_getattr trampoline is not called.

Add security_inode_getattr to allowlist and switch the d_path test stat
trampoline to security_inode_getattr.

Keeping dentry_open and filp_close, because they are in their own
files, so unlikely to be inlined, but in case they are, adding
security_file_open.

Adding flags that indicate trampolines were called and failing
the test if any of them got missed, so it's easier to identify
the issue next time.

Fixes: e4d1af4b ("selftests/bpf: Add test for d_path helper")
Suggested-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarJiri Olsa <jolsa@redhat.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200918112338.2618444-1-jolsa@kernel.org
parent c69d2ddb
...@@ -1114,6 +1114,14 @@ BPF_CALL_3(bpf_d_path, struct path *, path, char *, buf, u32, sz) ...@@ -1114,6 +1114,14 @@ BPF_CALL_3(bpf_d_path, struct path *, path, char *, buf, u32, sz)
} }
BTF_SET_START(btf_allowlist_d_path) BTF_SET_START(btf_allowlist_d_path)
#ifdef CONFIG_SECURITY
BTF_ID(func, security_file_permission)
BTF_ID(func, security_inode_getattr)
BTF_ID(func, security_file_open)
#endif
#ifdef CONFIG_SECURITY_PATH
BTF_ID(func, security_path_truncate)
#endif
BTF_ID(func, vfs_truncate) BTF_ID(func, vfs_truncate)
BTF_ID(func, vfs_fallocate) BTF_ID(func, vfs_fallocate)
BTF_ID(func, dentry_open) BTF_ID(func, dentry_open)
......
...@@ -120,6 +120,16 @@ void test_d_path(void) ...@@ -120,6 +120,16 @@ void test_d_path(void)
if (err < 0) if (err < 0)
goto cleanup; goto cleanup;
if (CHECK(!bss->called_stat,
"stat",
"trampoline for security_inode_getattr was not called\n"))
goto cleanup;
if (CHECK(!bss->called_close,
"close",
"trampoline for filp_close was not called\n"))
goto cleanup;
for (int i = 0; i < MAX_FILES; i++) { for (int i = 0; i < MAX_FILES; i++) {
CHECK(strncmp(src.paths[i], bss->paths_stat[i], MAX_PATH_LEN), CHECK(strncmp(src.paths[i], bss->paths_stat[i], MAX_PATH_LEN),
"check", "check",
......
...@@ -15,7 +15,10 @@ char paths_close[MAX_FILES][MAX_PATH_LEN] = {}; ...@@ -15,7 +15,10 @@ char paths_close[MAX_FILES][MAX_PATH_LEN] = {};
int rets_stat[MAX_FILES] = {}; int rets_stat[MAX_FILES] = {};
int rets_close[MAX_FILES] = {}; int rets_close[MAX_FILES] = {};
SEC("fentry/vfs_getattr") int called_stat = 0;
int called_close = 0;
SEC("fentry/security_inode_getattr")
int BPF_PROG(prog_stat, struct path *path, struct kstat *stat, int BPF_PROG(prog_stat, struct path *path, struct kstat *stat,
__u32 request_mask, unsigned int query_flags) __u32 request_mask, unsigned int query_flags)
{ {
...@@ -23,6 +26,8 @@ int BPF_PROG(prog_stat, struct path *path, struct kstat *stat, ...@@ -23,6 +26,8 @@ int BPF_PROG(prog_stat, struct path *path, struct kstat *stat,
__u32 cnt = cnt_stat; __u32 cnt = cnt_stat;
int ret; int ret;
called_stat = 1;
if (pid != my_pid) if (pid != my_pid)
return 0; return 0;
...@@ -42,6 +47,8 @@ int BPF_PROG(prog_close, struct file *file, void *id) ...@@ -42,6 +47,8 @@ int BPF_PROG(prog_close, struct file *file, void *id)
__u32 cnt = cnt_close; __u32 cnt = cnt_close;
int ret; int ret;
called_close = 1;
if (pid != my_pid) if (pid != my_pid)
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment