From patchwork Thu Sep 29 11:03:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isak Westin X-Patchwork-Id: 610669 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CC02C4332F for ; Thu, 29 Sep 2022 11:04:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235218AbiI2LEO (ORCPT ); Thu, 29 Sep 2022 07:04:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235197AbiI2LEM (ORCPT ); Thu, 29 Sep 2022 07:04:12 -0400 Received: from voyager.loytec.com (voyager.loytec.com [88.198.4.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECE198E0FE for ; Thu, 29 Sep 2022 04:04:10 -0700 (PDT) Received: from 212-17-98-152.static.upcbusiness.at ([212.17.98.152] helo=lexx.office.loytec.com) by voyager.loytec.com with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1odrKq-0007JU-0k for linux-bluetooth@vger.kernel.org; Thu, 29 Sep 2022 13:04:08 +0200 Received: from loytec-dev-vm.delta.corp ([10.101.25.21]) by lexx.office.loytec.com (8.15.2/8.15.2/Some OS 1.2.3-4.5) with ESMTP id 28TB45CF3109252; Thu, 29 Sep 2022 13:04:06 +0200 From: Isak Westin To: linux-bluetooth@vger.kernel.org Cc: Isak Westin Subject: [PATCH BlueZ 1/4] mesh: Ignore Secure Network Beacon from subnet Date: Thu, 29 Sep 2022 13:03:41 +0200 Message-Id: <20220929110344.26130-2-isak.westin@loytec.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220929110344.26130-1-isak.westin@loytec.com> References: <20220929110344.26130-1-isak.westin@loytec.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 212.17.98.152 X-SA-Exim-Mail-From: isak.westin@loytec.com X-SA-Exim-Scanned: No (on voyager.loytec.com); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org If this node is a member of a primary subnet and receives a Secure Network beacon on a secondary subnet with an IV Index greater than the last known IV Index of the primary subnet, the Secure Network beacon shall be ignored. See MshPRFv1.0.1 section 3.10.5. --- mesh/net.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mesh/net.c b/mesh/net.c index 7fec98531..dc3d1fd80 100644 --- a/mesh/net.c +++ b/mesh/net.c @@ -2708,7 +2708,7 @@ static void process_beacon(void *net_ptr, void *user_data) struct net_beacon_data *beacon_data = user_data; uint32_t ivi; bool ivu, kr, local_kr; - struct mesh_subnet *subnet; + struct mesh_subnet *subnet, *primary_subnet; ivi = beacon_data->ivi; @@ -2723,6 +2723,17 @@ static void process_beacon(void *net_ptr, void *user_data) if (!subnet) return; + /* + * @MshPRFv1.0.1 section 3.10.5: IV Update procedure + * If this node is a member of a primary subnet and receives a Secure + * Network beacon on a secondary subnet with an IV Index greater than + * the last known IV Index of the primary subnet, the Secure Network + * beacon shall be ignored. + */ + primary_subnet = get_primary_subnet(net); + if (primary_subnet && subnet != primary_subnet && ivi > net->iv_index) + return; + /* Get IVU and KR boolean bits from beacon */ ivu = beacon_data->ivu; kr = beacon_data->kr; From patchwork Thu Sep 29 11:03:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isak Westin X-Patchwork-Id: 610668 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2CF7C433FE for ; Thu, 29 Sep 2022 11:04:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235234AbiI2LEQ (ORCPT ); Thu, 29 Sep 2022 07:04:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235198AbiI2LEM (ORCPT ); Thu, 29 Sep 2022 07:04:12 -0400 Received: from voyager.loytec.com (voyager.loytec.com [88.198.4.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13DF012BD8F for ; Thu, 29 Sep 2022 04:04:10 -0700 (PDT) Received: from 212-17-98-152.static.upcbusiness.at ([212.17.98.152] helo=lexx.office.loytec.com) by voyager.loytec.com with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1odrKr-0007Jb-E8 for linux-bluetooth@vger.kernel.org; Thu, 29 Sep 2022 13:04:09 +0200 Received: from loytec-dev-vm.delta.corp ([10.101.25.21]) by lexx.office.loytec.com (8.15.2/8.15.2/Some OS 1.2.3-4.5) with ESMTP id 28TB45CG3109252; Thu, 29 Sep 2022 13:04:07 +0200 From: Isak Westin To: linux-bluetooth@vger.kernel.org Cc: Isak Westin Subject: [PATCH BlueZ 2/4] mesh: Ignore SNB with invalid IV Index values Date: Thu, 29 Sep 2022 13:03:42 +0200 Message-Id: <20220929110344.26130-3-isak.westin@loytec.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220929110344.26130-1-isak.westin@loytec.com> References: <20220929110344.26130-1-isak.westin@loytec.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 212.17.98.152 X-SA-Exim-Mail-From: isak.westin@loytec.com X-SA-Exim-Scanned: No (on voyager.loytec.com); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org If we are in IV update in progress state, and receive a Secure Network beacon with an IV index equal to last known IV index + 1, and IV update flag set to 1, it should be ignored. See MshPRFv1.0.1 section 3.10.5. --- mesh/net.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mesh/net.c b/mesh/net.c index dc3d1fd80..c225fdb9a 100644 --- a/mesh/net.c +++ b/mesh/net.c @@ -2671,6 +2671,10 @@ static bool update_iv_ivu_state(struct mesh_net *net, uint32_t iv_index, if (iv_index == net->iv_index) return false; + /* Ignore beacon with invalid IV index value */ + if (net->iv_update && iv_index == net->iv_index + 1) + return false; + if (!net->iv_update) { l_debug("iv_upd_state = IV_UPD_UPDATING"); net->iv_upd_state = IV_UPD_UPDATING; From patchwork Thu Sep 29 11:03:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isak Westin X-Patchwork-Id: 611909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D680C433F5 for ; Thu, 29 Sep 2022 11:04:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235224AbiI2LEP (ORCPT ); Thu, 29 Sep 2022 07:04:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234687AbiI2LEM (ORCPT ); Thu, 29 Sep 2022 07:04:12 -0400 Received: from voyager.loytec.com (voyager.loytec.com [88.198.4.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF6AD12BDA8 for ; Thu, 29 Sep 2022 04:04:11 -0700 (PDT) Received: from 212-17-98-152.static.upcbusiness.at ([212.17.98.152] helo=lexx.office.loytec.com) by voyager.loytec.com with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1odrKs-0007Jf-8W for linux-bluetooth@vger.kernel.org; Thu, 29 Sep 2022 13:04:10 +0200 Received: from loytec-dev-vm.delta.corp ([10.101.25.21]) by lexx.office.loytec.com (8.15.2/8.15.2/Some OS 1.2.3-4.5) with ESMTP id 28TB45CH3109252; Thu, 29 Sep 2022 13:04:08 +0200 From: Isak Westin To: linux-bluetooth@vger.kernel.org Cc: Isak Westin Subject: [PATCH BlueZ 3/4] mesh: Allow Key refresh to skip Phase 2 Date: Thu, 29 Sep 2022 13:03:43 +0200 Message-Id: <20220929110344.26130-4-isak.westin@loytec.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220929110344.26130-1-isak.westin@loytec.com> References: <20220929110344.26130-1-isak.westin@loytec.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 212.17.98.152 X-SA-Exim-Mail-From: isak.westin@loytec.com X-SA-Exim-Scanned: No (on voyager.loytec.com); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org If we are in Key Refresh Phase 1, and receive a Secure Network beacon using the new NetKey and with KR flag set to 0, Phase 2 should be skipped. See MshPRFv1.0.1 section 3.10.4.1. --- mesh/net.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mesh/net.c b/mesh/net.c index c225fdb9a..379a6e250 100644 --- a/mesh/net.c +++ b/mesh/net.c @@ -2613,7 +2613,8 @@ static bool update_kr_state(struct mesh_subnet *subnet, bool kr, uint32_t id) { /* Figure out the key refresh phase */ if (kr) { - if (id == subnet->net_key_upd) { + if (subnet->kr_phase == KEY_REFRESH_PHASE_ONE && + id == subnet->net_key_upd) { l_debug("Beacon based KR phase 2 change"); return (key_refresh_phase_two(subnet->net, subnet->idx) == MESH_STATUS_SUCCESS); @@ -2754,7 +2755,7 @@ static void process_beacon(void *net_ptr, void *user_data) ivu != net->iv_update) updated |= update_iv_ivu_state(net, ivi, ivu); - if (kr != local_kr) + if (kr != local_kr || beacon_data->net_key_id != subnet->net_key_cur) updated |= update_kr_state(subnet, kr, beacon_data->net_key_id); if (updated) From patchwork Thu Sep 29 11:03:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isak Westin X-Patchwork-Id: 611908 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34CB4C433F5 for ; Thu, 29 Sep 2022 11:04:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235126AbiI2LES (ORCPT ); Thu, 29 Sep 2022 07:04:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234729AbiI2LEP (ORCPT ); Thu, 29 Sep 2022 07:04:15 -0400 Received: from voyager.loytec.com (voyager.loytec.com [88.198.4.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37F2C1EC58 for ; Thu, 29 Sep 2022 04:04:13 -0700 (PDT) Received: from 212-17-98-152.static.upcbusiness.at ([212.17.98.152] helo=lexx.office.loytec.com) by voyager.loytec.com with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1odrKu-0007Jp-9Q for linux-bluetooth@vger.kernel.org; Thu, 29 Sep 2022 13:04:12 +0200 Received: from loytec-dev-vm.delta.corp ([10.101.25.21]) by lexx.office.loytec.com (8.15.2/8.15.2/Some OS 1.2.3-4.5) with ESMTP id 28TB45CI3109252; Thu, 29 Sep 2022 13:04:10 +0200 From: Isak Westin To: linux-bluetooth@vger.kernel.org Cc: Isak Westin Subject: [PATCH BlueZ 4/4] mesh: Allow Key Refresh Phase 0 to 3 transition Date: Thu, 29 Sep 2022 13:03:44 +0200 Message-Id: <20220929110344.26130-5-isak.westin@loytec.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220929110344.26130-1-isak.westin@loytec.com> References: <20220929110344.26130-1-isak.westin@loytec.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 212.17.98.152 X-SA-Exim-Mail-From: isak.westin@loytec.com X-SA-Exim-Scanned: No (on voyager.loytec.com); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Transition to Phase 3 from Phase 0 does not cause any state change, but is a valid transition. See MshPRFv1.0.1 section 4.2.14. --- mesh/cfgmod-server.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c index 7044b670d..be90ef8c5 100644 --- a/mesh/cfgmod-server.c +++ b/mesh/cfgmod-server.c @@ -436,6 +436,10 @@ static uint16_t cfg_key_refresh_phase(struct mesh_node *node, return 0; } + if (pkt[2] == KEY_REFRESH_TRANS_THREE && + phase == KEY_REFRESH_PHASE_NONE) + goto done; + status = mesh_net_key_refresh_phase_set(net, idx, pkt[2]); l_debug("Set KR Phase: net=%3.3x transition=%d", idx, pkt[2]);