Subject: bpf: tail-call targets bypass max_ctx_offset checks on raw_tp and tracepoint paths (OOB read, KASAN splat) The verifier records the furthest ctx byte a program may read in prog->aux->max_ctx_offset, and the raw_tp test_run, raw_tp attach, and tracepoint attach paths each refuse a program whose max_ctx_offset exceeds the ctx actually available. Every one of those checks looks only at the program being run or attached; a PROG_ARRAY tail-call target is never checked. A caller that never touches ctx keeps max_ctx_offset = 0, passes the gate, and tail-calls a target that reads far past the real buffer. Commit 08c987904970 ("bpf: Give a syscall program the largest context when it does tail calls") closed this for the SYSCALL test_run path only. Verified live on bpf-next HEAD 289cd43f93ed (2026-12-03, Linux 7.4.0-rc4), x86-64, KASAN + BPF_JIT_KASAN. ---------------------------------------------------------------------- Path 1: raw_tp test_run (net/bpf/test_run.c, bpf_prog_test_run_raw_tp) ctx = memdup_user(ctx_in, ctx_size_in) with no tail_call_reachable padding. Caller (max_ctx_offset 0) -> mid -> target (reads 96 bytes): BUG: KASAN: slab-out-of-bounds in bpf_prog_..._target+0x2a/0x259 Read of size 8 at addr ffff88810486a818 by task ld-linux-x86-64/104 Not tainted 7.4.0-rc4-g289cd43f93ed #4 bpf_prog_..._target+0x2a/0x259 __bpf_prog_test_run_raw_tp+0x5b8/0x900 bpf_prog_test_run_raw_tp+0x42f/0x7e0 __sys_bpf+0x114e/0x5420 __x64_sys_bpf+0xd5/0x1f0 The buggy address belongs to the cache memdup_user-8 of size 8 The buggy address is located 16 bytes to the right of allocated 8-byte region [ffff88810486a800, ffff88810486a808) ---------------------------------------------------------------------- Path 2: raw_tp attach (kernel/trace/bpf_trace.c, bpf_probe_register) Caller attached to sched_switch (3 args, 24-byte stack buffer) tail-calls a target reading 96 bytes: BUG: KASAN: stack-out-of-bounds in bpf_prog_..._target+0x2e0/0x775 Read of size 8 at addr ffffc9000064f200 by task ld-linux-x86-64/112 Not tainted 7.4.0-rc4-g289cd43f93ed #4 bpf_prog_..._target+0x2e0/0x775 bpf_trace_run4+0x641/0xaa0 __schedule+0x1735/0x40f0 The buggy address belongs to stack of task ld-linux-x86-64/112 and is located at offset 128 in frame: This frame has 2 objects: [32, 64) 'run_ctx' [96, 128) 'args' <- read starts at the first byte past 'args' ---------------------------------------------------------------------- Path 3: tracepoint attach (kernel/events/core.c, __perf_event_set_bpf_prog; check is max_ctx_offset > tp arg size, attached program only). Caller on sys_enter_nanosleep (32-byte stack buffer). With an 800-byte read the target program trips KASAN and then crashes the kernel, on a clean boot: BUG: KASAN: stack-out-of-bounds in bpf_prog_..._target+0x4ae/0x211e Read of size 8 at addr ffffc9000067fda0 by task ld-linux-x86-64/105 Not tainted 7.4.0-rc4-g289cd43f93ed-dirty #5 bpf_prog_..._target+0x4ae/0x211e trace_call_bpf_faultable+0x745/0xaf0 perf_call_bpf_enter+0x167/0x2b0 perf_syscall_enter+0x334/0xcd0 trace_syscall_enter+0x62/0xb0 do_syscall_64+0x41f/0x4d0 BUG: unable to handle page fault for address: ffffc90000680000 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page Oops: 0000 [#1] SMP KASAN NOPTI RIP: 0010:bpf_prog_..._target+0x1de7/0x211e trace_call_bpf_faultable+0x745/0xaf0 perf_syscall_enter+0x334/0xcd0 Note that trace_call_bpf_faultable() does not contain the read: the JITed target's plain ctx loads are not covered by the faultable wrapper, so the window runs off the task's vmalloc stack into the guard page. This variant is therefore both a silent infoleak at small windows and a reliable kernel crash at larger ones. ---------------------------------------------------------------------- Reproducers (CAP_BPF+CAP_PERFMON): make && ./rawtp_chain_leak ; ./rawtp_attach_leak ; ./tp_attach_bypass [sources attached] ---------------------------------------------------------------------- Analysis: All three gates validate only the attached/run program: net/bpf/test_run.c:796 ctx_size_in < prog->aux->max_ctx_offset net/bpf/test_run.c:808 memdup_user(ctx_in, ctx_size_in), no pad kernel/trace/bpf_trace.c:2209 max_ctx_offset > num_args*8 (attach) kernel/events/core.c:11896 max_ctx_offset > off (attach) prog_fd_array_get_ptr() / __bpf_prog_map_compatible() gate tail-call targets on program type, sleepable, hook key, cgroup storage, but never on max_ctx_offset.vmax_ctx_offset was never added to that list. 08c987904970 fixed the SYSCALL test_run instance of the same field, but the other three paths were out of its scope. Suggested fix: Path 1: apply 08c987904970's treatment to bpf_prog_test_run_raw_tp() (kvzalloc + pad to the max when the run program is tail_call_reachable, mirroring the syscall path's ctx_size_in < U16_MAX rejection). Paths 2+3 are the design question: the buffer size is a property of the hook, the requirement a property of arbitrary future tail-call targets. Options: (a) inflate the caller's max_ctx_offset to U32_MAX when it contains bpf_tail_call (the fixup_tail_calls pattern; correct but makes every tail-calling raw_tp/tp program unattachable). (b) zero-pad the on-stack arg buffers (bpf_trace_runN, perf/tp enter) for tail-call-reachable callers. (c) carry the real ctx size in the run context and bounds-check at tail-call entry. The gap exists since PROG_ARRAY tail calls (04fd61ab36ec, 2015) met the max_ctx_offset checks. Every current release and bpf-next HEAD have it. Thanks Pragyansh and Varun