netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH ipsec 0/2] xfrm interface: bug fix on changelink
@ 2019-07-10  7:45 Nicolas Dichtel
  2019-07-10  7:45 ` [PATCH ipsec 1/2] xfrm interface: avoid corruption " Nicolas Dichtel
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Nicolas Dichtel @ 2019-07-10  7:45 UTC (permalink / raw)
  To: steffen.klassert, davem; +Cc: netdev


Here are two bug fix seen by code review. The first one avoids a corruption of
existing xfrm interfaces and the second is a minor fix of an error message.

 include/net/xfrm.h        |  1 -
 net/xfrm/xfrm_interface.c | 20 ++++++--------------
 2 files changed, 6 insertions(+), 15 deletions(-)

Regards,
Nicolas


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH ipsec 1/2] xfrm interface: avoid corruption on changelink
  2019-07-10  7:45 [PATCH ipsec 0/2] xfrm interface: bug fix on changelink Nicolas Dichtel
@ 2019-07-10  7:45 ` Nicolas Dichtel
  2019-07-10  7:45 ` [PATCH ipsec 2/2] xfrm interface: ifname may be wrong in logs Nicolas Dichtel
  2019-07-15  9:52 ` [PATCH ipsec 0/2] xfrm interface: bug fix on changelink Nicolas Dichtel
  2 siblings, 0 replies; 10+ messages in thread
From: Nicolas Dichtel @ 2019-07-10  7:45 UTC (permalink / raw)
  To: steffen.klassert, davem; +Cc: netdev, Nicolas Dichtel

The new parameters must not be stored in the netdev_priv() before
validation, it may corrupt the interface. Note also that if data is NULL,
only a memset() is done.

$ ip link add xfrm1 type xfrm dev lo if_id 1
$ ip link add xfrm2 type xfrm dev lo if_id 2
$ ip link set xfrm1 type xfrm dev lo if_id 2
RTNETLINK answers: File exists
$ ip -d link list dev xfrm1
5: xfrm1@lo: <NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/none 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 minmtu 68 maxmtu 1500
    xfrm if_id 0x2 addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535

=> "if_id 0x2"

