From patchwork Tue Jan 28 21:53:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Gix X-Patchwork-Id: 197400 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A535C2D0DB for ; Tue, 28 Jan 2020 21:53:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5DF86207FD for ; Tue, 28 Jan 2020 21:53:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726292AbgA1Vx2 (ORCPT ); Tue, 28 Jan 2020 16:53:28 -0500 Received: from mga02.intel.com ([134.134.136.20]:27638 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726211AbgA1Vx1 (ORCPT ); Tue, 28 Jan 2020 16:53:27 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jan 2020 13:53:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,375,1574150400"; d="scan'208";a="246856245" Received: from bgi1-mobl2.amr.corp.intel.com ([10.255.84.27]) by orsmga002.jf.intel.com with ESMTP; 28 Jan 2020 13:53:27 -0800 From: Brian Gix To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, inga.stotland@intel.com, rafal.gajda@silvair.com Subject: [PATCH BlueZ v3 1/5] mesh: Relocate tree deletion to util.c/h Date: Tue, 28 Jan 2020 13:53:06 -0800 Message-Id: <20200128215310.8205-2-brian.gix@intel.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200128215310.8205-1-brian.gix@intel.com> References: <20200128215310.8205-1-brian.gix@intel.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org --- mesh/mesh-config-json.c | 20 +------------------- mesh/util.c | 25 +++++++++++++++++++++++++ mesh/util.h | 1 + 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c index 5855149e3..ad2d4d0f8 100644 --- a/mesh/mesh-config-json.c +++ b/mesh/mesh-config-json.c @@ -2253,24 +2253,6 @@ bool mesh_config_load_nodes(const char *cfgdir_name, mesh_config_node_func_t cb, return true; } -static int del_fobject(const char *fpath, const struct stat *sb, int typeflag, - struct FTW *ftwbuf) -{ - switch (typeflag) { - case FTW_DP: - rmdir(fpath); - l_debug("RMDIR %s", fpath); - break; - - case FTW_SL: - default: - remove(fpath); - l_debug("RM %s", fpath); - break; - } - return 0; -} - void mesh_config_destroy(struct mesh_config *cfg) { char *node_dir, *node_name; @@ -2291,7 +2273,7 @@ void mesh_config_destroy(struct mesh_config *cfg) if (strcmp(node_name, uuid)) return; - nftw(node_dir, del_fobject, 5, FTW_DEPTH | FTW_PHYS); + del_path(node_dir); /* Release node config object */ mesh_config_release(cfg); diff --git a/mesh/util.c b/mesh/util.c index 986ba4b28..43340f159 100644 --- a/mesh/util.c +++ b/mesh/util.c @@ -24,6 +24,7 @@ #define _GNU_SOURCE #include #include +#include #include #include #include @@ -129,3 +130,27 @@ int create_dir(const char *dir_name) return 0; } + +static int del_fobject(const char *fpath, const struct stat *sb, int typeflag, + struct FTW *ftwbuf) +{ + switch (typeflag) { + case FTW_DP: + rmdir(fpath); + l_debug("RMDIR %s", fpath); + break; + + case FTW_SL: + default: + remove(fpath); + l_debug("RM %s", fpath); + break; + } + return 0; +} + + +void del_path(const char *path) +{ + nftw(path, del_fobject, 5, FTW_DEPTH | FTW_PHYS); +} diff --git a/mesh/util.h b/mesh/util.h index d1e83b573..092d33041 100644 --- a/mesh/util.h +++ b/mesh/util.h @@ -23,3 +23,4 @@ bool str2hex(const char *str, uint16_t in_len, uint8_t *out, size_t hex2str(uint8_t *in, size_t in_len, char *out, size_t out_len); void print_packet(const char *label, const void *data, uint16_t size); int create_dir(const char *dir_name); +void del_path(const char *path); From patchwork Tue Jan 28 21:53:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Gix X-Patchwork-Id: 197399 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F026C2D0DB for ; Tue, 28 Jan 2020 21:53:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6DCAB207FD for ; Tue, 28 Jan 2020 21:53:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726320AbgA1Vxl (ORCPT ); Tue, 28 Jan 2020 16:53:41 -0500 Received: from mga12.intel.com ([192.55.52.136]:7924 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726211AbgA1Vxl (ORCPT ); Tue, 28 Jan 2020 16:53:41 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jan 2020 13:53:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,375,1574150400"; d="scan'208";a="246856286" Received: from bgi1-mobl2.amr.corp.intel.com ([10.255.84.27]) by orsmga002.jf.intel.com with ESMTP; 28 Jan 2020 13:53:40 -0800 From: Brian Gix To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, inga.stotland@intel.com, rafal.gajda@silvair.com Subject: [PATCH BlueZ v3 3/5] mesh: Clean-up unneeded Sequence Number increments Date: Tue, 28 Jan 2020 13:53:08 -0800 Message-Id: <20200128215310.8205-4-brian.gix@intel.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200128215310.8205-1-brian.gix@intel.com> References: <20200128215310.8205-1-brian.gix@intel.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Scrub of Sequence Number handling of OB messages to account for in-node delivery of segmented messages, so that each discrete message has a unique sequence number for the RPL. --- mesh/net.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mesh/net.c b/mesh/net.c index 71ff2cea0..9567d947e 100644 --- a/mesh/net.c +++ b/mesh/net.c @@ -3043,14 +3043,19 @@ static bool send_seg(struct mesh_net *net, struct mesh_sar *msg, uint8_t segO) uint8_t segN = SEG_MAX(msg->len); uint16_t seg_off = SEG_OFF(segO); uint32_t key_id = 0; - uint32_t seq_num = mesh_net_next_seq_num(net); + uint32_t seq_num; if (segN) { + /* Send each segment on unique seq_num */ + seq_num = mesh_net_next_seq_num(net); + if (msg->len - seg_off > SEG_OFF(1)) seg_len = SEG_OFF(1); else seg_len = msg->len - seg_off; } else { + /* Send on same seq_num used for Access Layer */ + seq_num = msg->seqAuth; seg_len = msg->len; } @@ -3185,7 +3190,7 @@ bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src, /* First enqueue to any Friends and internal models */ result = msg_rxed(net, false, iv_index, ttl, - seq + seg_max, + seq, net_idx, src, dst, key_aid, @@ -3196,12 +3201,8 @@ bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src, * or delivered to one of our Unicast addresses we are done */ if ((result && IS_UNICAST(dst)) || src == dst || - (dst >= net->src_addr && dst <= net->last_addr)) { - /* Adjust our seq_num for "virtual" delivery */ - net->seq_num += seg_max; - mesh_net_next_seq_num(net); + (dst >= net->src_addr && dst <= net->last_addr)) return true; - } /* If Segmented, Cancel any OB segmented message to same DST */ if (seg_max) { @@ -3226,7 +3227,7 @@ bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src, } payload->iv_index = mesh_net_get_iv_index(net); - payload->seqAuth = net->seq_num; + payload->seqAuth = seq; result = true; if (!IS_UNICAST(dst) && seg_max) { From patchwork Tue Jan 28 21:53:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Gix X-Patchwork-Id: 197398 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27313C33CB2 for ; Tue, 28 Jan 2020 21:53:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E7E50207FD for ; Tue, 28 Jan 2020 21:53:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726338AbgA1Vxz (ORCPT ); Tue, 28 Jan 2020 16:53:55 -0500 Received: from mga09.intel.com ([134.134.136.24]:27786 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726211AbgA1Vxz (ORCPT ); Tue, 28 Jan 2020 16:53:55 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jan 2020 13:53:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,375,1574150400"; d="scan'208";a="246856305" Received: from bgi1-mobl2.amr.corp.intel.com ([10.255.84.27]) by orsmga002.jf.intel.com with ESMTP; 28 Jan 2020 13:53:46 -0800 From: Brian Gix To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, inga.stotland@intel.com, rafal.gajda@silvair.com Subject: [PATCH BlueZ v3 4/5] mesh: Apply Replay Protection to all incoming packets Date: Tue, 28 Jan 2020 13:53:09 -0800 Message-Id: <20200128215310.8205-5-brian.gix@intel.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200128215310.8205-1-brian.gix@intel.com> References: <20200128215310.8205-1-brian.gix@intel.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Replay Protection was only being applied against Application Keys, but messages with Device Keys are just as vulnerable, and need to be checked as well. --- mesh/model.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/mesh/model.c b/mesh/model.c index 0018c7cff..92a00496c 100644 --- a/mesh/model.c +++ b/mesh/model.c @@ -608,7 +608,7 @@ static bool msg_send(struct mesh_node *node, bool credential, uint16_t src, iv_index = mesh_net_get_iv_index(net); - seq_num = mesh_net_get_seq_num(net); + seq_num = mesh_net_next_seq_num(net); if (!mesh_crypto_payload_encrypt(label, msg, out, msg_len, src, dst, key_aid, seq_num, iv_index, szmic, key)) { l_error("Failed to Encrypt Payload"); @@ -949,7 +949,7 @@ bool mesh_model_rx(struct mesh_node *node, bool szmict, uint32_t seq0, struct mesh_net *net = node_get_net(node); uint8_t num_ele; int decrypt_idx, i, ele_idx; - uint16_t addr; + uint16_t addr, crpl; struct mesh_virtual *decrypt_virt = NULL; bool result = false; bool is_subscription; @@ -997,14 +997,12 @@ bool mesh_model_rx(struct mesh_node *node, bool szmict, uint32_t seq0, /* print_packet("Clr Rx (pre-cache-check)", clear_text, size - 4); */ - if (key_aid != APP_AID_DEV) { - uint16_t crpl = node_get_crpl(node); + crpl = node_get_crpl(node); - if (net_msg_in_replay_cache(net, (uint16_t) decrypt_idx, src, - crpl, seq, iv_index)) { - result = true; - goto done; - } + if (net_msg_in_replay_cache(net, (uint16_t) decrypt_idx, src, + crpl, seq, iv_index)) { + result = true; + goto done; } print_packet("Clr Rx", clear_text, size - (szmict ? 8 : 4));