Skip to contentSkip to conversation

tipc: fixes in duplicate address discovery function

PATCH In review Jon Maloy 2 participants 6 messages Jul 6, 2018 – Jul 7, 2018

Subsystems (3)
lore
Share & tools
lore
author
#4 lore raw

PATCH 4/4 tipc: make function tipc_net_finalize() thread safe

In reply to Jon Maloy

The setting of the node address is not thread safe, meaning that two discoverers may decide to set it simultanously, with a duplicate entry in the name table as result. We fix that with this commit.

Fixes 25b0b9c4e835 ("tipc: handle collisions of 32-bit node address hash values")
---
 net/tipc/net.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
net/tipc/net.c +11 -6
index 4fbaa04..a7f6964 100644
@@ -121,12 +121,17 @@ int tipc_net_init(struct net *net, u8 *node_id, u32 addr)
 
 void tipc_net_finalize(struct net *net, u32 addr)
 {
-	tipc_set_node_addr(net, addr);
-	smp_mb();
-	tipc_named_reinit(net);
-	tipc_sk_reinit(net);
-	tipc_nametbl_publish(net, TIPC_CFG_SRV, addr, addr,
-			     TIPC_CLUSTER_SCOPE, 0, addr);
+	struct tipc_net *tn = tipc_net(net);
+
+	spin_lock_bh(&tn->node_list_lock);
+	if (!tipc_own_addr(net)) {
+		tipc_set_node_addr(net, addr);
+		tipc_named_reinit(net);
+		tipc_sk_reinit(net);
+		tipc_nametbl_publish(net, TIPC_CFG_SRV, addr, addr,
+				     TIPC_CLUSTER_SCOPE, 0, addr);
+	}
+	spin_unlock_bh(&tn->node_list_lock);
 }
 
 void tipc_net_stop(struct net *net)
Signature · 6 lines
2.1.4


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

Jon Maloy

author
#0 lore raw

cover tipc: fixes in duplicate address discovery function

commit 25b0b9c4e835 ("tipc: handle collisions of 32-bit node address hash values") introduced new functionality that has turned out to contain several bugs and weaknesses.

We address those in this series.

Jon Maloy (4):
tipc: fix wrong return value from function tipc_node_try_addr()
tipc: correct discovery message handling during address trial period
tipc: fix correct setting of message type in second discoverer
tipc: make function tipc_net_finalize() thread safe

 net/tipc/discover.c | 18 +++++++++++-------
 net/tipc/net.c      | 17 +++++++++++------
 net/tipc/node.c     |  7 +++++--
 3 files changed, 27 insertions(+), 15 deletions(-)
Signature · 1 line
2.1.4
author
#2 lore raw

PATCH 2/4 tipc: correct discovery message handling during address trial period

With the duplicate address discovery protocol for tipc nodes addresses we introduced a one second trial period before a node is allocated a hash number to use as address.

Unfortunately, we miss to handle the case when a regular LINK REQUEST/ RESPONSE arrives from a cluster node during the trial period. Such messages are not ignored as they should be, leading to links setup attempts while the node still has no address.

Fixes 25b0b9c4e835 ("tipc: handle collisions of 32-bit node address hash values")
---
 net/tipc/discover.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/tipc/discover.c +4 -1
