Commit 021d677
committed
bpf: properly verify tail call behavior
A successful ebpf tail call does not return to the caller, but to the
caller-of-the-caller, often just finishing the ebpf program altogether.
Any restrictions that the verifier needs to take into account - notably
the fact that the tail call might have modified packet pointers - are to
be checked on the caller-of-the-caller. Checking it on the caller made
the verifier refuse perfectly fine programs that would use the packet
pointers after a tail call, which is no problem as this code is only
executed if the tail call was unsuccessful, i.e. nothing happened.
This patch simulates the behavior of a tail call in the verifier. A
conditional jump to the code after the tail call is added for the case
of an unsucessful tail call, and a return to the caller is simulated for
a successful tail call.
For the successful case we assume that the tail call returns an int,
as tail calls are currently only allowed in functions that return and
int. We always assume that the tail call modified the packet pointers,
as we do not know what the tail call did.
For the unsuccessful case we know nothing happened, so we do not need to
add new constraints.
Fixes: 1a4607f ("bpf: consider that tail calls invalidate packet pointers")
Link: https://lore.kernel.org/bpf/[email protected]/
Signed-off-by: Martin Teichmann <[email protected]>1 parent efe6edf commit 021d677
1 file changed
+28
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4411 | 4411 | | |
4412 | 4412 | | |
4413 | 4413 | | |
| 4414 | + | |
| 4415 | + | |
| 4416 | + | |
| 4417 | + | |
| 4418 | + | |
4414 | 4419 | | |
4415 | 4420 | | |
4416 | 4421 | | |
| |||
11034 | 11039 | | |
11035 | 11040 | | |
11036 | 11041 | | |
| 11042 | + | |
| 11043 | + | |
| 11044 | + | |
| 11045 | + | |
11037 | 11046 | | |
11038 | 11047 | | |
11039 | 11048 | | |
| |||
11940 | 11949 | | |
11941 | 11950 | | |
11942 | 11951 | | |
| 11952 | + | |
| 11953 | + | |
| 11954 | + | |
| 11955 | + | |
| 11956 | + | |
| 11957 | + | |
| 11958 | + | |
| 11959 | + | |
| 11960 | + | |
| 11961 | + | |
| 11962 | + | |
| 11963 | + | |
| 11964 | + | |
| 11965 | + | |
| 11966 | + | |
| 11967 | + | |
| 11968 | + | |
| 11969 | + | |
| 11970 | + | |
11943 | 11971 | | |
11944 | 11972 | | |
11945 | 11973 | | |
| |||
20110 | 20138 | | |
20111 | 20139 | | |
20112 | 20140 | | |
20113 | | - | |
20114 | | - | |
20115 | | - | |
20116 | 20141 | | |
20117 | 20142 | | |
20118 | 20143 | | |
| |||
0 commit comments