All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Ahern <dsahern@gmail.com>
To: Peter Oskolkov <posk@google.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	netdev@vger.kernel.org
Cc: Peter Oskolkov <posk@posk.io>, Willem de Bruijn <willemb@google.com>
Subject: Re: [PATCH bpf-next v10 5/7] bpf: add handling of BPF_LWT_REROUTE to lwt_bpf.c
Date: Tue, 12 Feb 2019 19:58:07 -0700	[thread overview]
Message-ID: <681aca28-b4e5-eb0d-46cd-94db7a2c368c@gmail.com> (raw)
In-Reply-To: <20190212173247.121342-6-posk@google.com>

On 2/12/19 10:32 AM, Peter Oskolkov wrote:
> @@ -148,6 +174,87 @@ static int xmit_check_hhlen(struct sk_buff *skb)
>  	return 0;
>  }
>  
> +static int bpf_lwt_xmit_reroute(struct sk_buff *skb)
> +{
> +	struct net_device *l3mdev = l3mdev_master_dev_rcu(skb_dst(skb)->dev);
> +	int oif = l3mdev ? l3mdev->ifindex : 0;
> +	struct dst_entry *dst = NULL;
> +	struct sock *sk;
> +	struct net *net;
> +	bool ipv4;
> +	int err;
> +
> +	if (skb->protocol == htons(ETH_P_IP))
> +		ipv4 = true;
> +	else if (skb->protocol == htons(ETH_P_IPV6))
> +		ipv4 = false;
> +	else
> +		return -EAFNOSUPPORT;
> +
> +	sk = sk_to_full_sk(skb->sk);
> +	if (sk) {
> +		if (sk->sk_bound_dev_if)
> +			oif = sk->sk_bound_dev_if;
> +		net = sock_net(sk);
> +	} else {
> +		net = dev_net(skb_dst(skb)->dev);
> +	}
> +
> +	if (ipv4) {
> +		struct iphdr *iph = ip_hdr(skb);
> +		struct flowi4 fl4 = {};
> +		struct rtable *rt;
> +
> +		fl4.flowi4_oif = oif;
> +		fl4.flowi4_mark = skb->mark;
> +		fl4.flowi4_uid = sock_net_uid(net, sk);
> +		fl4.flowi4_tos = RT_TOS(iph->tos);
> +		fl4.flowi4_flags = FLOWI_FLAG_ANYSRC;
> +		fl4.flowi4_proto = iph->protocol;
> +		fl4.daddr = iph->daddr;
> +		fl4.saddr = iph->saddr;
> +
> +		rt = ip_route_output_key(net, &fl4);
> +		if (IS_ERR(rt) || rt->dst.error)
> +			return -EINVAL;

I think you have a dst leak here if rt is valid but the lookup is a
reject (e.g., unreachable or blackhole).

> +		dst = &rt->dst;
> +	} else {
> +		struct ipv6hdr *iph6 = ipv6_hdr(skb);
> +		struct flowi6 fl6 = {};
> +
> +		fl6.flowi6_oif = oif;
> +		fl6.flowi6_mark = skb->mark;
> +		fl6.flowi6_uid = sock_net_uid(net, sk);
> +		fl6.flowlabel = ip6_flowinfo(iph6);
> +		fl6.flowi6_proto = iph6->nexthdr;
> +		fl6.daddr = iph6->daddr;
> +		fl6.saddr = iph6->saddr;
> +
> +		err = ipv6_stub->ipv6_dst_lookup(net, skb->sk, &dst, &fl6);
> +		if (err || IS_ERR(dst) || dst->error)
> +			return -EINVAL;

same here.

You could check this by adding a route with unreachable as the target in
your tests. Test cleanup and namespace teardown will tell you pretty quick.

  reply	other threads:[~2019-02-13  2:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-12 17:32 [PATCH bpf-next v10 0/7] bpf: add BPF_LWT_ENCAP_IP option to bpf_lwt_push_encap Peter Oskolkov
2019-02-12 17:32 ` [PATCH bpf-next v10 1/7] bpf: add plumbing for BPF_LWT_ENCAP_IP in bpf_lwt_push_encap Peter Oskolkov
2019-02-12 17:32 ` [PATCH bpf-next v10 2/7] bpf: implement BPF_LWT_ENCAP_IP mode " Peter Oskolkov
2019-02-12 17:32 ` [PATCH bpf-next v10 3/7] bpf: handle GSO " Peter Oskolkov
2019-02-12 17:32 ` [PATCH bpf-next v10 4/7] ipv6_stub: add ipv6_route_input stub/proxy Peter Oskolkov
2019-02-12 17:32 ` [PATCH bpf-next v10 5/7] bpf: add handling of BPF_LWT_REROUTE to lwt_bpf.c Peter Oskolkov
2019-02-13  2:58   ` David Ahern [this message]
2019-02-13 19:57     ` Peter Oskolkov
2019-02-13 20:11       ` David Ahern
2019-02-13 20:41         ` Peter Oskolkov
2019-02-12 17:32 ` [PATCH bpf-next v10 6/7] bpf: sync <kdir>/include/.../bpf.h with tools/include/.../bpf.h Peter Oskolkov
2019-02-12 17:32 ` [PATCH bpf-next v10 7/7] selftests: bpf: add test_lwt_ip_encap selftest Peter Oskolkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=681aca28-b4e5-eb0d-46cd-94db7a2c368c@gmail.com \
    --to=dsahern@gmail.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=netdev@vger.kernel.org \
    --cc=posk@google.com \
    --cc=posk@posk.io \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.