[PATCH mptcp-next v3 04/10] Squash to "mptcp: add bpf_mptcp_sched_ops"

Geliang Tang posted 10 patches 3 years, 3 months ago
Maintainers: Mat Martineau <mathew.j.martineau@linux.intel.com>, Andrii Nakryiko <andrii@kernel.org>, John Fastabend <john.fastabend@gmail.com>, Yonghong Song <yhs@fb.com>, Jakub Kicinski <kuba@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Song Liu <songliubraving@fb.com>, "David S. Miller" <davem@davemloft.net>, KP Singh <kpsingh@kernel.org>, Shuah Khan <shuah@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Matthieu Baerts <matthieu.baerts@tessares.net>, Martin KaFai Lau <kafai@fb.com>, Eric Dumazet <edumazet@google.com>, Alexei Starovoitov <ast@kernel.org>
There is a newer version of this series
[PATCH mptcp-next v3 04/10] Squash to "mptcp: add bpf_mptcp_sched_ops"
Posted by Geliang Tang 3 years, 3 months ago
Drop the access code for mptcp_sched_data.

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 net/mptcp/bpf.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c
index 338146d173f4..4f4559d37f9e 100644
--- a/net/mptcp/bpf.c
+++ b/net/mptcp/bpf.c
@@ -33,6 +33,12 @@ bpf_mptcp_sched_get_func_proto(enum bpf_func_id func_id,
 	return bpf_base_func_proto(func_id);
 }
 
+static size_t subflow_offset(int i)
+{
+	return offsetof(struct mptcp_sched_data, subflows) +
+	       i * sizeof(struct mptcp_sched_subflow);
+}
+
 static int bpf_mptcp_sched_btf_struct_access(struct bpf_verifier_log *log,
 					     const struct btf *btf,
 					     const struct btf_type *t, int off,
@@ -40,36 +46,30 @@ static int bpf_mptcp_sched_btf_struct_access(struct bpf_verifier_log *log,
 					     u32 *next_btf_id,
 					     enum bpf_type_flag *flag)
 {
-	size_t end;
+	size_t start, end, soff;
+	int i;
 
-	if (atype == BPF_READ)
+	if (atype == BPF_READ) {
 		return btf_struct_access(log, btf, t, off, size, atype,
 					 next_btf_id, flag);
+	}
 
 	if (t != mptcp_sched_type) {
 		bpf_log(log, "only access to mptcp_sched_data is supported\n");
 		return -EACCES;
 	}
 
-	switch (off) {
-	case offsetof(struct mptcp_sched_data, sock):
-		end = offsetofend(struct mptcp_sched_data, sock);
-		break;
-	case offsetof(struct mptcp_sched_data, call_again):
-		end = offsetofend(struct mptcp_sched_data, call_again);
-		break;
-	default:
-		bpf_log(log, "no write support to mptcp_sched_data at off %d\n", off);
-		return -EACCES;
-	}
+	start = offsetof(struct mptcp_sched_subflow, is_scheduled);
+	end = offsetofend(struct mptcp_sched_subflow, is_scheduled);
 
-	if (off + size > end) {
-		bpf_log(log, "access beyond mptcp_sched_data at off %u size %u ended at %zu",
-			off, size, end);
-		return -EACCES;
+	for (i = 0; i < MPTCP_SUBFLOWS_MAX; i++) {
+		soff = subflow_offset(i);
+		if (off == soff + start && off + size <= soff + end)
+			return NOT_INIT; /* offsets match up with is_scheduled */
 	}
 
-	return NOT_INIT;
+	bpf_log(log, "no write support to mptcp_sched_data at off %d\n", off);
+	return -EACCES;
 }
 
 static const struct bpf_verifier_ops bpf_mptcp_sched_verifier_ops = {
-- 
2.34.1