Fixes: f203b76d7809 ("xfrm: Add virtual xfrm interfaces")
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 net/xfrm/xfrm_interface.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/net/xfrm/xfrm_interface.c b/net/xfrm/xfrm_interface.c
index 7dbe0c608df5..dfa5aebdec57 100644
--- a/net/xfrm/xfrm_interface.c
+++ b/net/xfrm/xfrm_interface.c
@@ -671,12 +671,12 @@ static int xfrmi_changelink(struct net_device *dev, struct nlattr *tb[],
 			   struct nlattr *data[],
 			   struct netlink_ext_ack *extack)
 {
-	struct xfrm_if *xi = netdev_priv(dev);
 	struct net *net = dev_net(dev);
+	struct xfrm_if_parms p;
+	struct xfrm_if *xi;
 
-	xfrmi_netlink_parms(data, &xi->p);
-
-	xi = xfrmi_locate(net, &xi->p);
+	xfrmi_netlink_parms(data, &p);
+	xi = xfrmi_locate(net, &p);
 	if (!xi) {
 		xi = netdev_priv(dev);
 	} else {
@@ -684,7 +684,7 @@ static int xfrmi_changelink(struct net_device *dev, struct nlattr *tb[],
 			return -EEXIST;
 	}
 
-	return xfrmi_update(xi, &xi->p);
+	return xfrmi_update(xi, &p);
 }
 
 static size_t xfrmi_get_size(const struct net_device *dev)
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH ipsec 2/2] xfrm interface: ifname may be wrong in logs
  2019-07-10  7:45 [PATCH ipsec 0/2] xfrm interface: bug fix on changelink Nicolas Dichtel
  2019-07-10  7:45 ` [PATCH ipsec 1/2] xfrm interface: avoid corruption " Nicolas Dichtel
@ 2019-07-10  7:45 ` Nicolas Dichtel
  2019-07-15  9:52 ` [PATCH ipsec 0/2] xfrm interface: bug fix on changelink Nicolas Dichtel
  2 siblings, 0 replies; 10+ messages in thread
From: Nicolas Dichtel @ 2019-07-10  7:45 UTC (permalink / raw)
  To: steffen.klassert, davem; +Cc: netdev, Nicolas Dichtel

The ifname is copied when the interface is created, but is never updated
later. In fact, this property is used only in one error message, where the
netdevice pointer is available, thus let's use it.

Fixes: f203b76d7809 ("xfrm: Add virtual xfrm interfaces")
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 include/net/xfrm.h        |  1 -
 net/xfrm/xfrm_interface.c | 10 +---------
 2 files changed, 1 insertion(+), 10 deletions(-)

diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index a2907873ed56..287e39753d94 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -988,7 +988,6 @@ static inline void xfrm_dst_destroy(struct xfrm_dst *xdst)
 void xfrm_dst_ifdown(struct dst_entry *dst, struct net_device *dev);
 
 struct xfrm_if_parms {
-	char name[IFNAMSIZ];	/* name of XFRM device */
 	int link;		/* ifindex of underlying L2 interface */
 	u32 if_id;		/* interface identifyer */
 };
diff --git a/net/xfrm/xfrm_interface.c b/net/xfrm/xfrm_interface.c
index dfa5aebdec57..a60d391f7ebe 100644
--- a/net/xfrm/xfrm_interface.c
+++ b/net/xfrm/xfrm_interface.c
@@ -145,8 +145,6 @@ static int xfrmi_create(struct net_device *dev)
 	if (err < 0)
 		goto out;
 
-	strcpy(xi->p.name, dev->name);
-
 	dev_hold(dev);
 	xfrmi_link(xfrmn, xi);
 
@@ -294,7 +292,7 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
 	if (tdev == dev) {
 		stats->collisions++;
 		net_warn_ratelimited("%s: Local routing loop detected!\n",
-				     xi->p.name);
+				     dev->name);
 		goto tx_err_dst_release;
 	}
 
@@ -638,12 +636,6 @@ static int xfrmi_newlink(struct net *src_net, struct net_device *dev,
 	int err;
 
 	xfrmi_netlink_parms(data, &p);
-
-	if (!tb[IFLA_IFNAME])
-		return -EINVAL;
-
-	nla_strlcpy(p.name, tb[IFLA_IFNAME], IFNAMSIZ);
-
 	xi = xfrmi_locate(net, &p);
 	if (xi)
 		return -EEXIST;
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH ipsec 0/2] xfrm interface: bug fix on changelink
  2019-07-10  7:45 [PATCH ipsec 0/2] xfrm interface: bug fix on changelink Nicolas Dichtel
  2019-07-10  7:45 ` [PATCH ipsec 1/2] xfrm interface: avoid corruption " Nicolas Dichtel
  2019-07-10  7:45 ` [PATCH ipsec 2/2] xfrm interface: ifname may be wrong in logs Nicolas Dichtel
@ 2019-07-15  9:52 ` Nicolas Dichtel
  2019-07-15 10:00   ` [PATCH ipsec v2 0/4] xfrm interface: bugs fixes Nicolas Dichtel
  2 siblings, 1 reply; 10+ messages in thread
From: Nicolas Dichtel @ 2019-07-15  9:52 UTC (permalink / raw)
  To: steffen.klassert, davem; +Cc: netdev

Le 10/07/2019 à 09:45, Nicolas Dichtel a écrit :
> 
> Here are two bug fix seen by code review. The first one avoids a corruption of
> existing xfrm interfaces and the second is a minor fix of an error message.
> 
>  include/net/xfrm.h        |  1 -
>  net/xfrm/xfrm_interface.c | 20 ++++++--------------
>  2 files changed, 6 insertions(+), 15 deletions(-)
Please, drop this series, I will resend it.


Regards,
Nicolas

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH ipsec v2 0/4] xfrm interface: bugs fixes
  2019-07-15  9:52 ` [PATCH ipsec 0/2] xfrm interface: bug fix on changelink Nicolas Dichtel
@ 2019-07-15 10:00   ` Nicolas Dichtel
  2019-07-15 10:00     ` [PATCH ipsec v2 1/4] xfrm interface: avoid corruption on changelink Nicolas Dichtel
                       ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Nicolas Dichtel @ 2019-07-15 10:00 UTC (permalink / raw)
  To: steffen.klassert, davem; +Cc: netdev


