From patchwork Mon Oct 15 17:27:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 984297 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=wand.net.nz Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HRCQIOQu"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Yll42cDmz9s8F for ; Tue, 16 Oct 2018 04:28:00 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726880AbeJPBOJ (ORCPT ); Mon, 15 Oct 2018 21:14:09 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=AyMpOO2hkNhGLi1tnF+bLoquEERvWA20WczedaWlSNQ=; b=HRCQIOQu6L5iUDaG+H+a/OAsBW0Rv8yPiNSord2IH7mp1ESfP6lKMaprv6njxg+aX1 Iy6A0wFNiusfYc4uPaRSZyxAACeKgho0eOk3fKOXOMx8ptKaOaJQ/DchZr729VVSHuGS wv+oMbOEfpy4ZmEesfBzeqaoPeJ/QAJmEwyvfyWExKM3yU4md0uenOKjCHJjPgij1x9i zyiNaHXyQwndSJYKnRrqhUh7TkLUFvgUFmTjQZc2138gMAatB9Wod4A6jjwtrMh8Vu5o GWwuRzPu0e/WWm/aEnioNHWD+uCvZQ+wAp/3DKO1ZJXoaQ9zItZJRxm5ajgcpNn7/TiW eXSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=AyMpOO2hkNhGLi1tnF+bLoquEERvWA20WczedaWlSNQ=; b=K7fsSz1LZqii1gF1HEvndgfGbZ+/WDbEfDh4kaKQbf/16Cy4oSHhdlmPTpEtyWIg5M 4e7rbCh5Gzz6/4jzqPJlE+0oRgq5kr8tVtfK7daCmhZufjJ3mDfBt7TO0v6Ll/irF7cU O5fpMtBUCSypiwiCbjayE+dYDG14W4ZnHUfZcBJM4Opx6laKleebjh3+rKFQM/0iMX10 48OmVLnCCACJjo84Um9bXwjCdWcFCMhMgKaSb7NATlmRkFoZhKReOZpK6Atufv6jin9W ZohmqDBUqV0YiSf868hsoid2tVfv9zhgIyiW1Xk2RDmK56MaewaAe/tTRDBOaGYIg63M CUkA== X-Gm-Message-State: ABuFfohwZUD2HOqFmoVPWOtFhwEfBkZyBcrdVqWfY5slSQhn9H4sw3Pz /FKkSXilZ5cHKJGQSBReI5s= X-Google-Smtp-Source: ACcGV62Sq+ytF4YOVGJ6nTNA4D/6Cv3VF4aX5lBW4Vckig+bRFpPxBqzBsOBAVdR9muo210RHZNwDw== X-Received: by 2002:a0c:c901:: with SMTP id r1mr17984145qvj.170.1539624477161; Mon, 15 Oct 2018 10:27:57 -0700 (PDT) Received: from localhost.localdomain ([99.0.85.34]) by smtp.gmail.com with ESMTPSA id n67-v6sm10346113qkh.66.2018.10.15.10.27.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 10:27:56 -0700 (PDT) From: Joe Stringer To: daniel@iogearbox.net, ast@kernel.org Cc: netdev@vger.kernel.org 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> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181015172746.6475-1-joe@wand.net.nz> References: <20181015172746.6475-1-joe@wand.net.nz> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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