The sk_storage iterator exposes values as raw PTR_TO_BUF memory. Attach validation checks only the maximum access against value_size, so BPF programs can read or overwrite BTF-managed fields such as __kptr without the verifier's ownership checks. Reject value accesses when the storage map has a BTF record containing managed fields. Iterators that do not access values, and maps without managed fields, retain their existing behavior. Fixes: 9db44fdd8105 ("bpf: Support kptrs in local storage maps") Cc: stable@vger.kernel.org Reported-by: Vega Assisted-by: LLM Signed-off-by: Zhiling Zou --- net/core/bpf_sk_storage.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c index 1d295a8769fa..b54fd90d4bde 100644 --- a/net/core/bpf_sk_storage.c +++ b/net/core/bpf_sk_storage.c @@ -863,6 +863,12 @@ static int bpf_iter_attach_map(struct bpf_prog *prog, if (map->map_type != BPF_MAP_TYPE_SK_STORAGE) goto put_map; + /* The iterator exposes values as raw buffers, bypassing field checks. */ + if (map->record && prog->aux->max_rdwr_access) { + err = -EACCES; + goto put_map; + } + if (prog->aux->max_rdwr_access > map->value_size) { err = -EACCES; goto put_map; -- 2.55.0