]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: lwtunnel: Fix reroute supplying invalid dst
authorJiri Benc <jbenc@redhat.com>
Wed, 9 Oct 2019 08:31:24 +0000 (10:31 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 14 Oct 2019 18:43:48 +0000 (11:43 -0700)
commit8a04d5ba29b564bfcdd2933998009f56c8da369d
tree5638d806575c844a9b27561ba1e93d27586602fa
parenta47276f72ea25dd0a4a8d1dd2502bef16af1089a
bpf: lwtunnel: Fix reroute supplying invalid dst

The dst in bpf_input() has lwtstate field set. As it is of the
LWTUNNEL_ENCAP_BPF type, lwtstate->data is struct bpf_lwt. When the bpf
program returns BPF_LWT_REROUTE, ip_route_input_noref is directly called on
this skb. This causes invalid memory access, as ip_route_input_slow calls
skb_tunnel_info(skb) that expects the dst->lwstate->data to be
struct ip_tunnel_info. This results to struct bpf_lwt being accessed as
struct ip_tunnel_info.

Drop the dst before calling the IP route input functions (both for IPv4 and
IPv6).

Reported by KASAN.

Fixes: 1d9b24d7468a ("bpf: add handling of BPF_LWT_REROUTE to lwt_bpf.c")
Signed-off-by: Jiri Benc <jbenc@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Peter Oskolkov <posk@google.com>
Link: https://lore.kernel.org/bpf/111664d58fe4e9dd9c8014bb3d0b2dab93086a9e.1570609794.git.jbenc@redhat.com
net/core/lwt_bpf.c