From nobody Tue Feb 10 04:14:17 2026 Received: from mx-rz-1.rrze.uni-erlangen.de (mx-rz-1.rrze.uni-erlangen.de [131.188.11.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5F731362; Mon, 21 Apr 2025 09:30:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=131.188.11.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745227821; cv=none; b=BFDryYuiCzLQLEDInq8ss17m2QNC4R/L6W+aGcZKYMeXJUHZt+VdxT+PGYZn73MCkmidPKw3Tu7/X/4/4kmrVUAvyLxrf4mpSf5wRfNlvcmPdYPjTmB7h3Kxa2PpRAKgYBWD1speg8RVD3L1dE3JNmTOg797uMlaf5jB6hdXFj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745227821; c=relaxed/simple; bh=hkrlTZ62WZIbf+MUF5R0plLe7rX+Hn2FPe/EawkV0eM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YRAgRqTO0+TsjuuYFEWSWpStqC+fauMtzPDhQGb/fVEZMZFqUvQ2UdjPbKDl7qWADFcypSreKO9P4vPGCeXeCif9CrzI7Zw+h/87wq3Gn5TV53g+rkM4EvTc9NOJ++Lb0xjeXSk/bvCnCX9zMFnNZUhlQgP8oYuy5d5JhcjM8Ac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fau.de; spf=pass smtp.mailfrom=fau.de; dkim=pass (2048-bit key) header.d=fau.de header.i=@fau.de header.b=Q58yTLNi; arc=none smtp.client-ip=131.188.11.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fau.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fau.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fau.de header.i=@fau.de header.b="Q58yTLNi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fau.de; s=fau-2021; t=1745227355; bh=x1254cGxcCub/kUQM5hyyDzmObtkQ9/oIwWSNnQPgK4=; h=From:To:Subject:Date:In-Reply-To:References:From:To:CC:Subject; b=Q58yTLNirc90MfQQmv3WZEWQgKgv39jvjR97S0Dw+0pZfWRtR27c0n9QrGk1swR8W Gbj4HXZOqEx88TVx8IGnXx+aj5A9F9ry9SEhG6neNxgkZMHDJLbSYZIwzFGhZkMBHp f1k81ShqLHH40k9ku7EZdXZUqUQ1+h8wKGRG5G3JaLlYc5Ncc4bYUHC57V/qVX1hlQ DYy9ak2pisCyBhkqry46aUBQ/UoOhDLLG4NMm+nIxnKZrZh4KgaUDLe6tJ8WrEfO/h scoiDfhNE39CsAz9fjvUQoQ0f6mgk4vvbflb8X/df2LZ70TznkKE1KqhuguWnYhDhv 65U0kRlQ/6GLA== Received: from mx-rz-smart.rrze.uni-erlangen.de (mx-rz-smart.rrze.uni-erlangen.de [IPv6:2001:638:a000:1025::1e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-rz-1.rrze.uni-erlangen.de (Postfix) with ESMTPS id 4Zh0JW2BHRz8sv4; Mon, 21 Apr 2025 11:22:35 +0200 (CEST) X-Virus-Scanned: amavisd-new at boeck1.rrze.uni-erlangen.de (RRZE) X-RRZE-Flag: Not-Spam X-RRZE-Submit-IP: 2001:9e8:3600:7e00:5b67:6b9c:caeb:75c Received: from luis-tp.fritz.box (unknown [IPv6:2001:9e8:3600:7e00:5b67:6b9c:caeb:75c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: U2FsdGVkX19/Cw3SxbY0NrcDswZrJkba51HAa62QSVk=) by smtp-auth.uni-erlangen.de (Postfix) with ESMTPSA id 4Zh0JR6bnNz8sx9; Mon, 21 Apr 2025 11:22:31 +0200 (CEST) From: Luis Gerhorst To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Puranjay Mohan , Xu Kuohai , Catalin Marinas , Will Deacon , Hari Bathini , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Mykola Lysenko , Shuah Khan , Luis Gerhorst , Henriette Herzog , Saket Kumar Bhaskar , Cupertino Miranda , Jiayuan Chen , Matan Shachnai , Dimitar Kanaliev , Shung-Hsi Yu , Daniel Xu , bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v2 01/11] selftests/bpf: Fix caps for __xlated/jited_unpriv Date: Mon, 21 Apr 2025 11:17:52 +0200 Message-ID: <20250421091802.3234859-2-luis.gerhorst@fau.de> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250421091802.3234859-1-luis.gerhorst@fau.de> References: <20250421091802.3234859-1-luis.gerhorst@fau.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, __xlated_unpriv and __jited_unpriv do not work because the BPF syscall will overwrite info.jited_prog_len and info.xlated_prog_len with 0 if the process is not bpf_capable(). This bug was not noticed before, because there is no test that actually uses __xlated_unpriv/__jited_unpriv. To resolve this, simply restore the capabilities earlier (but still after loading the program). Adding this here unconditionally is fine because the function first checks that the capabilities were initialized before attempting to restore them. This will be important later when we add tests that check whether a speculation barrier was inserted in the correct location. Signed-off-by: Luis Gerhorst Fixes: 9c9f73391310 ("selftests/bpf: allow checking xlated programs in veri= fier_* tests") Fixes: 7d743e4c759c ("selftests/bpf: __jited test tag to check disassembly = after jit") --- tools/testing/selftests/bpf/test_loader.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/test_loader.c b/tools/testing/self= tests/bpf/test_loader.c index 49f2fc61061f..9551d8d5f8f9 100644 --- a/tools/testing/selftests/bpf/test_loader.c +++ b/tools/testing/selftests/bpf/test_loader.c @@ -1042,6 +1042,14 @@ void run_subtest(struct test_loader *tester, emit_verifier_log(tester->log_buf, false /*force*/); validate_msgs(tester->log_buf, &subspec->expect_msgs, emit_verifier_log); =20 + /* Restore capabilities because the kernel will silently ignore requests + * for program info (such as xlated program text) if we are not + * bpf-capable. Also, for some reason test_verifier executes programs + * with all capabilities restored. Do the same here. + */ + if (restore_capabilities(&caps)) + goto tobj_cleanup; + if (subspec->expect_xlated.cnt) { err =3D get_xlated_program_text(bpf_program__fd(tprog), tester->log_buf, tester->log_buf_sz); @@ -1067,12 +1075,6 @@ void run_subtest(struct test_loader *tester, } =20 if (should_do_test_run(spec, subspec)) { - /* For some reason test_verifier executes programs - * with all capabilities restored. Do the same here. - */ - if (restore_capabilities(&caps)) - goto tobj_cleanup; - /* Do bpf_map__attach_struct_ops() for each struct_ops map. * This should trigger bpf_struct_ops->reg callback on kernel side. */ --=20 2.49.0