Here is a bunch of bugs fixes. Some have been seen by code review and some when
playing with x-netns.
The details are in each patch.

v1 -> v2:
 - add patch #3 and #4

 include/net/xfrm.h        |  2 --
 net/xfrm/xfrm_interface.c | 56 +++++++++++++++++++++--------------------------
 2 files changed, 25 insertions(+), 33 deletions(-)

Regards,
Nicolas


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH ipsec v2 1/4] xfrm interface: avoid corruption on changelink
  2019-07-15 10:00   ` [PATCH ipsec v2 0/4] xfrm interface: bugs fixes Nicolas Dichtel
@ 2019-07-15 10:00     ` Nicolas Dichtel
  2019-07-15 10:00     ` [PATCH ipsec v2 2/4] xfrm interface: ifname may be wrong in logs Nicolas Dichtel
                       ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Nicolas Dichtel @ 2019-07-15 10:00 UTC (permalink / raw)
  To: steffen.klassert, davem; +Cc: netdev, Nicolas Dichtel, Julien Floret

The new parameters must not be stored in the netdev_priv() before
validation, it may corrupt the interface. Note also that if data is NULL,
only a memset() is done.

$ ip link add xfrm1 type xfrm dev lo if_id 1
$ ip link add xfrm2 type xfrm dev lo if_id 2
$ ip link set xfrm1 type xfrm dev lo if_id 2
RTNETLINK answers: File exists
$ ip -d link list dev xfrm1
5: xfrm1@lo: <NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/none 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 minmtu 68 maxmtu 1500
    xfrm if_id 0x2 addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535

=> "if_id 0x2"

Fixes: f203b76d7809 ("xfrm: Add virtual xfrm interfaces")
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Tested-by: Julien Floret <julien.floret@6wind.com>
---
 net/xfrm/xfrm_interface.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/net/xfrm/xfrm_interface.c b/net/xfrm/xfrm_interface.c
index 74868f9d81fb..2310dc9e35c2 100644
--- a/net/xfrm/xfrm_interface.c
+++ b/net/xfrm/xfrm_interface.c
@@ -671,12 +671,12 @@ static int xfrmi_changelink(struct net_device *dev, struct nlattr *tb[],
 			   struct nlattr *data[],
 			   struct netlink_ext_ack *extack)
 {
-	struct xfrm_if *xi = netdev_priv(dev);
 	struct net *net = dev_net(dev);
+	struct xfrm_if_parms p;
+	struct xfrm_if *xi;
 
-	xfrmi_netlink_parms(data, &xi->p);
-
-	xi = xfrmi_locate(net, &xi->p);
+	xfrmi_netlink_parms(data, &p);
+	xi = xfrmi_locate(net, &p);
 	if (!xi) {
 		xi = netdev_priv(dev);
 	} else {
@@ -684,7 +684,7 @@ static int xfrmi_changelink(struct net_device *dev, struct nlattr *tb[],
 			return -EEXIST;
 	}
 
-	return xfrmi_update(xi, &xi->p);
+	return xfrmi_update(xi, &p);
 }
 
 static size_t xfrmi_get_size(const struct net_device *dev)
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH ipsec v2 2/4] xfrm interface: ifname may be wrong in logs
  2019-07-15 10:00   ` [PATCH ipsec v2 0/4] xfrm interface: bugs fixes Nicolas Dichtel
  2019-07-15 10:00     ` [PATCH ipsec v2 1/4] xfrm interface: avoid corruption on changelink Nicolas Dichtel
@ 2019-07-15 10:00     ` Nicolas Dichtel
  2019-07-15 10:00     ` [PATCH ipsec v2 3/4] xfrm interface: fix list corruption for x-netns Nicolas Dichtel
                       ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Nicolas Dichtel @ 2019-07-15 10:00 UTC (permalink / raw)
  To: steffen.klassert, davem; +Cc: netdev, Nicolas Dichtel

The ifname is copied when the interface is created, but is never updated
later. In fact, this property is used only in one error message, where the
netdevice pointer is available, thus let's use it.

Fixes: f203b76d7809 ("xfrm: Add virtual xfrm interfaces")
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 include/net/xfrm.h        |  1 -
 net/xfrm/xfrm_interface.c | 10 +---------
 2 files changed, 1 insertion(+), 10 deletions(-)

diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index b22db30c3d88..ad761ef84797 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -983,7 +983,6 @@ static inline void xfrm_dst_destroy(struct xfrm_dst *xdst)
 void xfrm_dst_ifdown(struct dst_entry *dst, struct net_device *dev);
 
 struct xfrm_if_parms {
-	char name[IFNAMSIZ];	/* name of XFRM device */
 	int link;		/* ifindex of underlying L2 interface */
 	u32 if_id;		/* interface identifyer */
 };
diff --git a/net/xfrm/xfrm_interface.c b/net/xfrm/xfrm_interface.c
index 2310dc9e35c2..68336ee00d72 100644
--- a/net/xfrm/xfrm_interface.c
+++ b/net/xfrm/xfrm_interface.c
@@ -145,8 +145,6 @@ static int xfrmi_create(struct net_device *dev)
 	if (err < 0)
 		goto out;
 
-	strcpy(xi->p.name, dev->name);
-
 	dev_hold(dev);
 	xfrmi_link(xfrmn, xi);
 
@@ -294,7 +292,7 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
 	if (tdev == dev) {
 		stats->collisions++;
 		net_warn_ratelimited("%s: Local routing loop detected!\n",
-				     xi->p.name);
+				     dev->name);
 		goto tx_err_dst_release;
 	}
 
@@ -638,12 +636,6 @@ static int xfrmi_newlink(struct net *src_net, struct net_device *dev,
 	int err;
 
 	xfrmi_netlink_parms(data, &p);
-
-	if (!tb[IFLA_IFNAME])
-		return -EINVAL;
-
-	nla_strlcpy(p.name, tb[IFLA_IFNAME], IFNAMSIZ);
-
 	xi = xfrmi_locate(net, &p);
 	if (xi)
 		return -EEXIST;
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH ipsec v2 3/4] xfrm interface: fix list corruption for x-netns
  2019-07-15 10:00   ` [PATCH ipsec v2 0/4] xfrm interface: bugs fixes Nicolas Dichtel
  2019-07-15 10:00     ` [PATCH ipsec v2 1/4] xfrm interface: avoid corruption on changelink Nicolas Dichtel
  2019-07-15 10:00     ` [PATCH ipsec v2 2/4] xfrm interface: ifname may be wrong in logs Nicolas Dichtel
