mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
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: 2012c867c8 ("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
This commit is contained in:
parent
ab08863c58
commit
a6f8a67c13
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user