summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorJosef Bacik <josef@toxicpanda.com>2026-10-17 16:37:21 +0000
committerAlexei Starovoitov <ast@kernel.org>2026-10-17 22:01:13 +0000
commit45e912fb1db00404267fafd9fd034c68b1f94622 (patch)
tree59a084b678528e6f5c011f38d9c812056080f899 /include/linux
parent13ac7c05bc45d3445b580da186548dd3487fae4e (diff)
downloadlinux-45e912fb1db00404267fafd9fd034c68b1f94622.tar.gz
linux-45e912fb1db00404267fafd9fd034c68b1f94622.zip
bpf: Check the new program of an iterator link update
The bpf_map_elem, bpf_sk_storage_map and sockmap iterators hand the key and the value of an element to the program as buffers. The verifier only records how far a program reaches into them, and ->attach_target() compares that with the key and value size of the map. bpf_iter_link_replace() does not. BPF_LINK_UPDATE installs a program that an attach refuses with -EACCES, and the program then reads, and for a value writes, behind every element that the iterator visits. It takes CAP_BPF and CAP_PERFMON, or a BPF token. Split the test out of the three ->attach_target() and ask it, as ->check_prog(), for the new program of an update as well. Targets without such a test take every program of their kind, as before. Fixes: d6c4503cc296 ("bpf: Implement bpf iterator for hash maps") Fixes: 5ce6e77c7edf ("bpf: Implement bpf iterator for sock local storage map") Fixes: 0365351524d7 ("net: Allow iterating sockmap and sockhash") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-20-alexei.starovoitov@gmail.com
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/bpf.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 46d325aa178e..3fb3c7d22d99 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -3128,6 +3128,8 @@ typedef int (*bpf_iter_attach_target_t)(struct bpf_prog *prog,
union bpf_iter_link_info *linfo,
struct bpf_iter_aux_info *aux);
typedef void (*bpf_iter_detach_target_t)(struct bpf_iter_aux_info *aux);
+typedef int (*bpf_iter_check_prog_t)(const struct bpf_prog *prog,
+ const struct bpf_iter_aux_info *aux);
typedef void (*bpf_iter_show_fdinfo_t) (const struct bpf_iter_aux_info *aux,
struct seq_file *seq);
typedef int (*bpf_iter_fill_link_info_t)(const struct bpf_iter_aux_info *aux,
@@ -3146,6 +3148,8 @@ struct bpf_iter_reg {
const char *target;
bpf_iter_attach_target_t attach_target;
bpf_iter_detach_target_t detach_target;
+ /* may the program run on what the link is attached to? */
+ bpf_iter_check_prog_t check_prog;
bpf_iter_show_fdinfo_t show_fdinfo;
bpf_iter_fill_link_info_t fill_link_info;
bpf_iter_get_func_proto_t get_func_proto;