@ 2019-07-15 10:00     ` Nicolas Dichtel
  2019-07-15 10:00     ` [PATCH ipsec v2 4/4] xfrm interface: fix management of phydev Nicolas Dichtel
  2019-07-18  7:37     ` [PATCH ipsec v2 0/4] xfrm interface: bugs fixes Steffen Klassert
  4 siblings, 0 replies; 10+ messages in thread
From: Nicolas Dichtel @ 2019-07-15 10:00 UTC (permalink / raw)
  To: steffen.klassert, davem; +Cc: netdev, Nicolas Dichtel, Julien Floret

dev_net(dev) is the netns of the device and xi->net is the link netns,
where the device has been linked.
changelink() must operate in the link netns to avoid a corruption of
the xfrm lists.

Note that xi->net and dev_net(xi->physdev) are always the same.

Before the patch, the xfrmi lists may be corrupted and can later trigger a
kernel panic.

Fixes: f203b76d7809 ("xfrm: Add virtual xfrm interfaces")
Reported-by: Julien Floret <julien.floret@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Tested-by: Julien Floret <julien.floret@6wind.com>
---
 net/xfrm/xfrm_interface.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/xfrm/xfrm_interface.c b/net/xfrm/xfrm_interface.c
index 68336ee00d72..53e5e47b2c55 100644
--- a/net/xfrm/xfrm_interface.c
+++ b/net/xfrm/xfrm_interface.c
@@ -503,7 +503,7 @@ static int xfrmi_change(struct xfrm_if *xi, const struct xfrm_if_parms *p)
 
 static int xfrmi_update(struct xfrm_if *xi, struct xfrm_if_parms *p)
 {
-	struct net *net = dev_net(xi->dev);
+	struct net *net = xi->net;
 	struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id);
 	int err;
 
@@ -663,9 +663,9 @@ static int xfrmi_changelink(struct net_device *dev, struct nlattr *tb[],
 			   struct nlattr *data[],
 			   struct netlink_ext_ack *extack)
 {
-	struct net *net = dev_net(dev);
+	struct xfrm_if *xi = netdev_priv(dev);
+	struct net *net = xi->net;
 	struct xfrm_if_parms p;
-	struct xfrm_if *xi;
 
 	xfrmi_netlink_parms(data, &p);
 	xi = xfrmi_locate(net, &p);
@@ -707,7 +707,7 @@ static struct net *xfrmi_get_link_net(const struct net_device *dev)
 {
 	struct xfrm_if *xi = netdev_priv(dev);
 
-	return dev_net(xi->phydev);
+	return xi->net;
 }
 
 static const struct nla_policy xfrmi_policy[IFLA_XFRM_MAX + 1] = {
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH ipsec v2 4/4] xfrm interface: fix management of phydev
  2019-07-15 10:00   ` [PATCH ipsec v2 0/4] xfrm interface: bugs fixes Nicolas Dichtel
                       ` (2 preceding siblings ...)
  2019-07-15 10:00     ` [PATCH ipsec v2 3/4] xfrm interface: fix list corruption for x-netns Nicolas Dichtel
