Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Ilya Leoshkevich and committed by
Alexei Starovoitov
2934565f 06cea99e

+6 -3
+4 -2
tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
··· 472 472 int prog_fd; 473 473 int lsm_fd = -1; 474 474 LIBBPF_OPTS(bpf_link_create_opts, link_opts); 475 + int err; 475 476 476 477 skel->bss->lsm_res = 0; 477 478 ··· 483 482 if (!ASSERT_GE(lsm_fd, 0, "lsm.link_create")) 484 483 goto cleanup; 485 484 486 - stack_mprotect(); 487 - if (!ASSERT_EQ(errno, EPERM, "stack_mprotect")) 485 + err = stack_mprotect(); 486 + if (!ASSERT_EQ(err, -1, "stack_mprotect") || 487 + !ASSERT_EQ(errno, EPERM, "stack_mprotect")) 488 488 goto cleanup; 489 489 490 490 usleep(1);
+2 -1
tools/testing/selftests/bpf/prog_tests/test_lsm.c
··· 75 75 skel->bss->monitored_pid = getpid(); 76 76 77 77 err = stack_mprotect(); 78 - if (!ASSERT_EQ(errno, EPERM, "stack_mprotect")) 78 + if (!ASSERT_EQ(err, -1, "stack_mprotect") || 79 + !ASSERT_EQ(errno, EPERM, "stack_mprotect")) 79 80 return err; 80 81 81 82 ASSERT_EQ(skel->bss->mprotect_count, 1, "mprotect_count");