Skip to content

Commit 73e4f9e

Browse files
ThinkerYzu1Martin KaFai Lau
authored andcommitted
bpf, net: validate struct_ops when updating value.
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>
1 parent 01031fd commit 73e4f9e

2 files changed

Lines changed: 7 additions & 10 deletions

File tree

kernel/bpf/bpf_struct_ops.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -672,13 +672,14 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
672672
*(unsigned long *)(udata + moff) = prog->aux->id;
673673
}
674674

675+
if (st_ops->validate) {
676+
err = st_ops->validate(kdata);
677+
if (err)
678+
goto reset_unlock;
679+
}
680+
675681
if (st_map->map.map_flags & BPF_F_LINK) {
676682
err = 0;
677-
if (st_ops->validate) {
678-
err = st_ops->validate(kdata);
679-
if (err)
680-
goto reset_unlock;
681-
}
682683
arch_protect_bpf_trampoline(st_map->image, PAGE_SIZE);
683684
/* Let bpf_link handle registration & unregistration.
684685
*

net/ipv4/tcp_cong.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,7 @@ EXPORT_SYMBOL_GPL(tcp_unregister_congestion_control);
146146
int tcp_update_congestion_control(struct tcp_congestion_ops *ca, struct tcp_congestion_ops *old_ca)
147147
{
148148
struct tcp_congestion_ops *existing;
149-
int ret;
150-
151-
ret = tcp_validate_congestion_control(ca);
152-
if (ret)
153-
return ret;
149+
int ret = 0;
154150

155151
ca->key = jhash(ca->name, sizeof(ca->name), strlen(ca->name));
156152

0 commit comments

Comments
 (0)