From: Hou Tao <houtao1@xxxxxxxxxx> Batched map operations, dumping the map content through bpffs, and iterating over each element using the bpf_for_each_map_elem() helper or the bpf map element iterator are not supported for maps with dynptr keys. Therefore, disable these operations for now. Signed-off-by: Hou Tao <houtao1@xxxxxxxxxx> --- include/linux/bpf.h | 3 ++- kernel/bpf/map_iter.c | 3 +++ kernel/bpf/syscall.c | 4 ++++ kernel/bpf/verifier.c | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 4f4b43b68f8d1..59295dd8d6fd3 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -629,7 +629,8 @@ static inline bool bpf_map_offload_neutral(const struct bpf_map *map) static inline bool bpf_map_support_seq_show(const struct bpf_map *map) { return (map->btf_value_type_id || map->btf_vmlinux_value_type_id) && - map->ops->map_seq_show_elem; + map->ops->map_seq_show_elem && + !bpf_map_has_dynptr_key(map); } int map_check_no_btf(const struct bpf_map *map, diff --git a/kernel/bpf/map_iter.c b/kernel/bpf/map_iter.c index 9575314f40a69..775d8bc63ed5d 100644 --- a/kernel/bpf/map_iter.c +++ b/kernel/bpf/map_iter.c @@ -113,6 +113,9 @@ static int bpf_iter_attach_map(struct bpf_prog *prog, if (IS_ERR(map)) return PTR_ERR(map); + if (bpf_map_has_dynptr_key(map)) + goto put_map; + if (map->map_type == BPF_MAP_TYPE_PERCPU_HASH || map->map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH || map->map_type == BPF_MAP_TYPE_PERCPU_ARRAY) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 40c3d85b06bae..24599749dc6f9 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -5508,6 +5508,10 @@ static int bpf_map_do_batch(const union bpf_attr *attr, err = -EPERM; goto err_put; } + if (bpf_map_has_dynptr_key(map)) { + err = -EOPNOTSUPP; + goto err_put; + } if (cmd == BPF_MAP_LOOKUP_BATCH) BPF_DO_BATCH(map->ops->map_lookup_batch, map, attr, uattr); diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 05a5636ae4984..fea94fcd8bf25 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -10246,6 +10246,10 @@ static int check_map_func_compatibility(struct bpf_verifier_env *env, if (map->map_type != BPF_MAP_TYPE_CGRP_STORAGE) goto error; break; + case BPF_FUNC_for_each_map_elem: + if (bpf_map_has_dynptr_key(map)) + goto error; + break; default: break; } -- 2.29.2