lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20201117082638.43675-3-bjorn.topel@gmail.com>
Date:   Tue, 17 Nov 2020 09:26:37 +0100
From:   Björn Töpel <bjorn.topel@...il.com>
To:     ast@...nel.org, daniel@...earbox.net, netdev@...r.kernel.org,
        bpf@...r.kernel.org
Cc:     Björn Töpel <bjorn.topel@...il.com>,
        xi.wang@...il.com, luke.r.nels@...il.com,
        linux-riscv@...ts.infradead.org
Subject: [PATCH bpf-next 2/3] selftests/bpf: Avoid running unprivileged tests with alignment requirements

Some architectures have strict alignment requirements. In that case,
the BPF verifier detects if a program has unaligned accesses and
rejects them. A user can pass BPF_F_ANY_ALIGNMENT to a program to
override this check. That, however, will only work when a privileged
user loads a program. A unprivileged user loading a program with this
flag will be rejected prior entering the verifier.

Hence, it does not make sense to load unprivileged programs without
strict alignment when testing the verifier. This patch avoids exactly
that.

Signed-off-by: Björn Töpel <bjorn.topel@...il.com>
---
 tools/testing/selftests/bpf/test_verifier.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index 9be395d9dc64..2075f6a98813 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -1152,9 +1152,15 @@ static void get_unpriv_disabled()
 
 static bool test_as_unpriv(struct bpf_test *test)
 {
-	return !test->prog_type ||
-	       test->prog_type == BPF_PROG_TYPE_SOCKET_FILTER ||
-	       test->prog_type == BPF_PROG_TYPE_CGROUP_SKB;
+	bool req_aligned = false;
+
+#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
+	req_aligned = test->flags & F_NEEDS_EFFICIENT_UNALIGNED_ACCESS;
+#endif
+	return (!test->prog_type ||
+		test->prog_type == BPF_PROG_TYPE_SOCKET_FILTER ||
+		test->prog_type == BPF_PROG_TYPE_CGROUP_SKB) &&
+		!req_aligned;
 }
 
 static int do_test(bool unpriv, unsigned int from, unsigned int to)
-- 
2.27.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