diff options
| author | Josef Bacik <josef@toxicpanda.com> | 2026-10-17 23:09:50 +0000 |
|---|---|---|
| committer | Alexei Starovoitov <ast@kernel.org> | 2026-10-18 00:36:44 +0000 |
| commit | a6f8a67c13ddd5fcfee0fae61ec5787ee6729ab3 (patch) | |
| tree | c98dd42f405d645d538ecfc7c68c0c55234cacb1 /kernel/bpf | |
| parent | ab08863c58b1a96ff8378e373cb3d277cbe65b68 (diff) | |
| download | linux-next-a6f8a67c13ddd5fcfee0fae61ec5787ee6729ab3.tar.gz linux-next-a6f8a67c13ddd5fcfee0fae61ec5787ee6729ab3.zip | |
bpf: Refuse packet slices for packet-changing helpers
The helpers which may change packet data do not take a packet pointer as a
memory argument: they have no pkt_access. They make the skb writable, or
make room in it, before they read what the argument points to, and that
can reallocate the head which it points into.
A slice from bpf_dynptr_slice() of the dynptr of the skb points into the
same head, but it is a PTR_TO_MEM, and the verifier lets it pass.
bpf_lwt_push_encap(), bpf_lwt_seg6_store_bytes() and bpf_lwt_seg6_action()
then read the old head, which has been freed. bpf_skb_store_bytes() follows
the head by now, but a slice is no better than a packet pointer there.
Refuse a slice of a packet where a packet pointer is refused for that
reason. All other helpers take slices as before. bpf_dynptr_write() and
bpf_dynptr_copy() can be used to copy inside of a packet.
Fixes: 2012c867c800 ("bpf: verifier: Accept dynptr mem as mem in helpers")
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://patch.msgid.link/20261017230950.802052-17-alexei.starovoitov@gmail.com
Diffstat (limited to 'kernel/bpf')
| -rw-r--r-- | kernel/bpf/verifier.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 3bc1df7aabe2..63fff641d985 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -9687,6 +9687,16 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg, u32 slot, u32 p if (err) return err; + /* + * A slice of a packet is packet data under another name. A helper which + * may reallocate the packet must not go on reading from the old one. + */ + if (is_helper(meta) && reg_is_dynptr_slice_pkt(reg) && + bpf_helper_changes_pkt_data(meta->func_id)) { + verbose(env, "function access to the packet is not allowed\n"); + return -EACCES; + } + if (arg_type_is_raw_mem(arg_type)) meta->arg_raw_mem.mask |= BIT(slot); |