@ 2019-07-15 10:00     ` Nicolas Dichtel
  2019-07-18  7:37     ` [PATCH ipsec v2 0/4] xfrm interface: bugs fixes Steffen Klassert
  4 siblings, 0 replies; 10+ messages in thread
From: Nicolas Dichtel @ 2019-07-15 10:00 UTC (permalink / raw)
  To: steffen.klassert, davem; +Cc: netdev, Nicolas Dichtel, Julien Floret

With the current implementation, phydev cannot be removed:

$ ip link add dummy type dummy
$ ip link add xfrm1 type xfrm dev dummy if_id 1
$ ip l d dummy
 kernel:[77938.465445] unregister_netdevice: waiting for dummy to become free. Usage count = 1

Manage it like in ip tunnels, ie just keep the ifindex. Not that the side
effect, is that the phydev is now optional.

Fixes: f203b76d7809 ("xfrm: Add virtual xfrm interfaces")
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Tested-by: Julien Floret <julien.floret@6wind.com>
---
 include/net/xfrm.h        |  1 -
 net/xfrm/xfrm_interface.c | 32 +++++++++++++++++---------------
 2 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index ad761ef84797..aa08a7a5f6ac 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -990,7 +990,6 @@ struct xfrm_if_parms {
 struct xfrm_if {
 	struct xfrm_if __rcu *next;	/* next interface in list */
 	struct net_device *dev;		/* virtual device associated with interface */
-	struct net_device *phydev;	/* physical device */
 	struct net *net;		/* netns for packet i/o */
 	struct xfrm_if_parms p;		/* interface parms */
 
diff --git a/net/xfrm/xfrm_interface.c b/net/xfrm/xfrm_interface.c
index 53e5e47b2c55..2ab4859df55a 100644
--- a/net/xfrm/xfrm_interface.c
+++ b/net/xfrm/xfrm_interface.c
@@ -175,7 +175,6 @@ static void xfrmi_dev_uninit(struct net_device *dev)
 	struct xfrmi_net *xfrmn = net_generic(xi->net, xfrmi_net_id);
 
 	xfrmi_unlink(xfrmn, xi);
-	dev_put(xi->phydev);
 	dev_put(dev);
 }
 
@@ -362,7 +361,7 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)
 		goto tx_err;
 	}
 
-	fl.flowi_oif = xi->phydev->ifindex;
+	fl.flowi_oif = xi->p.link;
 
 	ret = xfrmi_xmit2(skb, dev, &fl);
 	if (ret < 0)
@@ -548,7 +547,7 @@ static int xfrmi_get_iflink(const struct net_device *dev)
 {
 	struct xfrm_if *xi = netdev_priv(dev);
 
-	return xi->phydev->ifindex;
+	return xi->p.link;
 }
 
 
@@ -574,12 +573,14 @@ static void xfrmi_dev_setup(struct net_device *dev)
 	dev->needs_free_netdev	= true;
 	dev->priv_destructor	= xfrmi_dev_free;
 	netif_keep_dst(dev);
