Re: [PATCH bpf,v6 3/4] bpf: fix bpf socket lookup from tc/xdp to respect socket VRF bindings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/21/23 12:42 PM, Gilad Sever wrote:
When calling bpf_sk_lookup_tcp(), bpf_sk_lookup_udp() or
bpf_skc_lookup_tcp() from tc/xdp ingress, VRF socket bindings aren't
respoected, i.e. unbound sockets are returned, and bound sockets aren't
found.

VRF binding is determined by the sdif argument to sk_lookup(), however
when called from tc the IP SKB control block isn't initialized and thus
inet{,6}_sdif() always returns 0.

Fix by calculating sdif for the tc/xdp flows by observing the device's
l3 enslaved state.

The cg/sk_skb hooking points which are expected to support
inet{,6}_sdif() pass sdif=-1 which makes __bpf_skc_lookup() use the
existing logic.

Fixes: 6acc9b432e67 ("bpf: Add helper to retrieve socket in BPF")
Acked-by: Stanislav Fomichev <sdf@xxxxxxxxxx>
Reviewed-by: Shmulik Ladkani <shmulik.ladkani@xxxxxxxxx>
Reviewed-by: Eyal Birger <eyal.birger@xxxxxxxxx>
Signed-off-by: Gilad Sever <gilad9366@xxxxxxxxx>
[...]
  static const struct bpf_func_proto bpf_tc_sk_lookup_tcp_proto = {
@@ -6776,12 +6788,17 @@ static const struct bpf_func_proto bpf_tc_sk_lookup_tcp_proto = {
  BPF_CALL_5(bpf_tc_sk_lookup_udp, struct sk_buff *, skb,
  	   struct bpf_sock_tuple *, tuple, u32, len, u64, netns_id, u64, flags)
  {
-	struct net *caller_net = dev_net(skb->dev);
-	int ifindex = skb->dev->ifindex;
+	struct net_device *dev = skb->dev;
+	struct net *caller_net;
+	int ifindex, sdif;
+
+	caller_net = dev_net(dev);
+	ifindex = dev->ifindex;
+	sdif = dev_sdif(dev);
return (unsigned long)__bpf_sk_lookup(skb, tuple, len, caller_net,
  					      ifindex, IPPROTO_UDP, netns_id,
-					      flags);
+					      flags, sdif);
  }

Applied, thanks! Btw, the above looks now way uglier than before, so I fixed this
up wrt how it should have looked like for the submission:

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=9a5cb79762e0eda17ca15c2a6eaca4622383c21c

Thanks,
Daniel



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux