From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Stringer Subject: [PATCH bpf-next 2/2] bpf: Fix IPv6 dport byte-order in bpf_sk_lookup Date: Mon, 15 Oct 2018 10:27:46 -0700 Message-ID: <20181015172746.6475-3-joe@wand.net.nz> References: <20181015172746.6475-1-joe@wand.net.nz> Cc: netdev@vger.kernel.org To: daniel@iogearbox.net, ast@kernel.org Return-path: Received: from mail-qt1-f195.google.com ([209.85.160.195]:35231 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726861AbeJPBOI (ORCPT ); Mon, 15 Oct 2018 21:14:08 -0400 Received: by mail-qt1-f195.google.com with SMTP id d21-v6so10004717qtq.2 for ; Mon, 15 Oct 2018 10:27:57 -0700 (PDT) In-Reply-To: <20181015172746.6475-1-joe@wand.net.nz> Sender: netdev-owner@vger.kernel.org List-ID: Commit 6acc9b432e67 ("bpf: Add helper to retrieve socket in BPF") mistakenly passed the destination port in network byte-order to the IPv6 TCP/UDP socket lookup functions, which meant that BPF writers would need to either manually swap the byte-order of this field or otherwise IPv6 sockets could not be located via this helper. Fix the issue by swapping the byte-order appropriately in the helper. This also makes the API more consistent with the IPv4 version. Fixes: 6acc9b432e67 ("bpf: Add helper to retrieve socket in BPF") Signed-off-by: Joe Stringer --- net/core/filter.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index 21aba2a521c7..d877c4c599ce 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4846,17 +4846,18 @@ static struct sock *sk_lookup(struct net *net, struct bpf_sock_tuple *tuple, } else { struct in6_addr *src6 = (struct in6_addr *)&tuple->ipv6.saddr; struct in6_addr *dst6 = (struct in6_addr *)&tuple->ipv6.daddr; + u16 hnum = ntohs(tuple->ipv6.dport); int sdif = inet6_sdif(skb); if (proto == IPPROTO_TCP) sk = __inet6_lookup(net, &tcp_hashinfo, skb, 0, src6, tuple->ipv6.sport, - dst6, tuple->ipv6.dport, + dst6, hnum, dif, sdif, &refcounted); else if (likely(ipv6_bpf_stub)) sk = ipv6_bpf_stub->udp6_lib_lookup(net, src6, tuple->ipv6.sport, - dst6, tuple->ipv6.dport, + dst6, hnum, dif, sdif, &udp_table, skb); #endif -- 2.17.1