Skip to content

Commit a899337

Browse files
Tao ChenKernel Patches Daemon
authored andcommitted
selftests/bpf: Add bpf_get_task_cmdline test case
Create a task, call bpf_get_task_cmdline to retrieve the cmdline, and check if it succeeds. Signed-off-by: Tao Chen <[email protected]>
1 parent b9d7592 commit a899337

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ static const char * const vpid_success_tests[] = {
156156
"test_task_from_vpid_invalid",
157157
};
158158

159+
static const char * const cmdline_success_tests[] = {
160+
"test_get_task_cmdline",
161+
};
162+
159163
void test_task_kfunc(void)
160164
{
161165
int i;
@@ -174,5 +178,12 @@ void test_task_kfunc(void)
174178
run_vpid_success_test(vpid_success_tests[i]);
175179
}
176180

181+
for (i = 0; i < ARRAY_SIZE(cmdline_success_tests); i++) {
182+
if (!test__start_subtest(cmdline_success_tests[i]))
183+
continue;
184+
185+
run_success_test(cmdline_success_tests[i]);
186+
}
187+
177188
RUN_TESTS(task_kfunc_failure);
178189
}

tools/testing/selftests/bpf/progs/task_kfunc_success.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,19 @@ int BPF_PROG(task_kfunc_acquire_trusted_walked, struct task_struct *task, u64 cl
367367
return 0;
368368
}
369369

370+
SEC("lsm.s/task_alloc")
371+
int BPF_PROG(test_get_task_cmdline, struct task_struct *task)
372+
{
373+
char buf[64];
374+
int ret;
375+
376+
ret = bpf_get_task_cmdline(task, buf, sizeof(buf));
377+
if (ret < 0)
378+
err = 1;
379+
380+
return 0;
381+
}
382+
370383
SEC("syscall")
371384
int test_task_from_vpid_current(const void *ctx)
372385
{

0 commit comments

Comments
 (0)