Skip to content

Commit ba07f40

Browse files
committed
add test
1 parent cd2f1d3 commit ba07f40

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,13 @@ int static_tail_call(struct __sk_buff *sk)
11241124
return 0;
11251125
}
11261126

1127+
static __noinline
1128+
int *static_tail_call_return(struct __sk_buff *sk)
1129+
{
1130+
bpf_tail_call_static(sk, &jmp_table, 0);
1131+
return (void *)(long)sk->data;
1132+
}
1133+
11271134
/* Tail calls in sub-programs invalidate packet pointers. */
11281135
SEC("tc")
11291136
__failure __msg("invalid mem access")
@@ -1166,4 +1173,18 @@ int invalidate_pkt_pointers_by_tail_call(struct __sk_buff *sk)
11661173
return TCX_PASS;
11671174
}
11681175

1176+
/* Direct tail calls do not invalidate packet pointers. */
1177+
SEC("tc")
1178+
__success
1179+
int invalidate_pkt_pointers_by_tail_call_return(struct __sk_buff *sk)
1180+
{
1181+
int *p = (void *)(long)sk->data;
1182+
1183+
if ((void *)(p + 1) > (void *)(long)sk->data_end)
1184+
return TCX_DROP;
1185+
p = bpf_tail_call_return(sk, &jmp_table, 0);
1186+
*p = 42; /* this is NOT unsafe: tail calls don't return */
1187+
return TCX_PASS;
1188+
}
1189+
11691190
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)