Skip to content

Commit 4170bc6

Browse files
sinkapAlexei Starovoitov
authored and
Alexei Starovoitov
committed
bpf: Exercise syscall operations for inode and sk storage
Use the check_syscall_operations added for task_local_storage to exercise syscall operations for other local storage maps: * Check the absence of an element for the given fd. * Create a new element, retrieve and compare its value. * Delete the element and check again for absence. Signed-off-by: KP Singh <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Martin KaFai Lau <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 9cde3be commit 4170bc6

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

tools/testing/selftests/bpf/prog_tests/test_local_storage.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static bool check_syscall_operations(int map_fd, int obj_fd)
157157
void test_test_local_storage(void)
158158
{
159159
char tmp_exec_path[PATH_MAX] = "/tmp/copy_of_rmXXXXXX";
160-
int err, serv_sk = -1, task_fd = -1;
160+
int err, serv_sk = -1, task_fd = -1, rm_fd = -1;
161161
struct local_storage *skel = NULL;
162162

163163
skel = local_storage__open_and_load();
@@ -181,6 +181,15 @@ void test_test_local_storage(void)
181181
if (CHECK(err < 0, "copy_rm", "err %d errno %d\n", err, errno))
182182
goto close_prog;
183183

184+
rm_fd = open(tmp_exec_path, O_RDONLY);
185+
if (CHECK(rm_fd < 0, "open", "failed to open %s err:%d, errno:%d",
186+
tmp_exec_path, rm_fd, errno))
187+
goto close_prog;
188+
189+
if (!check_syscall_operations(bpf_map__fd(skel->maps.inode_storage_map),
190+
rm_fd))
191+
goto close_prog;
192+
184193
/* Sets skel->bss->monitored_pid to the pid of the forked child
185194
* forks a child process that executes tmp_exec_path and tries to
186195
* unlink its executable. This operation should be denied by the loaded
@@ -209,11 +218,15 @@ void test_test_local_storage(void)
209218
CHECK(skel->data->sk_storage_result != 0, "sk_storage_result",
210219
"sk_local_storage not set\n");
211220

212-
close(serv_sk);
221+
if (!check_syscall_operations(bpf_map__fd(skel->maps.sk_storage_map),
222+
serv_sk))
223+
goto close_prog;
213224

214225
close_prog_unlink:
215226
unlink(tmp_exec_path);
216227
close_prog:
228+
close(serv_sk);
229+
close(rm_fd);
217230
close(task_fd);
218231
local_storage__destroy(skel);
219232
}

0 commit comments

Comments
 (0)