Skip to content

Commit 1a4607f

Browse files
eddyz87Alexei Starovoitov
authored andcommitted
bpf: consider that tail calls invalidate packet pointers
Tail-called programs could execute any of the helpers that invalidate packet pointers. Hence, conservatively assume that each tail call invalidates packet pointers. Making the change in bpf_helper_changes_pkt_data() automatically makes use of check_cfg() logic that computes 'changes_pkt_data' effect for global sub-programs, such that the following program could be rejected: int tail_call(struct __sk_buff *sk) { bpf_tail_call_static(sk, &jmp_table, 0); return 0; } SEC("tc") int not_safe(struct __sk_buff *sk) { int *p = (void *)(long)sk->data; ... make p valid ... tail_call(sk); *p = 42; /* this is unsafe */ ... } The tc_bpf2bpf.c:subprog_tc() needs change: mark it as a function that can invalidate packet pointers. Otherwise, it can't be freplaced with tailcall_freplace.c:entry_freplace() that does a tail call. Signed-off-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 89ff408 commit 1a4607f

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

net/core/filter.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7924,6 +7924,8 @@ bool bpf_helper_changes_pkt_data(enum bpf_func_id func_id)
79247924
case BPF_FUNC_xdp_adjust_head:
79257925
case BPF_FUNC_xdp_adjust_meta:
79267926
case BPF_FUNC_xdp_adjust_tail:
7927+
/* tail-called program could call any of the above */
7928+
case BPF_FUNC_tail_call:
79277929
return true;
79287930
default:
79297931
return false;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ int subprog_tc(struct __sk_buff *skb)
1111

1212
__sink(skb);
1313
__sink(ret);
14+
/* let verifier know that 'subprog_tc' can change pointers to skb->data */
15+
bpf_skb_change_proto(skb, 0, 0);
1416
return ret;
1517
}
1618

0 commit comments

Comments
 (0)