linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michał Lowas-Rzechonek" <michal.lowas-rzechonek@silvair.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2] mesh: Fix IV Recovery procedure when IV Update is in progress
Date: Mon,  9 Sep 2019 21:25:09 +0200	[thread overview]
Message-ID: <20190909192509.15007-1-michal.lowas-rzechonek@silvair.com> (raw)

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


             reply	other threads:[~2019-09-09 19:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-09 19:25 Michał Lowas-Rzechonek [this message]
2019-09-17  6:53 ` [PATCH BlueZ v2] mesh: Fix IV Recovery procedure when IV Update is in progress Michał Lowas-Rzechonek
2019-09-30  9:11   ` Michał Lowas-Rzechonek
2019-10-01 15:21 ` Gix, Brian
2019-10-02 13:31   ` michal.lowas-rzechonek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190909192509.15007-1-michal.lowas-rzechonek@silvair.com \
    --to=michal.lowas-rzechonek@silvair.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).