All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>
Cc: bpf@vger.kernel.org, Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PATCH bpf-next v2 12/31] selftests/bpf: Check stack_mprotect() return value
Date: Sat, 28 Jan 2023 01:06:31 +0100	[thread overview]
Message-ID: <20230128000650.1516334-13-iii@linux.ibm.com> (raw)
In-Reply-To: <20230128000650.1516334-1-iii@linux.ibm.com>

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>
---
 tools/testing/selftests/bpf/prog_tests/bpf_cookie.c | 6 ++++--
 tools/testing/selftests/bpf/prog_tests/test_lsm.c   | 3 ++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
index 2be2d61954bc..26b2d1bffdfd 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
@@ -472,6 +472,7 @@ static void lsm_subtest(struct test_bpf_cookie *skel)
 	int prog_fd;
 	int lsm_fd = -1;
 	LIBBPF_OPTS(bpf_link_create_opts, link_opts);
+	int err;
 
 	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"))
 		goto cleanup;
 
-	stack_mprotect();
-	if (!ASSERT_EQ(errno, EPERM, "stack_mprotect"))
+	err = stack_mprotect();
+	if (!ASSERT_EQ(err, -1, "stack_mprotect") ||
+	    !ASSERT_EQ(errno, EPERM, "stack_mprotect"))
 		goto cleanup;
 
 	usleep(1);
diff --git a/tools/testing/selftests/bpf/prog_tests/test_lsm.c b/tools/testing/selftests/bpf/prog_tests/test_lsm.c
index 244c01125126..16175d579bc7 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_lsm.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_lsm.c
@@ -75,7 +75,8 @@ static int test_lsm(struct lsm *skel)
 	skel->bss->monitored_pid = getpid();
 
 	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;
 
 	ASSERT_EQ(skel->bss->mprotect_count, 1, "mprotect_count");
-- 
2.39.1


  parent reply	other threads:[~2023-01-28  0:07 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-28  0:06 [PATCH bpf-next v2 00/31] Support bpf trampoline for s390x Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 01/31] bpf: Use ARG_CONST_SIZE_OR_ZERO for 3rd argument of bpf_tcp_raw_gen_syncookie_ipv{4,6}() Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 02/31] bpf: Change BPF_MAX_TRAMP_LINKS to enum Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 03/31] selftests/bpf: Query BPF_MAX_TRAMP_LINKS using BTF Ilya Leoshkevich
2023-01-28 20:49   ` Alexei Starovoitov
2023-01-29  1:50     ` Alexei Starovoitov
2023-01-28  0:06 ` [PATCH bpf-next v2 04/31] selftests/bpf: Fix liburandom_read.so linker error Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 05/31] selftests/bpf: Fix symlink creation error Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 06/31] selftests/bpf: Fix kfree_skb on s390x Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 07/31] selftests/bpf: Set errno when urand_spawn() fails Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 08/31] selftests/bpf: Fix decap_sanity_ns cleanup Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 09/31] selftests/bpf: Fix verify_pkcs7_sig on s390x Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 10/31] selftests/bpf: Fix xdp_do_redirect " Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 11/31] selftests/bpf: Fix cgrp_local_storage " Ilya Leoshkevich
2023-01-28  0:06 ` Ilya Leoshkevich [this message]
2023-01-28  0:06 ` [PATCH bpf-next v2 13/31] selftests/bpf: Increase SIZEOF_BPF_LOCAL_STORAGE_ELEM " Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 14/31] selftests/bpf: Add a sign-extension test for kfuncs Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 15/31] selftests/bpf: Fix test_lsm on s390x Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 16/31] selftests/bpf: Fix test_xdp_adjust_tail_grow2 " Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 17/31] selftests/bpf: Fix vmlinux test " Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 18/31] selftests/bpf: Fix sk_assign " Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 19/31] selftests/bpf: Fix xdp_synproxy/tc " Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 20/31] selftests/bpf: Fix profiler " Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 21/31] libbpf: Simplify barrier_var() Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 22/31] libbpf: Fix unbounded memory access in bpf_usdt_arg() Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 23/31] libbpf: Fix BPF_PROBE_READ{_STR}_INTO() on s390x Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 24/31] bpf: iterators: Split iterators.lskel.h into little- and big- endian versions Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 25/31] bpf: btf: Add BTF_FMODEL_SIGNED_ARG flag Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 26/31] s390/bpf: Fix a typo in a comment Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 27/31] s390/bpf: Add expoline to tail calls Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 28/31] s390/bpf: Implement bpf_arch_text_poke() Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 29/31] s390/bpf: Implement arch_prepare_bpf_trampoline() Ilya Leoshkevich
2023-01-28  8:37   ` kernel test robot
2023-01-28  0:06 ` [PATCH bpf-next v2 30/31] s390/bpf: Implement bpf_jit_supports_subprog_tailcalls() Ilya Leoshkevich
2023-01-28  0:06 ` [PATCH bpf-next v2 31/31] s390/bpf: Implement bpf_jit_supports_kfunc_call() Ilya Leoshkevich
2023-01-28 20:50 ` [PATCH bpf-next v2 00/31] Support bpf trampoline for s390x patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230128000650.1516334-13-iii@linux.ibm.com \
    --to=iii@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.