From: Eduard Zingerman <eddyz87@gmail.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@kernel.org>,
Tao Lyu <tao.lyu@epfl.ch>,
Mathias Payer <mathias.payer@nebelwelt.net>,
Meng Xu <meng.xu.cs@uwaterloo.ca>,
Sanidhya Kashyap <sanidhya.kashyap@epfl.ch>
Subject: Re: [PATCH bpf-next v2 3/4] selftests/bpf: Add test for reading from STACK_INVALID slots
Date: Wed, 27 Nov 2024 17:50:48 -0800 [thread overview]
Message-ID: <f0fbf1268f34b3eb7b74359dc11ec4299f5d77ad.camel@gmail.com> (raw)
In-Reply-To: <20241127212026.3580542-4-memxor@gmail.com>
On Wed, 2024-11-27 at 13:20 -0800, Kumar Kartikeya Dwivedi wrote:
> Ensure that when CAP_PERFMON is dropped, and the verifier sees
> allow_ptr_leaks as false, we are not permitted to read from a
> STACK_INVALID slot. Without the fix, the test will report unexpected
> success in loading.
>
> Since we need to control the capabilities when loading this test to only
> retain CAP_BPF, refactor support added to do the same for
> test_verifier_mtu and reuse it for this selftest to avoid copy-paste.
>
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> ---
> .../selftests/bpf/prog_tests/verifier.c | 41 ++++++++++++++++---
> .../bpf/progs/verifier_stack_noperfmon.c | 21 ++++++++++
> 2 files changed, 56 insertions(+), 6 deletions(-)
> create mode 100644 tools/testing/selftests/bpf/progs/verifier_stack_noperfmon.c
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/testing/selftests/bpf/prog_tests/verifier.c
> index d9f65adb456b..aaf4324e8ef0 100644
> --- a/tools/testing/selftests/bpf/prog_tests/verifier.c
> +++ b/tools/testing/selftests/bpf/prog_tests/verifier.c
> @@ -63,6 +63,7 @@
> #include "verifier_prevent_map_lookup.skel.h"
> #include "verifier_private_stack.skel.h"
> #include "verifier_raw_stack.skel.h"
> +#include "verifier_stack_noperfmon.skel.h"
> #include "verifier_raw_tp_writable.skel.h"
> #include "verifier_reg_equal.skel.h"
> #include "verifier_ref_tracking.skel.h"
> @@ -226,22 +227,50 @@ void test_verifier_xdp_direct_packet_access(void) { RUN(verifier_xdp_direct_pack
> void test_verifier_bits_iter(void) { RUN(verifier_bits_iter); }
> void test_verifier_lsm(void) { RUN(verifier_lsm); }
>
> -void test_verifier_mtu(void)
> +static int test_verifier_disable_caps(__u64 *caps)
The original thread [0] discusses __caps_unpriv macro.
I'd prefer such macro over these changes to prog_tests/verifier.c,
were there any technical problems with code suggested in [0]?
[0] https://lore.kernel.org/bpf/a1e48f5d9ae133e19adc6adf27e19d585e06bab4.camel@gmail.com/#t
> {
> - __u64 caps = 0;
> int ret;
>
> /* In case CAP_BPF and CAP_PERFMON is not set */
> - ret = cap_enable_effective(1ULL << CAP_BPF | 1ULL << CAP_NET_ADMIN, &caps);
> + ret = cap_enable_effective(1ULL << CAP_BPF | 1ULL << CAP_NET_ADMIN, caps);
> if (!ASSERT_OK(ret, "set_cap_bpf_cap_net_admin"))
> - return;
> + return -EINVAL;
> ret = cap_disable_effective(1ULL << CAP_SYS_ADMIN | 1ULL << CAP_PERFMON, NULL);
> if (!ASSERT_OK(ret, "disable_cap_sys_admin"))
> + return -EINVAL;
> + return 0;
> +}
[...]
next prev parent reply other threads:[~2024-11-28 1:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-27 21:20 [PATCH bpf-next v2 0/4] Fixes for stack with allow_ptr_leaks Kumar Kartikeya Dwivedi
2024-11-27 21:20 ` [PATCH bpf-next v2 1/4] bpf: Don't relax STACK_INVALID to STACK_MISC when not allow_ptr_leaks Kumar Kartikeya Dwivedi
2024-11-28 1:09 ` Eduard Zingerman
2024-11-27 21:20 ` [PATCH bpf-next v2 2/4] bpf: Fix narrow scalar spill onto 64-bit spilled scalar slots Kumar Kartikeya Dwivedi
2024-11-28 1:21 ` Eduard Zingerman
2024-11-27 21:20 ` [PATCH bpf-next v2 3/4] selftests/bpf: Add test for reading from STACK_INVALID slots Kumar Kartikeya Dwivedi
2024-11-28 1:50 ` Eduard Zingerman [this message]
2024-11-28 1:57 ` Kumar Kartikeya Dwivedi
2024-11-28 2:01 ` Eduard Zingerman
2024-11-28 2:07 ` Kumar Kartikeya Dwivedi
2024-11-27 21:20 ` [PATCH bpf-next v2 4/4] selftests/bpf: Add test for narrow spill into 64-bit spilled scalar Kumar Kartikeya Dwivedi
2024-11-28 1:56 ` Eduard Zingerman
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=f0fbf1268f34b3eb7b74359dc11ec4299f5d77ad.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=martin.lau@kernel.org \
--cc=mathias.payer@nebelwelt.net \
--cc=memxor@gmail.com \
--cc=meng.xu.cs@uwaterloo.ca \
--cc=sanidhya.kashyap@epfl.ch \
--cc=tao.lyu@epfl.ch \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox