[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221207172434.435893-7-roberto.sassu@huaweicloud.com>
Date: Wed, 7 Dec 2022 18:24:33 +0100
From: Roberto Sassu <roberto.sassu@...weicloud.com>
To: ast@...nel.org, daniel@...earbox.net, andrii@...nel.org,
martin.lau@...ux.dev, song@...nel.org, yhs@...com,
john.fastabend@...il.com, kpsingh@...nel.org, sdf@...gle.com,
haoluo@...gle.com, jolsa@...nel.org, revest@...omium.org,
jackmanb@...omium.org, mykolal@...com, paul@...l-moore.com,
jmorris@...ei.org, serge@...lyn.com, shuah@...nel.org
Cc: bpf@...r.kernel.org, linux-security-module@...r.kernel.org,
linux-kselftest@...r.kernel.org, linux-kernel@...r.kernel.org,
Roberto Sassu <roberto.sassu@...wei.com>
Subject: [RFC][PATCH v2 6/7] selftests/bpf: Prevent positive ret values in test_lsm and verify_pkcs7_sig
From: Roberto Sassu <roberto.sassu@...wei.com>
Modify test_lsm and verify_pkcs7_sig to ensure that they don't return
positive values.
Signed-off-by: Roberto Sassu <roberto.sassu@...wei.com>
---
tools/testing/selftests/bpf/progs/lsm.c | 4 ++++
.../selftests/bpf/progs/test_verify_pkcs7_sig.c | 11 +++++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/lsm.c b/tools/testing/selftests/bpf/progs/lsm.c
index d8d8af623bc2..42252750d866 100644
--- a/tools/testing/selftests/bpf/progs/lsm.c
+++ b/tools/testing/selftests/bpf/progs/lsm.c
@@ -88,6 +88,10 @@ SEC("lsm/file_mprotect")
int BPF_PROG(test_int_hook, struct vm_area_struct *vma,
unsigned long reqprot, unsigned long prot, int ret)
{
+ /* file_mprotect hook must return zero or negative values. */
+ if (ret > 0)
+ ret = -EINVAL;
+
if (ret != 0)
return ret;
diff --git a/tools/testing/selftests/bpf/progs/test_verify_pkcs7_sig.c b/tools/testing/selftests/bpf/progs/test_verify_pkcs7_sig.c
index ce419304ff1f..d3cab4370f29 100644
--- a/tools/testing/selftests/bpf/progs/test_verify_pkcs7_sig.c
+++ b/tools/testing/selftests/bpf/progs/test_verify_pkcs7_sig.c
@@ -42,14 +42,14 @@ struct {
char _license[] SEC("license") = "GPL";
SEC("lsm.s/bpf")
-int BPF_PROG(bpf, int cmd, union bpf_attr *attr, unsigned int size)
+s64 BPF_PROG(bpf, int cmd, union bpf_attr *attr, unsigned int size)
{
struct bpf_dynptr data_ptr, sig_ptr;
struct data *data_val;
struct bpf_key *trusted_keyring;
__u32 pid;
__u64 value;
- int ret, zero = 0;
+ s64 ret, zero = 0;
pid = bpf_get_current_pid_tgid() >> 32;
if (pid != monitored_pid)
@@ -86,5 +86,12 @@ int BPF_PROG(bpf, int cmd, union bpf_attr *attr, unsigned int size)
bpf_key_put(trusted_keyring);
+ /*
+ * bpf hook must return zero or negative values, use s64 to propagate
+ * the bounds to R0.
+ */
+ if (ret > 0)
+ return -EINVAL;
+
return ret;
}
--
2.25.1
Powered by blists - more mailing lists