Skip to content

Commit 04514d1

Browse files
borkmannAlexei Starovoitov
authored andcommitted
bpf: guarantee r1 to be ctx in case of bpf_helper_changes_pkt_data
Some JITs don't cache skb context on stack in prologue, so when LD_ABS/IND is used and helper calls yield bpf_helper_changes_pkt_data() as true, then they temporarily save/restore skb pointer. However, the assumption that skb always has to be in r1 is a bit of a gamble. Right now it turned out to be true for all helpers listed in bpf_helper_changes_pkt_data(), but lets enforce that from verifier side, so that we make this a guarantee and bail out if the func proto is misconfigured in future helpers. In case of BPF helper calls from cBPF, bpf_helper_changes_pkt_data() is completely unrelevant here (since cBPF is context read-only) and therefore always false. Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 87338c8 commit 04514d1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

kernel/bpf/verifier.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,13 @@ static int check_call(struct bpf_verifier_env *env, int func_id, int insn_idx)
16741674
return -EINVAL;
16751675
}
16761676

1677+
/* With LD_ABS/IND some JITs save/restore skb from r1. */
16771678
changes_data = bpf_helper_changes_pkt_data(fn->func);
1679+
if (changes_data && fn->arg1_type != ARG_PTR_TO_CTX) {
1680+
verbose(env, "kernel subsystem misconfigured func %s#%d: r1 != ctx\n",
1681+
func_id_name(func_id), func_id);
1682+
return -EINVAL;
1683+
}
16781684

16791685
memset(&meta, 0, sizeof(meta));
16801686
meta.pkt_access = fn->pkt_access;

0 commit comments

Comments
 (0)