History

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.

Jiri Olsa committed 6 years ago

Commit a8a71791 parent c69d2dd3 files · +26 −1Browse files

Unified · Split

3 files
  1. kernel/trace/bpf_trace.c +8 −0
  2. tools/testing/selftests/bpf/prog_tests/d_path.c +10 −0
  3. tools/testing/selftests/bpf/progs/test_d_path.c +8 −1
kernel/trace/bpf_trace.c+8−0
@@ -1114,6 +1114,14 @@ BPF_CALL_3(bpf_d_path, struct path *, path, char *, buf, u32, sz) · 1113 unmodified lines
11141114 }
11151115
11161116 BTF_SET_START(btf_allowlist_d_path)
1117+#ifdef CONFIG_SECURITY
1118+BTF_ID(func, security_file_permission)
1119+BTF_ID(func, security_inode_getattr)
1120+BTF_ID(func, security_file_open)
1121+#endif
1122+#ifdef CONFIG_SECURITY_PATH
1123+BTF_ID(func, security_path_truncate)
1124+#endif
11171125 BTF_ID(func, vfs_truncate)
11181126 BTF_ID(func, vfs_fallocate)
11191127 BTF_ID(func, dentry_open)
tools/testing/selftests/bpf/prog_tests/d_path.c+10−0
@@ -120,6 +120,16 @@ void test_d_path(void) · 119 unmodified lines
120120 if (err < 0)
121121 goto cleanup;
122122
123+ if (CHECK(!bss->called_stat,
124+ "stat",
125+ "trampoline for security_inode_getattr was not called\n"))
126+ goto cleanup;
127+
128+ if (CHECK(!bss->called_close,
129+ "close",
130+ "trampoline for filp_close was not called\n"))
131+ goto cleanup;
132+
123133 for (int i = 0; i < MAX_FILES; i++) {
124134 CHECK(strncmp(src.paths[i], bss->paths_stat[i], MAX_PATH_LEN),
125135 "check",
tools/testing/selftests/bpf/progs/test_d_path.c+8−1
@@ -15,7 +15,10 @@ char paths_close[MAX_FILES][MAX_PATH_LEN] = {}; · 14 unmodified lines
1515 int rets_stat[MAX_FILES] = {};
1616 int rets_close[MAX_FILES] = {};
1717
18−SEC("fentry/vfs_getattr")
18+int called_stat = 0;
19+int called_close = 0;
20+
21+SEC("fentry/security_inode_getattr")
1922 int BPF_PROG(prog_stat, struct path *path, struct kstat *stat,
2023 __u32 request_mask, unsigned int query_flags)
2124 {
@@ -23,6 +26,8 @@ int BPF_PROG(prog_stat, struct path *path, struct kstat *stat, · 1 unmodified line
2326 __u32 cnt = cnt_stat;
2427 int ret;
2528
29+ called_stat = 1;
30+
2631 if (pid != my_pid)
2732 return 0;
2833
@@ -42,6 +47,8 @@ int BPF_PROG(prog_close, struct file *file, void *id) · 13 unmodified lines
4247 __u32 cnt = cnt_close;
4348 int ret;
4449
50+ called_close = 1;
51+
4552 if (pid != my_pid)
4653 return 0;
4754

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t