index 9f666e0..dcadc10 100644
@@ -133,6 +133,8 @@ static void disc_dupl_alert(struct tipc_bearer *b, u32 node_addr,
 }
 
 /* tipc_disc_addr_trial(): - handle an address uniqueness trial from peer
+ * Returns true if message should be dropped by caller, i.e., if it is a
+ * trial message or we are inside trial period. Otherwise false.
  */
 static bool tipc_disc_addr_trial_msg(struct tipc_discoverer *d,
 				     struct tipc_media_addr *maddr,
@@ -168,8 +170,9 @@ static bool tipc_disc_addr_trial_msg(struct tipc_discoverer *d,
 		msg_set_type(buf_msg(d->skb), DSC_REQ_MSG);
 	}
 
+	/* Accept regular link requests/responses only after trial period */
 	if (mtyp != DSC_TRIAL_MSG)
-		return false;
+		return trial;
 
 	sugg_addr = tipc_node_try_addr(net, peer_id, src);
 	if (sugg_addr)
Signature · 1 line
2.1.4
author
#1 lore raw

PATCH 1/4 tipc: fix wrong return value from function tipc_node_try_addr()

In reply to Jon Maloy

The function for checking if there is an node address conflict is supposed to return a suggestion for a new address if it finds a conflict, and zero otherwise. But in case the peer being checked is previously unknown it does instead return a "suggestion" for the checked address itself. This results in a DSC_TRIAL_FAIL_MSG being sent unecessarily to the peer, and sometimes makes the trial period starting over again.

Fixes 25b0b9c4e835 ("tipc: handle collisions of 32-bit node address hash values")
---
 net/tipc/node.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/tipc/node.c +5 -2
index 6a44eb8..0453bd4 100644
@@ -797,6 +797,7 @@ static u32 tipc_node_suggest_addr(struct net *net, u32 addr)
 }
 
 /* tipc_node_try_addr(): Check if addr can be used by peer, suggest other if not
+ * Returns suggested address if any, otherwise 0
  */
 u32 tipc_node_try_addr(struct net *net, u8 *id, u32 addr)
 {
@@ -819,12 +820,14 @@ u32 tipc_node_try_addr(struct net *net, u8 *id, u32 addr)
 	if (n) {
 		addr = n->addr;
 		tipc_node_put(n);
+		return addr;
 	}
-	/* Even this node may be in trial phase */
+
+	/* Even this node may be in conflict */
 	if (tn->trial_addr == addr)
 		return tipc_node_suggest_addr(net, addr);
 
-	return addr;
+	return 0;
 }
 
 void tipc_node_check_dest(struct net *net, u32 addr,
Signature · 1 line
2.1.4
author
#3 lore raw

PATCH 3/4 tipc: fix correct setting of message type in second discoverer

In reply to Jon Maloy

The duplicate address discovery protocol is not safe against two discoverers running in parallel. The one executing first after the trial period is over will set the node address and change its own message type to DSC_REQ_MSG. The one executing last may find that the node address is already set, and never change message type, with the result that its links may never be established.

In this commmit we ensure that the message type always is set correctly after the trial period is over.

Fixes 25b0b9c4e835 ("tipc: handle collisions of 32-bit node address hash values")
---
 net/tipc/discover.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
net/tipc/discover.c +7 -6
index dcadc10..2830709 100644
@@ -287,7 +287,6 @@ static void tipc_disc_timeout(struct timer_list *t)
 {
 	struct tipc_discoverer *d = from_timer(d, t, timer);
 	struct tipc_net *tn = tipc_net(d->net);
-	u32 self = tipc_own_addr(d->net);
 	struct tipc_media_addr maddr;
 	struct sk_buff *skb = NULL;
 	struct net *net = d->net;
@@ -301,12 +300,14 @@ static void tipc_disc_timeout(struct timer_list *t)
 		goto exit;
 	}
 
-	/* Did we just leave the address trial period ? */
-	if (!self && !time_before(jiffies, tn->addr_trial_end)) {
-		self = tn->trial_addr;
-		tipc_net_finalize(net, self);
-		msg_set_prevnode(buf_msg(d->skb), self);
+	/* Trial period over ? */
+	if (!time_before(jiffies, tn->addr_trial_end)) {
+		/* Did we just leave it ? */
+		if (!tipc_own_addr(net))
+			tipc_net_finalize(net, tn->trial_addr);
+
 		msg_set_type(buf_msg(d->skb), DSC_REQ_MSG);
+		msg_set_prevnode(buf_msg(d->skb), tipc_own_addr(net));
 	}
 
 	/* Adjust timeout interval according to discovery phase */
Signature · 1 line
2.1.4
maintainer
#5 lore raw
In reply to Jon Maloy

From: Jon Maloy <[email protected]>
Date: Fri, 6 Jul 2018 20:10:02 +0200

Quoted 5 lines

commit 25b0b9c4e835 ("tipc: handle collisions of 32-bit node address hash values") introduced new functionality that has turned out to contain several bugs and weaknesses.

We address those in this series.

Series applied and queued up for -stable, thanks!