Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2177209ybm; Thu, 23 May 2019 12:37:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqysXS55ssG01/VayrVTICzIGAG+0N6Y4QDcPkmgr8U6FIejudAL4rgJtn29OXx6eZGM/zuc X-Received: by 2002:a62:fb18:: with SMTP id x24mr41743991pfm.76.1558640261664; Thu, 23 May 2019 12:37:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558640261; cv=none; d=google.com; s=arc-20160816; b=WgMGFQThax8B0eMnHLaN4QAQWV9CiQXDCJV21edZmmUAKZM4X+LDyDPi0g0yPSpgWd xTFKSqoYTehwx2nCgwh+iO/zky5f+/vJ1soqNmFZMOtSHRzNkWJVOjIt2rS0bMqSCA1C eOaGBim3mVMChC5+Hre8o1Atlbv1UwlzocbvU/91wa0QEdkIO9Cpvg7NLcmX1H33ZNYs J+x8M9oT2nYJk7inmwAtGncodOS2QvrauD47XYeLRO5NgU5+xpJTzQVWPcn6IWYYYdK3 qiTKMcbAFm7UReq16/lCCp4+NCwwPicUp2B2MhbpsLEQKA9NG+xDMLLLWiCOiVpNHNCV GeEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SKlvcE1g/Ha2D/wcqFgUEZUtRf0ngV2Vng6Gzj07mW4=; b=GoA5frqpnQbalyEZK0kBslWx0mu57Db8SIeiAn3loJKn/QukL5Lgn3/RoMpwSh4Hv2 AcXUg316SHCSPJmX7oEFaxkv/NrvLBAD5wR+/SKrNnJw1MWHZzwByM0Lsu3kLAWPqBze NUksr/kj4eeRtUw9EoCZy9V/gQRP6boPtU4E7TYotnAmH91odmV2cRfleQC+D/8i6Q43 8KkUG0ykl0ScSrcQl7DXpy1BdX/wC5AtB7xPqikjrI/4js1nrPTdGKNzY8pjQfbLu1kd uaCw3yLL5C6SaRsWR++gRXXMvO5qRiqzH21fgJIL/bwktxTETGSgX48j5aGohNMAw1MI os5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jeH8OGKJ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l32si534528pjb.20.2019.05.23.12.37.26; Thu, 23 May 2019 12:37:41 -0700 (PDT) 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=@kernel.org header.s=default header.b=jeH8OGKJ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391777AbfEWTf1 (ORCPT + 99 others); Thu, 23 May 2019 15:35:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:38680 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390681AbfEWT0q (ORCPT ); Thu, 23 May 2019 15:26:46 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 36410206BA; Thu, 23 May 2019 19:26:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558639605; bh=Jm4gOeMZDy0CWa0ohmtarmH9iyQ6p78f9xr7urk7Y3k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jeH8OGKJZ0FvkYBChRfK13LPIlpD3YMAnqLAlYXGE2tBXB6OgBZi4T7IxD95cw/5+ YhigK3QNUfu9rk71QqoONiwJidZxoPNgQ0W0UmdZCdWDTvS0MTdYXpVIXt7XNuZ1HU WvwPn3o7fZFJMfH29JQIOw+Oz4x3+nLKcygw23aU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sabrina Dubroca , Nicolas Dichtel , "David S. Miller" , Dan Winship Subject: [PATCH 5.1 010/122] rtnetlink: always put IFLA_LINK for links with a link-netnsid Date: Thu, 23 May 2019 21:05:32 +0200 Message-Id: <20190523181706.363871384@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181705.091418060@linuxfoundation.org> References: <20190523181705.091418060@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sabrina Dubroca [ Upstream commit feadc4b6cf42a53a8a93c918a569a0b7e62bd350 ] Currently, nla_put_iflink() doesn't put the IFLA_LINK attribute when iflink == ifindex. In some cases, a device can be created in a different netns with the same ifindex as its parent. That device will not dump its IFLA_LINK attribute, which can confuse some userspace software that expects it. For example, if the last ifindex created in init_net and foo are both 8, these commands will trigger the issue: ip link add parent type dummy # ifindex 9 ip link add link parent netns foo type macvlan # ifindex 9 in ns foo So, in case a device puts the IFLA_LINK_NETNSID attribute in a dump, always put the IFLA_LINK attribute as well. Thanks to Dan Winship for analyzing the original OpenShift bug down to the missing netlink attribute. v2: change Fixes tag, it's been here forever, as Nicolas Dichtel said add Nicolas' ack v3: change Fixes tag fix subject typo, spotted by Edward Cree Analyzed-by: Dan Winship Fixes: d8a5ec672768 ("[NET]: netlink support for moving devices between network namespaces.") Signed-off-by: Sabrina Dubroca Acked-by: Nicolas Dichtel Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/rtnetlink.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1496,14 +1496,15 @@ static int put_master_ifindex(struct sk_ return ret; } -static int nla_put_iflink(struct sk_buff *skb, const struct net_device *dev) +static int nla_put_iflink(struct sk_buff *skb, const struct net_device *dev, + bool force) { int ifindex = dev_get_iflink(dev); - if (dev->ifindex == ifindex) - return 0; + if (force || dev->ifindex != ifindex) + return nla_put_u32(skb, IFLA_LINK, ifindex); - return nla_put_u32(skb, IFLA_LINK, ifindex); + return 0; } static noinline_for_stack int nla_put_ifalias(struct sk_buff *skb, @@ -1520,6 +1521,8 @@ static int rtnl_fill_link_netnsid(struct const struct net_device *dev, struct net *src_net) { + bool put_iflink = false; + if (dev->rtnl_link_ops && dev->rtnl_link_ops->get_link_net) { struct net *link_net = dev->rtnl_link_ops->get_link_net(dev); @@ -1528,10 +1531,12 @@ static int rtnl_fill_link_netnsid(struct if (nla_put_s32(skb, IFLA_LINK_NETNSID, id)) return -EMSGSIZE; + + put_iflink = true; } } - return 0; + return nla_put_iflink(skb, dev, put_iflink); } static int rtnl_fill_link_af(struct sk_buff *skb, @@ -1617,7 +1622,6 @@ static int rtnl_fill_ifinfo(struct sk_bu #ifdef CONFIG_RPS nla_put_u32(skb, IFLA_NUM_RX_QUEUES, dev->num_rx_queues) || #endif - nla_put_iflink(skb, dev) || put_master_ifindex(skb, dev) || nla_put_u8(skb, IFLA_CARRIER, netif_carrier_ok(dev)) || (dev->qdisc &&