+
+	eth_broadcast_addr(dev->broadcast);
 }
 
 static int xfrmi_dev_init(struct net_device *dev)
 {
 	struct xfrm_if *xi = netdev_priv(dev);
-	struct net_device *phydev = xi->phydev;
+	struct net_device *phydev = __dev_get_by_index(xi->net, xi->p.link);
 	int err;
 
 	dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
@@ -594,13 +595,19 @@ static int xfrmi_dev_init(struct net_device *dev)
 
 	dev->features |= NETIF_F_LLTX;
 
-	dev->needed_headroom = phydev->needed_headroom;
-	dev->needed_tailroom = phydev->needed_tailroom;
+	if (phydev) {
+		dev->needed_headroom = phydev->needed_headroom;
+		dev->needed_tailroom = phydev->needed_tailroom;
 
-	if (is_zero_ether_addr(dev->dev_addr))
-		eth_hw_addr_inherit(dev, phydev);
-	if (is_zero_ether_addr(dev->broadcast))
-		memcpy(dev->broadcast, phydev->broadcast, dev->addr_len);
+		if (is_zero_ether_addr(dev->dev_addr))
+			eth_hw_addr_inherit(dev, phydev);
+		if (is_zero_ether_addr(dev->broadcast))
+			memcpy(dev->broadcast, phydev->broadcast,
+			       dev->addr_len);
+	} else {
+		eth_hw_addr_random(dev);
+		eth_broadcast_addr(dev->broadcast);
+	}
 
 	return 0;
 }
@@ -644,13 +651,8 @@ static int xfrmi_newlink(struct net *src_net, struct net_device *dev,
 	xi->p = p;
 	xi->net = net;
 	xi->dev = dev;
-	xi->phydev = dev_get_by_index(net, p.link);
-	if (!xi->phydev)
-		return -ENODEV;
 
 	err = xfrmi_create(dev);
-	if (err < 0)
-		dev_put(xi->phydev);
 	return err;
 }
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH ipsec v2 0/4] xfrm interface: bugs fixes
  2019-07-15 10:00   ` [PATCH ipsec v2 0/4] xfrm interface: bugs fixes Nicolas Dichtel
                       ` (3 preceding siblings ...)
  2019-07-15 10:00     ` [PATCH ipsec v2 4/4] xfrm interface: fix management of phydev Nicolas Dichtel
@ 2019-07-18  7:37     ` Steffen Klassert
  4 siblings, 0 replies; 10+ messages in thread
From: Steffen Klassert @ 2019-07-18  7:37 UTC (permalink / raw)
  To: Nicolas Dichtel; +Cc: davem, netdev

On Mon, Jul 15, 2019 at 12:00:19PM +0200, Nicolas Dichtel wrote:
> 
> Here is a bunch of bugs fixes. Some have been seen by code review and some when
> playing with x-netns.
> The details are in each patch.
> 
> v1 -> v2:
>  - add patch #3 and #4

Series applied, thanks Nicolas!


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-07-18  7:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-10  7:45 [PATCH ipsec 0/2] xfrm interface: bug fix on changelink Nicolas Dichtel
2019-07-10  7:45 ` [PATCH ipsec 1/2] xfrm interface: avoid corruption " Nicolas Dichtel
2019-07-10  7:45 ` [PATCH ipsec 2/2] xfrm interface: ifname may be wrong in logs Nicolas Dichtel
2019-07-15  9:52 ` [PATCH ipsec 0/2] xfrm interface: bug fix on changelink Nicolas Dichtel
2019-07-15 10:00   ` [PATCH ipsec v2 0/4] xfrm interface: bugs fixes Nicolas Dichtel
2019-07-15 10:00     ` [PATCH ipsec v2 1/4] xfrm interface: avoid corruption on changelink Nicolas Dichtel
2019-07-15 10:00     ` [PATCH ipsec v2 2/4] xfrm interface: ifname may be wrong in logs Nicolas Dichtel
2019-07-15 10:00     ` [PATCH ipsec v2 3/4] xfrm interface: fix list corruption for x-netns Nicolas Dichtel
2019-07-15 10:00     ` [PATCH ipsec v2 4/4] xfrm interface: fix management of phydev Nicolas Dichtel
2019-07-18  7:37     ` [PATCH ipsec v2 0/4] xfrm interface: bugs fixes Steffen Klassert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).