From patchwork Thu May 14 14:50:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 1290421 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=OtJCogSS; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49NDxt3rVwz9sVD for ; Fri, 15 May 2020 00:51:14 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727944AbgENOvL (ORCPT ); Thu, 14 May 2020 10:51:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727930AbgENOvJ (ORCPT ); Thu, 14 May 2020 10:51:09 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C2D8C061A0C; Thu, 14 May 2020 07:51:09 -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=9aeupGr/vYCGhcnA5BL5/A+kju2wf0xeZ9G4QPK75kk=; b=OtJCogSSSaiBxkBNZ4yJOfrXZU dI9zMSPuNJmV+rSZltYlRcxDsXi3GjXO461DNt6dNJFuj5gHnDjgn2nR0evlkSKB3/S9FQ1H9mw/3 QtZygveZZFW4IcvmDV5KKrGqK9l/6U6VdTTvQP+IVF5V8N7UGd3EMRRmtMejKvmi/mnGnNpiSr3XR jTy3jDb3B3E3wVeYCMufyF50QqUdbhVvTMu52TISn8gQvwGOH5dky+bkQpgTiOwqEIFZULZ6LRJYi Ut3GVAmeVUc5y8WUYxrURS402agSCAc2b776F9poc51HkMJ3pFjsO1DjIi+P1IywafvANtmlnUer9 0dOdyRpA==; 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 1jZFCU-0007sz-Li; Thu, 14 May 2020 14:51:07 +0000 From: Christoph Hellwig To: "David S. Miller" , Jakub Kicinski Cc: Alexey Kuznetsov , Hideaki YOSHIFUJI , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] ipv4: streamline ipmr_new_tunnel Date: Thu, 14 May 2020 16:50:58 +0200 Message-Id: <20200514145101.3000612-2-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200514145101.3000612-1-hch@lst.de> References: <20200514145101.3000612-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 Reduce a few level of indentation to simplify the function. Signed-off-by: Christoph Hellwig --- net/ipv4/ipmr.c | 73 ++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 9cf83cc85e4ad..84541c601cfab 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -469,50 +469,49 @@ static bool ipmr_init_vif_indev(const struct net_device *dev) static struct net_device *ipmr_new_tunnel(struct net *net, struct vifctl *v) { - struct net_device *dev; + mm_segment_t oldfs = get_fs(); + struct net_device *tunnel_dev, *new_dev; + struct ip_tunnel_parm p = { }; + struct ifreq ifr; + int err; - dev = __dev_get_by_name(net, "tunl0"); + tunnel_dev = __dev_get_by_name(net, "tunl0"); + if (!tunnel_dev) + goto out; - if (dev) { - const struct net_device_ops *ops = dev->netdev_ops; - int err; - struct ifreq ifr; - struct ip_tunnel_parm 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; - 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 (!tunnel_dev->netdev_ops->ndo_do_ioctl) + goto out; - if (ops->ndo_do_ioctl) { - mm_segment_t oldfs = get_fs(); + set_fs(KERNEL_DS); + err = tunnel_dev->netdev_ops->ndo_do_ioctl(tunnel_dev, &ifr, + SIOCADDTUNNEL); + set_fs(oldfs); + if (err) + goto out; - set_fs(KERNEL_DS); - err = ops->ndo_do_ioctl(dev, &ifr, SIOCADDTUNNEL); - set_fs(oldfs); - } else { - err = -EOPNOTSUPP; - } - dev = NULL; + new_dev = __dev_get_by_name(net, p.name); + if (!new_dev) + goto out; - if (err == 0 && - (dev = __dev_get_by_name(net, p.name)) != NULL) { - dev->flags |= IFF_MULTICAST; - if (!ipmr_init_vif_indev(dev)) - goto failure; - if (dev_open(dev, NULL)) - goto failure; - dev_hold(dev); - } - } - return dev; + new_dev->flags |= IFF_MULTICAST; + if (!ipmr_init_vif_indev(new_dev)) + goto out_unregister; + if (dev_open(new_dev, NULL)) + goto out_unregister; + dev_hold(new_dev); + return new_dev; -failure: - unregister_netdevice(dev); +out_unregister: + unregister_netdevice(new_dev); +out: return NULL; } From patchwork Thu May 14 14:50:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 1290425 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=rtRDYrb4; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49NDyC3lQzz9sRK for ; Fri, 15 May 2020 00:51:31 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727976AbgENOvQ (ORCPT ); Thu, 14 May 2020 10:51:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726197AbgENOvN (ORCPT ); Thu, 14 May 2020 10:51:13 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2788FC061A0C; Thu, 14 May 2020 07:51:13 -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=TpVloFu6IYpJ0w9TRJEpII9AVAYGVXsstbhPcZAAyj0=; b=rtRDYrb4y/t7TRIpTg+hKWZdQ/ o+96IAlIwgi9xsGLHJx5TYq0sULQtqnfNoh7aKWN7FztTWdKNO3ySElMEmyLRDyP61E3d4ojiwGIW iKL3h2I8pJ+jdG6V4OAAl4F9ph6aWwoy7dR7vuERvaV14Ly4nWoK58L/QTrDjdqQ8SaBsFGXS3bY/ rt+ELRvLrScd6qefcuI2krS4LI2Ndb0NK6e+T4Rx3Goo4JrsNg8VqR077rYxxIYcRQ9twvHtJSO0N n9pDXaYDAZTuFmRy2O5OpU7e1Ij69ObD2kQJH/mg95VYVxLppff8q+GWgGGmZxiyXlIMD8S1QbqsZ 6Ke1Ghig==; 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 1jZFCX-0007tO-Nz; Thu, 14 May 2020 14:51:10 +0000 From: Christoph Hellwig To: "David S. Miller" , Jakub Kicinski Cc: Alexey Kuznetsov , Hideaki YOSHIFUJI , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] ipv4: consolidate the VIFF_TUNNEL handling in ipmr_new_tunnel Date: Thu, 14 May 2020 16:50:59 +0200 Message-Id: <20200514145101.3000612-3-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200514145101.3000612-1-hch@lst.de> References: <20200514145101.3000612-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 84541c601cfab..6bf2a88abe86e 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -419,37 +419,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) { @@ -507,12 +476,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) @@ -864,14 +843,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 Thu May 14 14:51:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 1290422 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=nplF2gXe; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49NDy12wh1z9sVF for ; Fri, 15 May 2020 00:51:21 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726197AbgENOvR (ORCPT ); Thu, 14 May 2020 10:51:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726763AbgENOvP (ORCPT ); Thu, 14 May 2020 10:51:15 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8780FC061A0C; Thu, 14 May 2020 07:51:15 -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=g3yEEkwwk4Q3j5s04IMTk/eTfXLS0xuwowPPt0s7L98=; b=nplF2gXenKKVcqt+1wEdBUqj7v Loe8nt/+DW1iGJ7jhXvkukFBLmvY/rM0giFPOjt3RMSkIIgWuw7OjznSnNWVNLgPcoLHjhqJ9gmSG BPKe+Xx/pJHbr6UURqoOlBVJZWFUSpGhfj4Hh8aAILxyXtU/1jufGJzpLyvZCo0hJsML3xE2wmfIi kWUXF1h8kfdnF2Rn+pFW5i3+Xsccz8wEXC7H8eCv5dRNNEzlVC6vWCDnzyui6Lp16VtcvfamREUBs tmeGi3X6/+LUsCx/kQ4+nokVaKMfQAbovxmAQO2KwUNGY4m+JSc47xyNwJu6+Ai1aVSdotj5Rdd6y H0aw5AqQ==; 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 1jZFCa-0007uA-PK; Thu, 14 May 2020 14:51:13 +0000 From: Christoph Hellwig To: "David S. Miller" , Jakub Kicinski Cc: Alexey Kuznetsov , Hideaki YOSHIFUJI , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] ipv4: use symbol_get to access ipip symbols Date: Thu, 14 May 2020 16:51:00 +0200 Message-Id: <20200514145101.3000612-4-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200514145101.3000612-1-hch@lst.de> References: <20200514145101.3000612-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 Instead of going through the ioctl handler from kernel space, use symbol_get to access the ip_tunnel_ioctl directly. Signed-off-by: Christoph Hellwig --- net/ipv4/ipmr.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 6bf2a88abe86e..3780ab694c574 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -438,10 +438,9 @@ static bool ipmr_init_vif_indev(const struct net_device *dev) static struct net_device *ipmr_new_tunnel(struct net *net, struct vifctl *v) { - mm_segment_t oldfs = get_fs(); + int (*tunnel_ctl)(struct net_device *, struct ip_tunnel_parm *, int); struct net_device *tunnel_dev, *new_dev; struct ip_tunnel_parm p = { }; - struct ifreq ifr; int err; tunnel_dev = __dev_get_by_name(net, "tunl0"); @@ -454,21 +453,17 @@ static struct net_device *ipmr_new_tunnel(struct net *net, struct vifctl *v) 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 (!tunnel_dev->netdev_ops->ndo_do_ioctl) - goto out; + tunnel_ctl = symbol_get(ip_tunnel_ioctl); + if (!tunnel_ctl) + return ERR_PTR(-ENOBUFS); - set_fs(KERNEL_DS); - err = tunnel_dev->netdev_ops->ndo_do_ioctl(tunnel_dev, &ifr, - SIOCADDTUNNEL); - set_fs(oldfs); - if (err) - goto out; + if (tunnel_ctl(tunnel_dev, &p, SIOCADDTUNNEL)) + goto out_symbol_put; new_dev = __dev_get_by_name(net, p.name); if (!new_dev) - goto out; + goto out_symbol_put; new_dev->flags |= IFF_MULTICAST; if (!ipmr_init_vif_indev(new_dev)) @@ -479,17 +474,18 @@ static struct net_device *ipmr_new_tunnel(struct net *net, struct vifctl *v) 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); + tunnel_ctl(tunnel_dev, &p, SIOCDELTUNNEL); dev_put(new_dev); new_dev = ERR_PTR(err); } + + symbol_put(ip_tunnel_ioctl); return new_dev; out_unregister: unregister_netdevice(new_dev); +out_symbol_put: + symbol_put(ipmr_new_tunnel); out: return ERR_PTR(-ENOBUFS); } From patchwork Thu May 14 14:51:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 1290424 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=bHVMonzJ; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49NDy86f3Fz9sVF for ; Fri, 15 May 2020 00:51:28 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728035AbgENOvV (ORCPT ); Thu, 14 May 2020 10:51:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728017AbgENOvT (ORCPT ); Thu, 14 May 2020 10:51:19 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AFE4C061A0E; Thu, 14 May 2020 07:51:18 -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=0AUA+C35O90CNEqWuihWhLytXpVCKHU/MNxz8OyW+Og=; b=bHVMonzJJM6bd2Mw7qZZA5RVCZ 9jYWddGzIR+yhHBBMOuK+6jTVuWG1SJszeWgxI3AOw5g5bHTUNKy5P8XagOC2kEVilXlIsprTCZnd TDpbJxzExaTxflRi6AksqgxgsIRtexQCgx6h3XGoNwtqn9ejWyH6d3yrYMfcE8rIXtFmNEeKlMlbi DPAEo18rOkVOYop4WksH37rCcY8WeDq4QTAzchGeDM3352feOsvq/0qiB8W0jtgYZbjYgzJyntJWX iQYryH/StjDY/YPcWm+HFoJcvkImjOMHe5OY2TjY50jdT7WwMi+FYheV45QE6hFE2qHOwU0fVdGVv bMHIBDNg==; 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 1jZFCd-0007w2-ON; Thu, 14 May 2020 14:51:16 +0000 From: Christoph Hellwig To: "David S. Miller" , Jakub Kicinski Cc: Alexey Kuznetsov , Hideaki YOSHIFUJI , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] ipv6: symbol_get to access a sit symbol Date: Thu, 14 May 2020 16:51:01 +0200 Message-Id: <20200514145101.3000612-5-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200514145101.3000612-1-hch@lst.de> References: <20200514145101.3000612-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 Instead of going through the ioctl handler from kernel space, use symbol_get to the newly factored out ipip6_set_dstaddr helper, bypassing addrconf.c entirely. Signed-off-by: Christoph Hellwig --- include/net/addrconf.h | 1 - include/net/ipv6.h | 2 ++ net/ipv6/addrconf.c | 66 ------------------------------------------ net/ipv6/af_inet6.c | 20 ++++++++++++- net/ipv6/sit.c | 41 ++++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 68 deletions(-) diff --git a/include/net/addrconf.h b/include/net/addrconf.h index fdb07105384ca..569eb03ae2440 100644 --- a/include/net/addrconf.h +++ b/include/net/addrconf.h @@ -76,7 +76,6 @@ void addrconf_cleanup(void); int addrconf_add_ifaddr(struct net *net, void __user *arg); int addrconf_del_ifaddr(struct net *net, void __user *arg); -int addrconf_set_dstaddr(struct net *net, void __user *arg); int ipv6_chk_addr(struct net *net, const struct in6_addr *addr, const struct net_device *dev, int strict); diff --git a/include/net/ipv6.h b/include/net/ipv6.h index 955badd1e8ffc..1b983f32c87ce 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h @@ -1080,6 +1080,8 @@ struct in6_addr *fl6_update_dst(struct flowi6 *fl6, const struct ipv6_txoptions *opt, struct in6_addr *orig); +int ipip6_set_dstaddr(struct net *net, void __user *arg); + /* * socket options (ipv6_sockglue.c) */ diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index fd885f06c4ed6..02186f00f91c5 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -2783,72 +2783,6 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao) in6_dev_put(in6_dev); } -/* - * Set destination address. - * Special case for SIT interfaces where we create a new "virtual" - * device. - */ -int addrconf_set_dstaddr(struct net *net, void __user *arg) -{ - struct in6_ifreq ireq; - struct net_device *dev; - int err = -EINVAL; - - rtnl_lock(); - - err = -EFAULT; - if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq))) - goto err_exit; - - dev = __dev_get_by_index(net, ireq.ifr6_ifindex); - - err = -ENODEV; - 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; - 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); - } - } -#endif - -err_exit: - rtnl_unlock(); - return err; -} - static int ipv6_mc_config(struct sock *sk, bool join, const struct in6_addr *addr, int ifindex) { diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c index 345baa0a754f4..3ec9734c7bb11 100644 --- a/net/ipv6/af_inet6.c +++ b/net/ipv6/af_inet6.c @@ -538,6 +538,19 @@ int inet6_getname(struct socket *sock, struct sockaddr *uaddr, } EXPORT_SYMBOL(inet6_getname); +static int inet6_ioctl_set_dstaddr(struct net *net, void __user *arg) +{ + int (*set_dstaddr)(struct net *, void __user *); + int err; + + set_dstaddr = symbol_get(ipip6_set_dstaddr); + if (!set_dstaddr) + return -EOPNOTSUPP; + err = set_dstaddr(net, arg); + symbol_put(ipip6_set_dstaddr); + return err; +} + int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) { struct sock *sk = sock->sk; @@ -554,7 +567,12 @@ int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) case SIOCDIFADDR: return addrconf_del_ifaddr(net, (void __user *) arg); case SIOCSIFDSTADDR: - return addrconf_set_dstaddr(net, (void __user *) arg); + /* Special case for SIT interfaces where we create a new + * "virtual" device. + */ + if (!IS_ENABLED(CONFIG_IPV6_SIT)) + return -ENODEV; + return inet6_ioctl_set_dstaddr(net, (void __user *) arg); default: if (!sk->sk_prot->ioctl) return -ENOIOCTLCMD; diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index 98954830c40ba..cb2cfa297f72e 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -274,6 +274,47 @@ static struct ip_tunnel *ipip6_tunnel_locate(struct net *net, return NULL; } +int ipip6_set_dstaddr(struct net *net, void __user *arg) +{ + struct ip_tunnel_parm p = { }; + struct in6_ifreq ireq; + struct net_device *tunnel_dev, *new_dev; + int err; + + rtnl_lock(); + err = -EFAULT; + if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq))) + goto out_unlock; + + err = -ENODEV; + tunnel_dev = __dev_get_by_index(net, ireq.ifr6_ifindex); + if (!tunnel_dev || tunnel_dev->type != ARPHRD_SIT) + goto out_unlock; + + err = -EADDRNOTAVAIL; + if (!(ipv6_addr_type(&ireq.ifr6_addr) & IPV6_ADDR_COMPATv4)) + goto out_unlock; + + 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; + p.iph.frag_off |= htons(IP_DF); + + err = -ENOBUFS; + if (!ipip6_tunnel_locate(dev_net(tunnel_dev), &p, true)) + goto out_unlock; + new_dev = __dev_get_by_name(net, p.name); + if (!new_dev) + goto out_unlock; + err = dev_open(new_dev, NULL); +out_unlock: + rtnl_unlock(); + return err; +} +EXPORT_SYMBOL_GPL(ipip6_set_dstaddr); + #define for_each_prl_rcu(start) \ for (prl = rcu_dereference(start); \ prl; \