Linux-Bluetooth Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH BlueZ v2] mesh: Fix IV Recovery procedure when IV Update is in progress
@ 2019-09-09 19:25 Michał Lowas-Rzechonek
  2019-09-17  6:53 ` Michał Lowas-Rzechonek
  0 siblings, 1 reply; 2+ messages in thread
From: Michał Lowas-Rzechonek @ 2019-09-09 19:25 UTC (permalink / raw)
  To: linux-bluetooth

This patch ensures that Sequence Number is reset only when IV Index used
for outgoing messages increases.

This fixes erroneously cleared sequence number when node performs IV
Recovery procedure on startup in a following scenario:
 - node has IV Index set to <N>
 - node starts in IV_UPD_INIT state
 - node receives a Secure Network Beacon with IV Index <N>+1 and IV
   Update flag set

Upon reception, the node shall:
 - increase its IV Index to <N>+1
 - enter IV_UPD_UPDATING state

This means that the node keeps transmitting messages using IV Index
equal to <N>, therefore it shall *not* reset its Sequence Number before IV
Update procedure completes.

If, on the other hand, SNB contains either:
 - IV Index <N>+2 (regardless of IV Update flag)
 - IV Index <N>+1 and IV Update flag *not* set
the node shall reset the Sequence Number right away.
---
 mesh/net.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/mesh/net.c b/mesh/net.c
index 7c4049e0e..ba7bb32fd 100644
--- a/mesh/net.c
+++ b/mesh/net.c
@@ -2735,8 +2735,6 @@ static void update_iv_kr_state(struct mesh_subnet *subnet, uint32_t iv_index,
 	}
 
 	if (net->iv_upd_state == IV_UPD_INIT) {
-		if (iv_index > net->iv_index)
-			mesh_net_set_seq_num(net, 0);
 		net->iv_index = iv_index;
 
 		if (iv_update) {
@@ -2757,6 +2755,12 @@ static void update_iv_kr_state(struct mesh_subnet *subnet, uint32_t iv_index,
 		mesh_config_write_iv_index(node_config_get(net->node), iv_index,
 							net->iv_upd_state);
 
+		/* Reset seq num if iv index used for *outgoing* messages has
+		 * just been increased
+		 */
+		if (mesh_net_get_iv_index(net) > local_iv_index)
+			mesh_net_set_seq_num(net, 0);
+
 		/* Figure out the key refresh phase */
 		if (kr_transition) {
 			l_debug("Beacon based KR phase change");
-- 
2.22.0


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

* Re: [PATCH BlueZ v2] mesh: Fix IV Recovery procedure when IV Update is in progress
  2019-09-09 19:25 [PATCH BlueZ v2] mesh: Fix IV Recovery procedure when IV Update is in progress Michał Lowas-Rzechonek
@ 2019-09-17  6:53 ` Michał Lowas-Rzechonek
  0 siblings, 0 replies; 2+ messages in thread
From: Michał Lowas-Rzechonek @ 2019-09-17  6:53 UTC (permalink / raw)
  To: linux-bluetooth, Brian Gix

Hi Brian,

On 09/09, Michał Lowas-Rzechonek wrote:
> This patch ensures that Sequence Number is reset only when IV Index used
> for outgoing messages increases.

Did you have a chance to take a look at this?

regards
-- 
Michał Lowas-Rzechonek <michal.lowas-rzechonek@silvair.com>
Silvair http://silvair.com
Jasnogórska 44, 31-358 Krakow, POLAND

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-09 19:25 [PATCH BlueZ v2] mesh: Fix IV Recovery procedure when IV Update is in progress Michał Lowas-Rzechonek
2019-09-17  6:53 ` Michał Lowas-Rzechonek

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org linux-bluetooth@archiver.kernel.org
	public-inbox-index linux-bluetooth


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/ public-inbox