mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-03 07:38:10 +00:00
selftests/bpf: Check stack_mprotect() return value
If stack_mprotect() succeeds, errno is not changed. This can produce misleading error messages, that show stale errno. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Link: https://lore.kernel.org/r/20230128000650.1516334-13-iii@linux.ibm.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
06cea99e68
commit
2934565f04
2 changed files with 6 additions and 3 deletions
|
@ -472,6 +472,7 @@ static void lsm_subtest(struct test_bpf_cookie *skel)
|
||||||
int prog_fd;
|
int prog_fd;
|
||||||
int lsm_fd = -1;
|
int lsm_fd = -1;
|
||||||
LIBBPF_OPTS(bpf_link_create_opts, link_opts);
|
LIBBPF_OPTS(bpf_link_create_opts, link_opts);
|
||||||
|
int err;
|
||||||
|
|
||||||
skel->bss->lsm_res = 0;
|
skel->bss->lsm_res = 0;
|
||||||
|
|
||||||
|
@ -482,8 +483,9 @@ static void lsm_subtest(struct test_bpf_cookie *skel)
|
||||||
if (!ASSERT_GE(lsm_fd, 0, "lsm.link_create"))
|
if (!ASSERT_GE(lsm_fd, 0, "lsm.link_create"))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
stack_mprotect();
|
err = stack_mprotect();
|
||||||
if (!ASSERT_EQ(errno, EPERM, "stack_mprotect"))
|
if (!ASSERT_EQ(err, -1, "stack_mprotect") ||
|
||||||
|
!ASSERT_EQ(errno, EPERM, "stack_mprotect"))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
usleep(1);
|
usleep(1);
|
||||||
|
|
|
@ -75,7 +75,8 @@ static int test_lsm(struct lsm *skel)
|
||||||
skel->bss->monitored_pid = getpid();
|
skel->bss->monitored_pid = getpid();
|
||||||
|
|
||||||
err = stack_mprotect();
|
err = stack_mprotect();
|
||||||
if (!ASSERT_EQ(errno, EPERM, "stack_mprotect"))
|
if (!ASSERT_EQ(err, -1, "stack_mprotect") ||
|
||||||
|
!ASSERT_EQ(errno, EPERM, "stack_mprotect"))
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
ASSERT_EQ(skel->bss->mprotect_count, 1, "mprotect_count");
|
ASSERT_EQ(skel->bss->mprotect_count, 1, "mprotect_count");
|
||||||
|
|
Loading…
Reference in a new issue