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
Cc: Brian Gix <brian.gix@intel.com>,
	Jakub Witowski <jakub.witowski@silvair.com>
Subject: [PATCH BlueZ] mesh: Honor IV Update flag in app layer crypto
Date: Tue, 25 Jun 2019 13:25:30 +0200	[thread overview]
Message-ID: <20190625112530.21870-1-michal.lowas-rzechonek@silvair.com> (raw)

Since IV Index is used in application nonces, we need to honor IV Update
flag not only in network layer crypto, but also in application layer.
Otherwise, we cannot decode application payloads from nodes that are in
IV Update state.
---
 mesh/net.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/mesh/net.c b/mesh/net.c
index a597b8794..1aa1c4cfa 100644
--- a/mesh/net.c
+++ b/mesh/net.c
@@ -2489,6 +2489,14 @@ static void net_rx(void *net_ptr, void *user_data)
 	size_t out_size;
 	uint32_t key_id;
 	int8_t rssi = 0;
+	uint32_t iv_index;
+	bool iv_flag = !!(net->iv_index & 1);
+	bool iv_pkt = !!(data->data[0] & 0x80);
+
+	if (iv_pkt == iv_flag)
+		iv_index = net->iv_index;
+	else
+		iv_index = net->iv_index - 1;
 
 	key_id = net_key_decrypt(net->iv_index, data->data, data->len,
 							&out, &out_size);
@@ -2504,16 +2512,10 @@ static void net_rx(void *net_ptr, void *user_data)
 		rssi = data->info->rssi;
 	}
 
-	relay_advice = packet_received(net, key_id, net->iv_index,
+	relay_advice = packet_received(net, key_id, iv_index,
 							out, out_size, rssi);
 	if (relay_advice > data->relay_advice) {
-		bool iv_flag = !!(net->iv_index & 1);
-		bool iv_pkt = !!(data->data[0] & 0x80);
-
-		data->iv_index = net->iv_index;
-		if (iv_pkt != iv_flag)
-			data->iv_index--;
-
+		data->iv_index = iv_index;
 		data->relay_advice = relay_advice;
 		data->key_id = key_id;
 		data->net = net;
-- 
2.19.1


                 reply	other threads:[~2019-06-25 11:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20190625112530.21870-1-michal.lowas-rzechonek@silvair.com \
    --to=michal.lowas-rzechonek@silvair.com \
    --cc=brian.gix@intel.com \
    --cc=jakub.witowski@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).