Skip to content

Commit 4e91bfa

Browse files
committed
add a test for tail calls from static functions
1 parent 15ae071 commit 4e91bfa

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,10 +1117,17 @@ int tail_call(struct __sk_buff *sk)
11171117
return 0;
11181118
}
11191119

1120+
static __noinline
1121+
int static_tail_call(struct __sk_buff *sk)
1122+
{
1123+
bpf_tail_call_static(sk, &jmp_table, 0);
1124+
return 0;
1125+
}
1126+
11201127
/* Tail calls in sub-programs invalidate packet pointers. */
11211128
SEC("tc")
11221129
__failure __msg("invalid mem access")
1123-
int invalidate_pkt_pointers_by_indirect_tail_call(struct __sk_buff *sk)
1130+
int invalidate_pkt_pointers_by_global_tail_call(struct __sk_buff *sk)
11241131
{
11251132
int *p = (void *)(long)sk->data;
11261133

@@ -1131,6 +1138,20 @@ int invalidate_pkt_pointers_by_indirect_tail_call(struct __sk_buff *sk)
11311138
return TCX_PASS;
11321139
}
11331140

1141+
/* Tail calls in static sub-programs invalidate packet pointers. */
1142+
SEC("tc")
1143+
__failure __msg("invalid mem access")
1144+
int invalidate_pkt_pointers_by_static_tail_call(struct __sk_buff *sk)
1145+
{
1146+
int *p = (void *)(long)sk->data;
1147+
1148+
if ((void *)(p + 1) > (void *)(long)sk->data_end)
1149+
return TCX_DROP;
1150+
static_tail_call(sk);
1151+
*p = 42; /* this is unsafe */
1152+
return TCX_PASS;
1153+
}
1154+
11341155
/* Direct tail calls do not invalidate packet pointers. */
11351156
SEC("tc")
11361157
__success

0 commit comments

Comments
 (0)