public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Kui-Feng Lee <kuifeng@meta.com>
To: <bpf@vger.kernel.org>, <ast@kernel.org>, <martin.lau@linux.dev>,
	<song@kernel.org>, <kernel-team@meta.com>, <andrii@kernel.org>,
	<sdf@google.com>
Cc: Kui-Feng Lee <kuifeng@meta.com>
Subject: [PATCH bpf-next v4 4/9] bpf: Validate kdata of a struct_ops before transiting to READY.
Date: Tue, 7 Mar 2023 15:33:02 -0800	[thread overview]
Message-ID: <20230307233307.3626875-5-kuifeng@meta.com> (raw)
In-Reply-To: <20230307233307.3626875-1-kuifeng@meta.com>

By utilizing this check, we can avoid creating a struct_ops that
cannot be registered afterward. This way, future complications can be
avoided with ease.

Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>
---
 kernel/bpf/bpf_struct_ops.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c
index dcb7a408d4e9..c71c8d73c7ad 100644
--- a/kernel/bpf/bpf_struct_ops.c
+++ b/kernel/bpf/bpf_struct_ops.c
@@ -504,6 +504,11 @@ static int bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
 
 	set_memory_rox((long)st_map->image, 1);
 	if (st_map->map.map_flags & BPF_F_LINK) {
+		if (st_ops->validate) {
+			err = st_ops->validate(kdata);
+			if (err)
+				goto unlock;
+		}
 		/* Let bpf_link handle registration & unregistration.
 		 *
 		 * Pair with smp_load_acquire() during lookup_elem().
-- 
2.34.1


  parent reply	other threads:[~2023-03-07 23:33 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07 23:32 [PATCH bpf-next v4 0/9] Transit between BPF TCP congestion controls Kui-Feng Lee
2023-03-07 23:32 ` [PATCH bpf-next v4 1/9] bpf: Retire the struct_ops map kvalue->refcnt Kui-Feng Lee
2023-03-07 23:33 ` [PATCH bpf-next v4 2/9] bpf: Create links for BPF struct_ops maps Kui-Feng Lee
2023-03-08  0:37   ` Andrii Nakryiko
2023-03-08  1:11     ` Kui-Feng Lee
2023-03-07 23:33 ` [PATCH bpf-next v4 3/9] net: Update an existing TCP congestion control algorithm Kui-Feng Lee
2023-03-07 23:33 ` Kui-Feng Lee [this message]
2023-03-07 23:33 ` [PATCH bpf-next v4 5/9] libbpf: Create a bpf_link in bpf_map__attach_struct_ops() Kui-Feng Lee
2023-03-08  0:46   ` Andrii Nakryiko
2023-03-08  3:33     ` Kui-Feng Lee
2023-03-07 23:33 ` [PATCH bpf-next v4 6/9] bpf: Update the struct_ops of a bpf_link Kui-Feng Lee
2023-03-08  0:49   ` Andrii Nakryiko
2023-03-08 16:27     ` Kui-Feng Lee
2023-03-07 23:33 ` [PATCH bpf-next v4 7/9] libbpf: Update a bpf_link with another struct_ops Kui-Feng Lee
2023-03-08  0:53   ` Andrii Nakryiko
2023-03-08  1:45     ` Kui-Feng Lee
2023-03-07 23:33 ` [PATCH bpf-next v4 8/9] libbpf: Use .struct_ops.link section to indicate a struct_ops with a link Kui-Feng Lee
2023-03-08  1:07   ` Andrii Nakryiko
2023-03-08  4:23     ` Kui-Feng Lee
2023-03-07 23:33 ` [PATCH bpf-next v4 9/9] selftests/bpf: Test switching TCP Congestion Control algorithms Kui-Feng Lee
2023-03-08  1:10   ` Andrii Nakryiko
2023-03-08 15:58     ` Kui-Feng Lee
2023-03-08 17:18       ` Andrii Nakryiko
2023-03-08 18:10         ` Kui-Feng Lee
2023-03-08 18:43           ` Andrii Nakryiko

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=20230307233307.3626875-5-kuifeng@meta.com \
    --to=kuifeng@meta.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kernel-team@meta.com \
    --cc=martin.lau@linux.dev \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    /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