From patchwork Tue May 19 13:03:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 219014 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D23B4C433DF for ; Tue, 19 May 2020 13:03:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A11742081A for ; Tue, 19 May 2020 13:03:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="FC/urf85" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728897AbgESND4 (ORCPT ); Tue, 19 May 2020 09:03:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728612AbgESNDz (ORCPT ); Tue, 19 May 2020 09:03:55 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EC03C08C5C3; Tue, 19 May 2020 06:03:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=gEcIlXPDOpnjvuoYXNVQDG0cqiJg1ipM9BnENUoDM9Q=; b=FC/urf85XUhNkvWEarFUJfLYXl D0qap657f9owFUlDM1LtU+iPuzbkNh41C2wdmm37ZyKELnsRI+whloZRQNX1Vjzd5CwGwt7AbhrqV 25Seun/TJmnTbFOePC4umXhonVpPNKudcKP16353gZM83xgTOLw+e9/PbtP7qrjQ+cZCDlYywpoHG 0Bk9yD061Qpho+z4HpDH3q6V4ewx4ck2EUXzcHPxyVKHdYU1sFrtQlAbZkebjj+dR4wLzcEwI3KcS gmMIeA2kmquoJpe+qaHhOIskGXGX1rtK2RqZIDReKjO/5qIs16SxoPneMcogIeNziwwgTJ6NWnRfy H8fCXskg==; Received: from [2001:4bb8:188:1506:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jb1u3-0003zW-Bo; Tue, 19 May 2020 13:03:27 +0000 From: Christoph Hellwig To: "David S. Miller" , Jakub Kicinski Cc: Alexey Kuznetsov , Hideaki YOSHIFUJI , Steffen Klassert , Herbert Xu , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/9] ipv4: consolidate the VIFF_TUNNEL handling in ipmr_new_tunnel Date: Tue, 19 May 2020 15:03:12 +0200 Message-Id: <20200519130319.1464195-3-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200519130319.1464195-1-hch@lst.de> References: <20200519130319.1464195-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Also move the dev_set_allmulti call and the error handling into the ioctl helper. This allows reusing already looked up tunnel_dev pointer and the set up argument structure for the deletion in the error handler. Signed-off-by: Christoph Hellwig --- net/ipv4/ipmr.c | 53 ++++++++++++------------------------------------- 1 file changed, 13 insertions(+), 40 deletions(-) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index a1169b6941134..cd1a3260a99af 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -421,37 +421,6 @@ static void ipmr_free_table(struct mr_table *mrt) /* Service routines creating virtual interfaces: DVMRP tunnels and PIMREG */ -static void ipmr_del_tunnel(struct net_device *dev, struct vifctl *v) -{ - struct net *net = dev_net(dev); - - dev_close(dev); - - dev = __dev_get_by_name(net, "tunl0"); - if (dev) { - const struct net_device_ops *ops = dev->netdev_ops; - struct ifreq ifr; - struct ip_tunnel_parm p; - - memset(&p, 0, sizeof(p)); - p.iph.daddr = v->vifc_rmt_addr.s_addr; - p.iph.saddr = v->vifc_lcl_addr.s_addr; - p.iph.version = 4; - p.iph.ihl = 5; - p.iph.protocol = IPPROTO_IPIP; - sprintf(p.name, "dvmrp%d", v->vifc_vifi); - ifr.ifr_ifru.ifru_data = (__force void __user *)&p; - - if (ops->ndo_do_ioctl) { - mm_segment_t oldfs = get_fs(); - - set_fs(KERNEL_DS); - ops->ndo_do_ioctl(dev, &ifr, SIOCDELTUNNEL); - set_fs(oldfs); - } - } -} - /* Initialize ipmr pimreg/tunnel in_device */ static bool ipmr_init_vif_indev(const struct net_device *dev) { @@ -509,12 +478,22 @@ static struct net_device *ipmr_new_tunnel(struct net *net, struct vifctl *v) if (dev_open(new_dev, NULL)) goto out_unregister; dev_hold(new_dev); + err = dev_set_allmulti(new_dev, 1); + if (err) { + dev_close(new_dev); + set_fs(KERNEL_DS); + tunnel_dev->netdev_ops->ndo_do_ioctl(tunnel_dev, &ifr, + SIOCDELTUNNEL); + set_fs(oldfs); + dev_put(new_dev); + new_dev = ERR_PTR(err); + } return new_dev; out_unregister: unregister_netdevice(new_dev); out: - return NULL; + return ERR_PTR(-ENOBUFS); } #if defined(CONFIG_IP_PIMSM_V1) || defined(CONFIG_IP_PIMSM_V2) @@ -866,14 +845,8 @@ static int vif_add(struct net *net, struct mr_table *mrt, break; case VIFF_TUNNEL: dev = ipmr_new_tunnel(net, vifc); - if (!dev) - return -ENOBUFS; - err = dev_set_allmulti(dev, 1); - if (err) { - ipmr_del_tunnel(dev, vifc); - dev_put(dev); - return err; - } + if (IS_ERR(dev)) + return PTR_ERR(dev); break; case VIFF_USE_IFINDEX: case 0: From patchwork Tue May 19 13:03:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 219013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0DEDC433E0 for ; Tue, 19 May 2020 13:04:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B60920709 for ; Tue, 19 May 2020 13:04:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="o1x4fSlQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728973AbgESNED (ORCPT ); Tue, 19 May 2020 09:04:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728954AbgESNEA (ORCPT ); Tue, 19 May 2020 09:04:00 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26C6AC08C5C4; Tue, 19 May 2020 06:04:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=RjxiJywqJojajkQHo5ctJXUjgepAaAnx5XtlttT7D94=; b=o1x4fSlQCZi+V++zGwl1kfXPN5 SzACjpzA0QeCobSM+iONMAKqCdCLyr8UFjaUKxCFtuNHcelBdUufoMqX1mheFlSDz5aRvxaD+6ltv PkLR0yVehkwudM746g7XUaeh72lwy7QcZ6Uaslqvs4cUjBgROvyfWrPLdrumLtM4Wxa8YRyktVvqq ImeRIRTGDIN8tbPZHSFQxPKlbZvtNKlZPlIrqJ2joaLNE9fc2Pogy8oB/dXTxQSPyTsAks8mCFn96 AC/yzWRXaWiTskiQK4/M9YCegIOfx/eYMc9CA5ibtPtOzBZnFqMmHXrYTWTmjiVi/om0vBlfDH2FW 3QiBKrXw==; Received: from [2001:4bb8:188:1506:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jb1uE-00048D-Ez; Tue, 19 May 2020 13:03:38 +0000 From: Christoph Hellwig To: "David S. Miller" , Jakub Kicinski Cc: Alexey Kuznetsov , Hideaki YOSHIFUJI , Steffen Klassert , Herbert Xu , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/9] sit: impement ->ndo_tunnel_ctl Date: Tue, 19 May 2020 15:03:16 +0200 Message-Id: <20200519130319.1464195-7-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200519130319.1464195-1-hch@lst.de> References: <20200519130319.1464195-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Implement the ->ndo_tunnel_ctl method, and use ip_tunnel_ioctl to handle userspace requests for the SIOCGETTUNNEL, SIOCADDTUNNEL, SIOCCHGTUNNEL and SIOCDELTUNNEL ioctls. Signed-off-by: Christoph Hellwig --- net/ipv6/sit.c | 73 +++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 39 deletions(-) diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index 7c158fdc02daf..1fbb4dfbb191b 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -1267,60 +1267,45 @@ __ipip6_tunnel_ioctl_validate(struct net *net, struct ip_tunnel_parm *p) } static int -ipip6_tunnel_get(struct net_device *dev, struct ifreq *ifr) +ipip6_tunnel_get(struct net_device *dev, struct ip_tunnel_parm *p) { struct ip_tunnel *t = netdev_priv(dev); - struct ip_tunnel_parm p; - if (dev == dev_to_sit_net(dev)->fb_tunnel_dev) { - if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) - return -EFAULT; - t = ipip6_tunnel_locate(t->net, &p, 0); - } + if (dev == dev_to_sit_net(dev)->fb_tunnel_dev) + t = ipip6_tunnel_locate(t->net, p, 0); if (!t) t = netdev_priv(dev); - - if (copy_to_user(ifr->ifr_ifru.ifru_data, &t->parms, sizeof(p))) - return -EFAULT; + memcpy(p, &t->parms, sizeof(*p)); return 0; } static int -ipip6_tunnel_add(struct net_device *dev, struct ifreq *ifr) +ipip6_tunnel_add(struct net_device *dev, struct ip_tunnel_parm *p) { struct ip_tunnel *t = netdev_priv(dev); - struct ip_tunnel_parm p; int err; - if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) - return -EFAULT; - err = __ipip6_tunnel_ioctl_validate(t->net, &p); + err = __ipip6_tunnel_ioctl_validate(t->net, p); if (err) return err; - t = ipip6_tunnel_locate(t->net, &p, 1); + t = ipip6_tunnel_locate(t->net, p, 1); if (!t) return -ENOBUFS; - - if (copy_to_user(ifr->ifr_ifru.ifru_data, &t->parms, sizeof(p))) - return -EFAULT; return 0; } static int -ipip6_tunnel_change(struct net_device *dev, struct ifreq *ifr) +ipip6_tunnel_change(struct net_device *dev, struct ip_tunnel_parm *p) { struct ip_tunnel *t = netdev_priv(dev); - struct ip_tunnel_parm p; int err; - if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) - return -EFAULT; - err = __ipip6_tunnel_ioctl_validate(t->net, &p); + err = __ipip6_tunnel_ioctl_validate(t->net, p); if (err) return err; - t = ipip6_tunnel_locate(t->net, &p, 0); + t = ipip6_tunnel_locate(t->net, p, 0); if (dev == dev_to_sit_net(dev)->fb_tunnel_dev) { if (!t) return -ENOENT; @@ -1329,33 +1314,28 @@ ipip6_tunnel_change(struct net_device *dev, struct ifreq *ifr) if (t->dev != dev) return -EEXIST; } else { - if (((dev->flags & IFF_POINTOPOINT) && !p.iph.daddr) || - (!(dev->flags & IFF_POINTOPOINT) && p.iph.daddr)) + if (((dev->flags & IFF_POINTOPOINT) && !p->iph.daddr) || + (!(dev->flags & IFF_POINTOPOINT) && p->iph.daddr)) return -EINVAL; t = netdev_priv(dev); } - ipip6_tunnel_update(t, &p, t->fwmark); + ipip6_tunnel_update(t, p, t->fwmark); } - if (copy_to_user(ifr->ifr_ifru.ifru_data, &t->parms, sizeof(p))) - return -EFAULT; return 0; } static int -ipip6_tunnel_del(struct net_device *dev, struct ifreq *ifr) +ipip6_tunnel_del(struct net_device *dev, struct ip_tunnel_parm *p) { struct ip_tunnel *t = netdev_priv(dev); - struct ip_tunnel_parm p; if (!ns_capable(t->net->user_ns, CAP_NET_ADMIN)) return -EPERM; if (dev == dev_to_sit_net(dev)->fb_tunnel_dev) { - if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) - return -EFAULT; - t = ipip6_tunnel_locate(t->net, &p, 0); + t = ipip6_tunnel_locate(t->net, p, 0); if (!t) return -ENOENT; if (t == netdev_priv(dev_to_sit_net(dev)->fb_tunnel_dev)) @@ -1366,18 +1346,32 @@ ipip6_tunnel_del(struct net_device *dev, struct ifreq *ifr) return 0; } +static int +ipip6_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm *p, int cmd) +{ + switch (cmd) { + case SIOCGETTUNNEL: + return ipip6_tunnel_get(dev, p); + case SIOCADDTUNNEL: + return ipip6_tunnel_add(dev, p); + case SIOCCHGTUNNEL: + return ipip6_tunnel_change(dev, p); + case SIOCDELTUNNEL: + return ipip6_tunnel_del(dev, p); + default: + return -EINVAL; + } +} + static int ipip6_tunnel_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { switch (cmd) { case SIOCGETTUNNEL: - return ipip6_tunnel_get(dev, ifr); case SIOCADDTUNNEL: - return ipip6_tunnel_add(dev, ifr); case SIOCCHGTUNNEL: - return ipip6_tunnel_change(dev, ifr); case SIOCDELTUNNEL: - return ipip6_tunnel_del(dev, ifr); + return ip_tunnel_ioctl(dev, ifr, cmd); case SIOCGETPRL: return ipip6_tunnel_get_prl(dev, ifr); case SIOCADDPRL: @@ -1404,6 +1398,7 @@ static const struct net_device_ops ipip6_netdev_ops = { .ndo_do_ioctl = ipip6_tunnel_ioctl, .ndo_get_stats64 = ip_tunnel_get_stats64, .ndo_get_iflink = ip_tunnel_get_iflink, + .ndo_tunnel_ctl = ipip6_tunnel_ctl, }; static void ipip6_dev_free(struct net_device *dev) From patchwork Tue May 19 13:03:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 219011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F77BC433E2 for ; Tue, 19 May 2020 13:04:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75FA720829 for ; Tue, 19 May 2020 13:04:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="lwzn2rID" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729026AbgESNEU (ORCPT ); Tue, 19 May 2020 09:04:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728877AbgESNEJ (ORCPT ); Tue, 19 May 2020 09:04:09 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E753C08C5C3; Tue, 19 May 2020 06:03:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=ztGaRGjmnfTDhAKwb1uAT+sXQk1EV/hKojrYxDtc3CE=; b=lwzn2rID1tguj1XlyFWT1MT166 fhEPC3Df2l0Titlte6j/Yp9HUFvPFJ37gQ7nCxNrGGB7nSTnnb+6M7/AUA+6Cq+3TpEUCgx3f/qjq hMc3yDd9sWwkUUIPOvlfzHrnOThilQY9Dhod9/ICp21dVvvfWf07gE92Nk66OxzQA5AZAQSMFfQMo BccSDRqdVxnbX56gCPVnWTDal7WHvS4H677IiYfNlxDhBODeXcudfowAsBHuzdespgc6LX2YO1LgY hm5qjjHTpz06wvB7dVeWptep1VswcN6ZiVaBJvzKXjlY+eY750Lv9FEA1UqYKO+jvKAcQj1lD25Kb +gLsye4g==; Received: from [2001:4bb8:188:1506:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jb1uH-0004Ae-4w; Tue, 19 May 2020 13:03:41 +0000 From: Christoph Hellwig To: "David S. Miller" , Jakub Kicinski Cc: Alexey Kuznetsov , Hideaki YOSHIFUJI , Steffen Klassert , Herbert Xu , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/9] ipv6: stub out even more of addrconf_set_dstaddr if SIT is disabled Date: Tue, 19 May 2020 15:03:17 +0200 Message-Id: <20200519130319.1464195-8-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200519130319.1464195-1-hch@lst.de> References: <20200519130319.1464195-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There is no point in copying the structure from userspace or looking up a device if SIT support is not disabled and we'll eventually return -ENODEV anyway. Signed-off-by: Christoph Hellwig --- net/ipv6/addrconf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index ab7e839753aed..8300176f91e74 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -2794,6 +2794,9 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg) struct net_device *dev; int err = -EINVAL; + if (!IS_ENABLED(CONFIG_IPV6_SIT)) + return -ENODEV; + rtnl_lock(); err = -EFAULT; @@ -2806,7 +2809,6 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg) if (!dev) goto err_exit; -#if IS_ENABLED(CONFIG_IPV6_SIT) if (dev->type == ARPHRD_SIT) { const struct net_device_ops *ops = dev->netdev_ops; struct ifreq ifr; @@ -2842,7 +2844,6 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg) err = dev_open(dev, NULL); } } -#endif err_exit: rtnl_unlock(); From patchwork Tue May 19 13:03:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 219012 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28670C433E1 for ; Tue, 19 May 2020 13:04:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3F052081A for ; Tue, 19 May 2020 13:04:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="IOR3UDJn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729054AbgESNEX (ORCPT ); Tue, 19 May 2020 09:04:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729008AbgESNEP (ORCPT ); Tue, 19 May 2020 09:04:15 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DF32C08C5C6; Tue, 19 May 2020 06:04:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=vbZ3Gk3U+uf9dFZUpTloiSgwD+BngwLojurLSGg3KgY=; b=IOR3UDJnzSh0iomJNankSbhqf2 6sKfmoF7jHsNqwgVVhoZRmZxNIMfLp/k80jlLjltPPx0oJ/WabY5hz95X1jOlVbUzTi1Hw+cZzFKD 8aoZIu3O+ZGLtdj0YtqCfS136Kp8hpp/Gn3r+In+WViLnvn+qeyEDN2N9l9vET9JCddYX90eSvOkc V6dKMNBg6IIwAVP4j4MBtJ94oqCHEAW2K0H/MjjMLqKteo3gxgqGldGb/GVFRAyRDd6iBFn5GR1et YRw+ixSLnNggzfm0Fk5H1Yd6g1ianjMhpjjHkrKvgJIy2U0A9+prdUP1SEgzsDCAhdjASAoxjm3f7 nxC2Ts0g==; Received: from [2001:4bb8:188:1506:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jb1uJ-0004DQ-V3; Tue, 19 May 2020 13:03:44 +0000 From: Christoph Hellwig To: "David S. Miller" , Jakub Kicinski Cc: Alexey Kuznetsov , Hideaki YOSHIFUJI , Steffen Klassert , Herbert Xu , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 8/9] ipv6: streamline addrconf_set_dstaddr Date: Tue, 19 May 2020 15:03:18 +0200 Message-Id: <20200519130319.1464195-9-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200519130319.1464195-1-hch@lst.de> References: <20200519130319.1464195-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Factor out a addrconf_set_sit_dstaddr helper for the actual work if we found a SIT device, and only hold the rtnl lock around the device lookup and that new helper, as there is no point in holding it over a copy_from_user call. Signed-off-by: Christoph Hellwig --- net/ipv6/addrconf.c | 87 ++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 49 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 8300176f91e74..c827edf877414 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -2783,6 +2783,38 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao) in6_dev_put(in6_dev); } +static int addrconf_set_sit_dstaddr(struct net *net, struct net_device *dev, + struct in6_ifreq *ireq) +{ + struct ip_tunnel_parm p = { }; + mm_segment_t oldfs = get_fs(); + struct ifreq ifr; + int err; + + if (!(ipv6_addr_type(&ireq->ifr6_addr) & IPV6_ADDR_COMPATv4)) + return -EADDRNOTAVAIL; + + p.iph.daddr = ireq->ifr6_addr.s6_addr32[3]; + p.iph.version = 4; + p.iph.ihl = 5; + p.iph.protocol = IPPROTO_IPV6; + p.iph.ttl = 64; + ifr.ifr_ifru.ifru_data = (__force void __user *)&p; + + if (!dev->netdev_ops->ndo_do_ioctl) + return -EOPNOTSUPP; + set_fs(KERNEL_DS); + err = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCADDTUNNEL); + set_fs(oldfs); + if (err) + return err; + + dev = __dev_get_by_name(net, p.name); + if (!dev) + return -ENOBUFS; + return dev_open(dev, NULL); +} + /* * Set destination address. * Special case for SIT interfaces where we create a new "virtual" @@ -2790,62 +2822,19 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao) */ int addrconf_set_dstaddr(struct net *net, void __user *arg) { - struct in6_ifreq ireq; struct net_device *dev; - int err = -EINVAL; + struct in6_ifreq ireq; + int err = -ENODEV; if (!IS_ENABLED(CONFIG_IPV6_SIT)) return -ENODEV; - - rtnl_lock(); - - err = -EFAULT; if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq))) - goto err_exit; + return -EFAULT; + rtnl_lock(); dev = __dev_get_by_index(net, ireq.ifr6_ifindex); - - err = -ENODEV; - if (!dev) - goto err_exit; - - if (dev->type == ARPHRD_SIT) { - const struct net_device_ops *ops = dev->netdev_ops; - struct ifreq ifr; - struct ip_tunnel_parm p; - - err = -EADDRNOTAVAIL; - if (!(ipv6_addr_type(&ireq.ifr6_addr) & IPV6_ADDR_COMPATv4)) - goto err_exit; - - memset(&p, 0, sizeof(p)); - p.iph.daddr = ireq.ifr6_addr.s6_addr32[3]; - p.iph.saddr = 0; - p.iph.version = 4; - p.iph.ihl = 5; - p.iph.protocol = IPPROTO_IPV6; - p.iph.ttl = 64; - ifr.ifr_ifru.ifru_data = (__force void __user *)&p; - - if (ops->ndo_do_ioctl) { - mm_segment_t oldfs = get_fs(); - - set_fs(KERNEL_DS); - err = ops->ndo_do_ioctl(dev, &ifr, SIOCADDTUNNEL); - set_fs(oldfs); - } else - err = -EOPNOTSUPP; - - if (err == 0) { - err = -ENOBUFS; - dev = __dev_get_by_name(net, p.name); - if (!dev) - goto err_exit; - err = dev_open(dev, NULL); - } - } - -err_exit: + if (dev && dev->type == ARPHRD_SIT) + err = addrconf_set_sit_dstaddr(net, dev, &ireq); rtnl_unlock(); return err; }