Received: by 10.223.176.46 with SMTP id f43csp819020wra; Wed, 24 Jan 2018 06:27:51 -0800 (PST) X-Google-Smtp-Source: AH8x227HBBN1NH9Vkol/9UrdSFNDPN+v/KjvfP4rKu+gPYkl/6o311TeB4wqtkSIrdiUUyrECCPJ X-Received: by 2002:a17:902:b2c1:: with SMTP id x1-v6mr8350821plw.85.1516804071075; Wed, 24 Jan 2018 06:27:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516804071; cv=none; d=google.com; s=arc-20160816; b=VaBiKpP4CB9eAHTxNvMkK8ZfHOZX9mavF8AH4f8YWrolRLNYq0E1qZU5qv0HwyRX06 tiRKFls+KU5OybYmHXRC5MuZfvJS9ADK7J6xcYh8XgXkVEOMfan1HkWBAxs/N8eZiDlu NgeTqBukUwHh002Lr9ELYwq/eaO2/ZdxEwP8WAay136tHoW/iE2T8zfnX6/8bqQ8A73o S0SzxsjEQt9VwpMT52D5mWdBFHjWB7UfHuhB6TBWFVgDfiAhs7GQd2kt1zUb7+tfAXnK 4fArcFM1k8djhEKHOWkxW0bRc1Aiijo8kTpa2N/pB+fIAvzJlkHKgWtq8fsLDtU2Brv7 wV0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=stKKXRLxc6vvp7u3c8PKelpubIxkifEEFUK5bGFb6uw=; b=uwvRQhLYiY3apN5alELabtSpepSM+VD3y68QpD2nAJyz3y/L4Y1i5va2BH8UPgkT+9 WthEV/Sax+BtXpDb5Pqr/WZ8MZ4Y94O48JyakevS67Ip5pMzCjOmn4Veo3OlP5LznEtE d9Qw64x1zoNoEDF+0gKXH2yhQ8WXegJpfyAGSvqb2ZOik4TrF30BOUyJcC9RH4GYCDeD SwYG6XkfTku/fQM6rOUwoNnpGEOIlMM5e9aGsRfvrpbsBldpUl8+RmYSttfrL5AVkonH 7uLcFXgl7z1kCDCX8IYayYUJbkD8d8RwbgKEl++VGEPn9XmFB+tCBTKnt2E90aw4ZXNJ TXKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VXXt0Pcb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f126si2975097pfg.175.2018.01.24.06.27.37; Wed, 24 Jan 2018 06:27:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VXXt0Pcb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934069AbeAXO0x (ORCPT + 99 others); Wed, 24 Jan 2018 09:26:53 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:45995 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934021AbeAXO0v (ORCPT ); Wed, 24 Jan 2018 09:26:51 -0500 Received: by mail-wm0-f66.google.com with SMTP id i186so8786952wmi.4; Wed, 24 Jan 2018 06:26:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=stKKXRLxc6vvp7u3c8PKelpubIxkifEEFUK5bGFb6uw=; b=VXXt0PcbwZ4TuArLr6u0fB2PWDATT/vXzApnRYHxEPVO9suN9Et/46e1zfJBe6eeJM S7cr9SLr1WEcmoNWfF4v/s+co7sInPq3EcEkU9uHfn11E7An25eSl3+m3MnpoTxNefP2 ne7R5AWfRQSQAt1ARyO8k6UJj0SXfZrItpEVf+fbwzn84i5agEg1oqdikukdCmdIcihI RDt9iKVdVT6ueVkU3vLarGUu/dD4Agp4oAyKSkCCNWCepMBhDYVrr8o3eQInJAD6xWE4 Pa7VvVb7bKephcib4i3nUXDvGsnabsPLy5tWxHjDtbJ3f/LtTCZ4BOLwkQkPuSSzITY4 z69g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=stKKXRLxc6vvp7u3c8PKelpubIxkifEEFUK5bGFb6uw=; b=Qi42rSJihPK3TxQwuAy6Ef+308LinCmdZbob1TbnYKhDxKNTxW4/dg7Roeul2sE4LL lgj6GcgfS77hXNk8qllYCaqHUASAAYBVSg6591sG/GuVd3bkMrLhU3JCijm83aiJnAOQ ALj7x1ZoUNmX97MYnIgNk21rS5rmq1yvulKHyLEyGhgxkGYWTZPPUvMK/nOvsObHJrkT Z9AQkCAmqsk2NvotvJqJ3wy5ECUycVX6lbLz+qwKptgCxBokHqRi6OS5TL+7fFjGQcYw 3DgsMuf84tj9N5pFjQyMVNh27RazmJvXtwNV1+UQggLiMQY5fqNsBAr0aZEi2gstBbZT P7eQ== X-Gm-Message-State: AKwxytdm5kO7TLjKjnA/hjYgcC67XKSGuVO6KiacxHBiUmAgkN9M7AV5 +XyWdoFot4bQdNBPJad9VPZQat7H15k= X-Received: by 10.28.191.19 with SMTP id p19mr4677551wmf.142.1516804009666; Wed, 24 Jan 2018 06:26:49 -0800 (PST) Received: from localhost.localdomain (eap108107.extern.uni-tuebingen.de. [134.2.108.107]) by smtp.gmail.com with ESMTPSA id q48sm3992178wrb.31.2018.01.24.06.26.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jan 2018 06:26:49 -0800 (PST) From: Christian Brauner X-Google-Original-From: Christian Brauner To: netdev@vger.kernel.org Cc: ebiederm@xmission.com, davem@davemloft.net, dsahern@gmail.com, fw@strlen.de, daniel@iogearbox.net, lucien.xin@gmail.com, mschiffer@universe-factory.net, jakub.kicinski@netronome.com, vyasevich@gmail.com, linux-kernel@vger.kernel.org, jbenc@redhat.com, w.bumiller@proxmox.com, nicolas.dichtel@6wind.com, Christian Brauner Subject: [PATCH net-next 3/3 V1] rtnetlink: enable IFLA_IF_NETNSID for RTM_DELLINK Date: Wed, 24 Jan 2018 15:26:34 +0100 Message-Id: <20180124142634.17766-4-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180124142634.17766-1-christian.brauner@ubuntu.com> References: <20180124142634.17766-1-christian.brauner@ubuntu.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org - Backwards Compatibility: If userspace wants to determine whether RTM_DELLINK supports the IFLA_IF_NETNSID property they should first send an RTM_GETLINK request with IFLA_IF_NETNSID on lo. If either EACCESS is returned or the reply does not include IFLA_IF_NETNSID userspace should assume that IFLA_IF_NETNSID is not supported on this kernel. If the reply does contain an IFLA_IF_NETNSID property userspace can send an RTM_DELLINK with a IFLA_IF_NETNSID property. If they receive EOPNOTSUPP then the kernel does not support the IFLA_IF_NETNSID property with RTM_DELLINK. Userpace should then fallback to other means. - Security: Callers must have CAP_NET_ADMIN in the owning user namespace of the target network namespace. Signed-off-by: Christian Brauner --- Changelog 2018-01-24: * Preserve old behavior and report -ENODEV when either ifindex or ifname is provided and IFLA_GROUP is set. Spotted by Wolfgang Bumiller. --- net/core/rtnetlink.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index a4d4409685e3..fdb9e8777abb 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -2630,36 +2630,53 @@ static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) { struct net *net = sock_net(skb->sk); - struct net_device *dev; + struct net *tgt_net = net; + struct net_device *dev = NULL; struct ifinfomsg *ifm; char ifname[IFNAMSIZ]; struct nlattr *tb[IFLA_MAX+1]; int err; + int netnsid = -1; err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy, extack); if (err < 0) return err; - if (tb[IFLA_IF_NETNSID]) - return -EOPNOTSUPP; - if (tb[IFLA_IFNAME]) nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ); + if (tb[IFLA_IF_NETNSID]) { + netnsid = nla_get_s32(tb[IFLA_IF_NETNSID]); + tgt_net = get_target_net(NETLINK_CB(skb).sk, netnsid); + if (IS_ERR(tgt_net)) + return PTR_ERR(tgt_net); + } + + err = -EINVAL; ifm = nlmsg_data(nlh); if (ifm->ifi_index > 0) - dev = __dev_get_by_index(net, ifm->ifi_index); + dev = __dev_get_by_index(tgt_net, ifm->ifi_index); else if (tb[IFLA_IFNAME]) - dev = __dev_get_by_name(net, ifname); + dev = __dev_get_by_name(tgt_net, ifname); else if (tb[IFLA_GROUP]) - return rtnl_group_dellink(net, nla_get_u32(tb[IFLA_GROUP])); + err = rtnl_group_dellink(tgt_net, nla_get_u32(tb[IFLA_GROUP])); else - return -EINVAL; + goto out; - if (!dev) - return -ENODEV; + if (!dev) { + if (tb[IFLA_IFNAME] || ifm->ifi_index > 0) + err = -ENODEV; - return rtnl_delete_link(dev); + goto out; + } + + err = rtnl_delete_link(dev); + +out: + if (netnsid >= 0) + put_net(tgt_net); + + return err; } int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm) -- 2.14.1