From patchwork Fri Jul 7 12:26:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Gobert X-Patchwork-Id: 117124 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp3231487vqx; Fri, 7 Jul 2023 05:30:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlEVj2LJ1Zvh0tQHDwo1WL6udPSbUcRg0vTJ3KtZ6rTJaFcnQwOCTxwWxV8D60r8pzL8dgWQ X-Received: by 2002:a17:90a:c690:b0:262:c974:6057 with SMTP id n16-20020a17090ac69000b00262c9746057mr3958634pjt.32.1688733058859; Fri, 07 Jul 2023 05:30:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688733058; cv=none; d=google.com; s=arc-20160816; b=QQulCslcDCr1/uzzFc2X80RgPegBNoPDRI9Y//Ni33SgIeCWt4ZqnzSyRpBr3KFS6d NYg+60zQT7uy1Z4NzHvnD7GScbuHZsZyipvGgyP7/trnHRDxDGPUbKBwc7eFLlXZiwiD my3DUBjqaakCEL8Y0qqMi1Wyq+8nPq+zGKx8Ay89+GmYp+ul72C45NZFLGuOPjC9XkgB xPqZ1wsEcoFhTd5JYbbyGo5Hus5fF0ZmzjDP4ZNiouv9+fjnfAvgwPlcf1evtZFRzwvn qkK5oYS7uBd106QMoWcdbPUB/wXdDKURcRx/xq3hXYkwji4wWeLkGYluvPfZAWpr8gC4 luxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:to:from:date :dkim-signature; bh=bklyYiP/IhxeYjsLbgb+f+L9NtgpRzAgyHR6T9K9BbM=; fh=NfPdGD6Y/fUukMnDQdv+EWH4vc0MgRZIMcW8czEW4Rs=; b=vfVLg6Il42dJUi7k05aS0+Hm25qIYUaP1tFUS1NhMg5ESmmuCArcOuZkolaxI3gRcJ B7d5GmlOWvwzljucpOQedwL+QSsdLYppOQR5HlVYPVMR/txqspqrwxG1D+yRjpd1G0m5 cG+A+SbEBuMw5Iv78Y3z1ZTsyjTZvR4Ytef+6TmLYhR8HxJ/w/XV4i4b17ToD0rSsqYH gIK+Aw8ZXF6EkTanAeTrsIk0ILY1Yh1RrGZsdJTQ5iJV1QggHwrYlRU9mjNMRH5J3GIp QX8HGsIYJrm0whNS0/2GFVGEseMNz+bbgUPlWupeRsmHV0GpAttpAeECrlBGeu9N78aC fnDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=sUEPF7Cp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b13-20020a17090a550d00b00263492ded2asi1862266pji.94.2023.07.07.05.30.43; Fri, 07 Jul 2023 05:30:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=sUEPF7Cp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232465AbjGGM0m (ORCPT + 99 others); Fri, 7 Jul 2023 08:26:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232010AbjGGM0l (ORCPT ); Fri, 7 Jul 2023 08:26:41 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F25FC1FEA; Fri, 7 Jul 2023 05:26:39 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3fbc656873eso23014105e9.1; Fri, 07 Jul 2023 05:26:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688732798; x=1691324798; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:to:from:date:from:to:cc:subject:date:message-id :reply-to; bh=bklyYiP/IhxeYjsLbgb+f+L9NtgpRzAgyHR6T9K9BbM=; b=sUEPF7CpHwBz6vjelHaHjXAqGKvaLXbaMuzOdBmX+LCOt2ExjEtZMW5dZSSRVnR8j9 xBTD7abRZljt5XD0reFOvz/nSQOiA0Yx3Fhz1h7qEDCC3AN5E9NlswMjkHbH1KpEc6tw cQHMnbQNMJmZM0lufQnkKQyGERwt1ALNnlKCZW8/1V5hsdz5+vYfYfs3hhOiSKqBqVp/ 9cMiF/LlXXVLEEUI8v8F684bPYkWV93YF1faBlwil1RJLFtd9KV25g8317jy7Cj0CI1k 6sAwvYEjWOh1syIKkmmwcz2k37kg24NrHznZVhYJeH6gEGyFNpwOd3e17D5kf9JSd7Uv PIrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688732798; x=1691324798; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bklyYiP/IhxeYjsLbgb+f+L9NtgpRzAgyHR6T9K9BbM=; b=AxBloCPUvi5lhkVy19Y+Bg52fQFW1p/0nAr82crsr6XZzO3XcndVCVVScgfJRjQ5EW KB+5wVNSbT3lJC6dcTaNYdVLgkWg6nVVAyPHl1lnB5ZhCvs90EodjzlezpDoeUZCOf9O Xfgtyldh88nXLzWvC7p3AXqUWWZS182bI8W8zuguUsKYOAlcZge9p+XbY9r5kn2CR4vx dReXUUfdTP8mmYIaWD6GI/F6UdbtFm0arQZ6NyqGlr+SeKJW05OgGAKDX7LOGIHZNm57 1X93t/1dXhlFzLSCi6fP9RBD+ecIiM7O5MXNYI8bcJBhOet6GChvbiIo0R2M4H2W9YSk JrZQ== X-Gm-Message-State: ABy/qLYWweabasKNVFb+J1AcPXl0RNdQKr6rTGi+sA0tEW4rw10tkMF6 L7Z9MulyTUF1EScw7xqq7l0U2dIQRbc= X-Received: by 2002:a05:600c:247:b0:3fc:65:8dff with SMTP id 7-20020a05600c024700b003fc00658dffmr1502438wmj.4.1688732798311; Fri, 07 Jul 2023 05:26:38 -0700 (PDT) Received: from debian ([89.238.191.199]) by smtp.gmail.com with ESMTPSA id e4-20020a5d5004000000b0030fb4b55c13sm4307150wrt.96.2023.07.07.05.26.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 05:26:38 -0700 (PDT) Date: Fri, 7 Jul 2023 14:26:28 +0200 From: Richard Gobert To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, willemdebruijn.kernel@gmail.com, dsahern@kernel.org, tom@herbertland.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, gal@nvidia.com Subject: [PATCH 1/1] net: gro: fix misuse of CB in udp socket lookup Message-ID: <20230707122627.GA17845@debian> References: <20230707121650.GA17677@debian> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230707121650.GA17677@debian> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770764594673913445?= X-GMAIL-MSGID: =?utf-8?q?1770764956074935175?= This patch fixes a misuse of IP{6}CB(skb) in GRO, while calling to `udp6_lib_lookup2` when handling udp tunnels. `udp6_lib_lookup2` fetch the device from CB. The fix changes it to fetch the device from `skb->dev`. l3mdev case requires special attention since it has a master and a slave device. Fixes: a6024562ffd7 ("udp: Add GRO functions to UDP socket") Reported-by: Gal Pressman Signed-off-by: Richard Gobert --- include/net/udp.h | 2 ++ net/ipv4/udp.c | 21 +++++++++++++++++++-- net/ipv4/udp_offload.c | 7 +++++-- net/ipv6/udp.c | 21 +++++++++++++++++++-- net/ipv6/udp_offload.c | 7 +++++-- 5 files changed, 50 insertions(+), 8 deletions(-) -- 2.36.1 diff --git a/include/net/udp.h b/include/net/udp.h index 4d13424f8f72..48af1479882f 100644 --- a/include/net/udp.h +++ b/include/net/udp.h @@ -299,6 +299,7 @@ int udp_lib_getsockopt(struct sock *sk, int level, int optname, int udp_lib_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval, unsigned int optlen, int (*push_pending_frames)(struct sock *)); +void udp4_get_iif_sdif(const struct sk_buff *skb, int *iif, int *sdif); struct sock *udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport, __be32 daddr, __be16 dport, int dif); struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport, @@ -310,6 +311,7 @@ struct sock *udp6_lib_lookup(struct net *net, const struct in6_addr *saddr, __be16 sport, const struct in6_addr *daddr, __be16 dport, int dif); +void udp6_get_iif_sdif(const struct sk_buff *skb, int *iif, int *sdif); struct sock *__udp6_lib_lookup(struct net *net, const struct in6_addr *saddr, __be16 sport, const struct in6_addr *daddr, __be16 dport, diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 42a96b3547c9..0581ab184afd 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -550,15 +550,32 @@ static inline struct sock *__udp4_lib_lookup_skb(struct sk_buff *skb, inet_sdif(skb), udptable, skb); } +void udp4_get_iif_sdif(const struct sk_buff *skb, int *iif, int *sdif) +{ + *iif = inet_iif(skb) || skb->dev->ifindex; + *sdif = 0; + +#if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV) + if (netif_is_l3_slave(skb->dev)) { + struct net_device *master = netdev_master_upper_dev_get_rcu(skb->dev); + *sdif = *iif; + *iif = master ? master->ifindex : 0; + } +#endif +} + struct sock *udp4_lib_lookup_skb(const struct sk_buff *skb, __be16 sport, __be16 dport) { const struct iphdr *iph = ip_hdr(skb); struct net *net = dev_net(skb->dev); + int iif, sdif; + + udp4_get_iif_sdif(skb, &iif, &sdif); return __udp4_lib_lookup(net, iph->saddr, sport, - iph->daddr, dport, inet_iif(skb), - inet_sdif(skb), net->ipv4.udp_table, NULL); + iph->daddr, dport, iif, + sdif, net->ipv4.udp_table, NULL); } /* Must be called under rcu_read_lock(). diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index 75aa4de5b731..70d760b271db 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -603,10 +603,13 @@ static struct sock *udp4_gro_lookup_skb(struct sk_buff *skb, __be16 sport, { const struct iphdr *iph = skb_gro_network_header(skb); struct net *net = dev_net(skb->dev); + int iif, sdif; + + udp4_get_iif_sdif(skb, &iif, &sdif); return __udp4_lib_lookup(net, iph->saddr, sport, - iph->daddr, dport, inet_iif(skb), - inet_sdif(skb), net->ipv4.udp_table, NULL); + iph->daddr, dport, iif, + sdif, net->ipv4.udp_table, NULL); } INDIRECT_CALLABLE_SCOPE diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 317b01c9bc39..aac9b20d67e4 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -294,15 +294,32 @@ static struct sock *__udp6_lib_lookup_skb(struct sk_buff *skb, inet6_sdif(skb), udptable, skb); } +void udp6_get_iif_sdif(const struct sk_buff *skb, int *iif, int *sdif) +{ + *iif = skb->dev->ifindex; + *sdif = 0; + +#if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV) + if (netif_is_l3_slave(skb->dev)) { + struct net_device *master = netdev_master_upper_dev_get_rcu(skb->dev); + *sdif = *iif; + *iif = master ? master->ifindex : 0; + } +#endif +} + struct sock *udp6_lib_lookup_skb(const struct sk_buff *skb, __be16 sport, __be16 dport) { const struct ipv6hdr *iph = ipv6_hdr(skb); struct net *net = dev_net(skb->dev); + int iif, sdif; + + udp6_get_iif_sdif(skb, &iif, &sdif); return __udp6_lib_lookup(net, &iph->saddr, sport, - &iph->daddr, dport, inet6_iif(skb), - inet6_sdif(skb), net->ipv4.udp_table, NULL); + &iph->daddr, dport, iif, + sdif, net->ipv4.udp_table, NULL); } /* Must be called under rcu_read_lock(). diff --git a/net/ipv6/udp_offload.c b/net/ipv6/udp_offload.c index ad3b8726873e..88191d79002e 100644 --- a/net/ipv6/udp_offload.c +++ b/net/ipv6/udp_offload.c @@ -119,10 +119,13 @@ static struct sock *udp6_gro_lookup_skb(struct sk_buff *skb, __be16 sport, { const struct ipv6hdr *iph = skb_gro_network_header(skb); struct net *net = dev_net(skb->dev); + int iif, sdif; + + udp6_get_iif_sdif(skb, &iif, &sdif); return __udp6_lib_lookup(net, &iph->saddr, sport, - &iph->daddr, dport, inet6_iif(skb), - inet6_sdif(skb), net->ipv4.udp_table, NULL); + &iph->daddr, dport, iif, + sdif, net->ipv4.udp_table, NULL); } INDIRECT_CALLABLE_SCOPE