Netdev List
 help / color / mirror / Atom feed
From: Zicheng Qu <quzicheng@huawei.com>
To: <kernel@openeuler.org>
Cc: <tanghui20@huawei.com>, <quzicheng@huawei.com>,
	<quzicheng315@163.com>, Kui-Feng Lee <thinker.li@gmail.com>,
	<netdev@vger.kernel.org>,
	"Martin KaFai Lau" <martin.lau@kernel.org>,
	Luo Gengkun <luogengkun2@huawei.com>
Subject: [PATCH OLK-6.6 086/451] bpf, net: validate struct_ops when updating value.
Date: Fri, 3 Apr 2026 07:27:21 +0000	[thread overview]
Message-ID: <20260403073326.3096906-87-quzicheng@huawei.com> (raw)
In-Reply-To: <20260403073326.3096906-1-quzicheng@huawei.com>

From: Kui-Feng Lee <thinker.li@gmail.com>

mainline inclusion
from mainline-v6.9-rc1
commit 73e4f9e615d7b99f39663d4722dc73e8fa5db5f9
category: feature
bugzilla: https://atomgit.com/openeuler/kernel/issues/8335
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=73e4f9e615d7b99f39663d4722dc73e8fa5db5f9

----------------------------------------------------------------------

Perform all validations when updating values of struct_ops maps. Doing
validation in st_ops->reg() and st_ops->update() is not necessary anymore.
However, tcp_register_congestion_control() has been called in various
places. It still needs to do validations.

Cc: netdev@vger.kernel.org
Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
Link: https://lore.kernel.org/r/20240224223418.526631-2-thinker.li@gmail.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Luo Gengkun <luogengkun2@huawei.com>
---
 kernel/bpf/bpf_struct_ops.c | 11 ++++++-----
 net/ipv4/tcp_cong.c         |  6 +-----
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c
index 0d7be97a2411..c244ed5114fd 100644
--- a/kernel/bpf/bpf_struct_ops.c
+++ b/kernel/bpf/bpf_struct_ops.c
@@ -667,13 +667,14 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
 		*(unsigned long *)(udata + moff) = prog->aux->id;
 	}
 
+	if (st_ops->validate) {
+		err = st_ops->validate(kdata);
+		if (err)
+			goto reset_unlock;
+	}
+
 	if (st_map->map.map_flags & BPF_F_LINK) {
 		err = 0;
-		if (st_ops->validate) {
-			err = st_ops->validate(kdata);
-			if (err)
-				goto reset_unlock;
-		}
 		arch_protect_bpf_trampoline(st_map->image, PAGE_SIZE);
 		/* Let bpf_link handle registration & unregistration.
 		 *
diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c
index 95dbb2799be4..48617d99abb0 100644
--- a/net/ipv4/tcp_cong.c
+++ b/net/ipv4/tcp_cong.c
@@ -145,11 +145,7 @@ EXPORT_SYMBOL_GPL(tcp_unregister_congestion_control);
 int tcp_update_congestion_control(struct tcp_congestion_ops *ca, struct tcp_congestion_ops *old_ca)
 {
 	struct tcp_congestion_ops *existing;
-	int ret;
-
-	ret = tcp_validate_congestion_control(ca);
-	if (ret)
-		return ret;
+	int ret = 0;
 
 	ca->key = jhash(ca->name, sizeof(ca->name), strlen(ca->name));
 
-- 
2.34.1


      parent reply	other threads:[~2026-04-03  7:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260403073326.3096906-1-quzicheng@huawei.com>
2026-04-03  7:26 ` [PATCH OLK-6.6 048/451] bpf, net: introduce bpf_struct_ops_desc Zicheng Qu
2026-04-03  7:26 ` [PATCH OLK-6.6 058/451] bpf, net: switch to dynamic registration Zicheng Qu
2026-04-03  7:27 ` Zicheng Qu [this message]

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=20260403073326.3096906-87-quzicheng@huawei.com \
    --to=quzicheng@huawei.com \
    --cc=kernel@openeuler.org \
    --cc=luogengkun2@huawei.com \
    --cc=martin.lau@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=quzicheng315@163.com \
    --cc=tanghui20@huawei.com \
    --cc=thinker.li@gmail.com \
    /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