Skip to content

Commit fcd11ff

Browse files
mykyta5Alexei Starovoitov
authored andcommitted
selftests/bpf: Reject scalar store into kptr slot
Verify that the verifier rejects a direct scalar write to a kptr map value slot without crashing. Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com> Link: https://lore.kernel.org/r/20260416-kptr_crash-v1-2-5589356584b4@meta.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 4d0a375 commit fcd11ff

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

tools/testing/selftests/bpf/progs/map_kptr_fail.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,19 @@ int kptr_xchg_possibly_null(struct __sk_buff *ctx)
385385
return 0;
386386
}
387387

388+
SEC("?tc")
389+
__failure __msg("invalid kptr access, R")
390+
int reject_scalar_store_to_kptr(struct __sk_buff *ctx)
391+
{
392+
struct map_value *v;
393+
int key = 0;
394+
395+
v = bpf_map_lookup_elem(&array_map, &key);
396+
if (!v)
397+
return 0;
398+
399+
*(volatile u64 *)&v->unref_ptr = 0xBADC0DE;
400+
return 0;
401+
}
402+
388403
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)