Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: Test accesses to ctx padding

This patch adds tests covering the various paddings in ctx structures.
In case of sk_lookup BPF programs, the behavior is a bit different
because accesses to the padding are explicitly allowed. Other cases
result in a clear reject from the verifier.

Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/3dc5f025e350aeb2bb1c257b87c577518e574aeb.1758094761.git.paul.chaignon@gmail.com

authored by

Paul Chaignon and committed by
Daniel Borkmann
180a46bc 7c60f6e4

+30
+30
tools/testing/selftests/bpf/progs/verifier_ctx.c
··· 262 262 unaligned_access("flow_dissector", __sk_buff, data); 263 263 unaligned_access("netfilter", bpf_nf_ctx, skb); 264 264 265 + #define padding_access(type, ctx, prev_field, sz) \ 266 + SEC(type) \ 267 + __description("access on " #ctx " padding after " #prev_field) \ 268 + __naked void padding_ctx_access_##ctx(void) \ 269 + { \ 270 + asm volatile (" \ 271 + r1 = *(u%[size] *)(r1 + %[off]); \ 272 + r0 = 0; \ 273 + exit;" \ 274 + : \ 275 + : __imm_const(size, sz * 8), \ 276 + __imm_const(off, offsetofend(struct ctx, prev_field)) \ 277 + : __clobber_all); \ 278 + } 279 + 280 + __failure __msg("invalid bpf_context access") 281 + padding_access("cgroup/bind4", bpf_sock_addr, msg_src_ip6[3], 4); 282 + 283 + __success 284 + padding_access("sk_lookup", bpf_sk_lookup, remote_port, 2); 285 + 286 + __failure __msg("invalid bpf_context access") 287 + padding_access("tc", __sk_buff, tstamp_type, 2); 288 + 289 + __failure __msg("invalid bpf_context access") 290 + padding_access("cgroup/post_bind4", bpf_sock, dst_port, 2); 291 + 292 + __failure __msg("invalid bpf_context access") 293 + padding_access("sk_reuseport", sk_reuseport_md, hash, 4); 294 + 265 295 char _license[] SEC("license") = "GPL";