From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Serhey Popovych , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 3.18 044/101] veth: Be more robust on network device creation when no attributes Date: Mon, 9 Apr 2018 00:35:54 +0000 Message-ID: <20180409003505.164715-44-alexander.levin@microsoft.com> References: <20180409003505.164715-1-alexander.levin@microsoft.com> In-Reply-To: <20180409003505.164715-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: From: Serhey Popovych [ Upstream commit 191cdb3822e5df6b3c8b9f8cb8c4bf93f6cc90c7 ] There are number of problems with configuration peer network device in absence of IFLA_VETH_PEER attributes where attributes for main network device shared with peer. First it is not feasible to configure both network devices with same MAC address since this makes communication in such configuration problematic. This case can be reproduced with following sequence: # ip link add address 02:11:22:33:44:55 type veth # ip li sh ... 26: veth0@veth1: mtu 1500 qdisc \ noop state DOWN mode DEFAULT qlen 1000 link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff 27: veth1@veth0: mtu 1500 qdisc \ noop state DOWN mode DEFAULT qlen 1000 link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff Second it is not possible to register both main and peer network devices with same name, that happens when name for main interface is given with IFLA_IFNAME and same attribute reused for peer. This case can be reproduced with following sequence: # ip link add dev veth1a type veth RTNETLINK answers: File exists To fix both of the cases check if corresponding netlink attributes are taken from peer_tb when valid or name based on rtnl ops kind and random address is used. Signed-off-by: Serhey Popovych Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/veth.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index b6b322828549..dfe6d84d518f 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -357,7 +357,7 @@ static int veth_newlink(struct net *src_net, struct net= _device *dev, tbp =3D tb; } =20 - if (tbp[IFLA_IFNAME]) { + if (ifmp && tbp[IFLA_IFNAME]) { nla_strlcpy(ifname, tbp[IFLA_IFNAME], IFNAMSIZ); name_assign_type =3D NET_NAME_USER; } else { @@ -376,7 +376,7 @@ static int veth_newlink(struct net *src_net, struct net= _device *dev, return PTR_ERR(peer); } =20 - if (tbp[IFLA_ADDRESS] =3D=3D NULL) + if (!ifmp || !tbp[IFLA_ADDRESS]) eth_hw_addr_random(peer); =20 if (ifmp && (dev->ifindex !=3D 0)) --=20 2.15.1