Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp144184ybl; Wed, 11 Dec 2019 15:29:41 -0800 (PST) X-Google-Smtp-Source: APXvYqyRw3cbZIuH4JDRofSSRXNn6tqVvyIzrOooQd+2bDQvMUWcNgU5vkaEAo4wQJzFjkPBuRXg X-Received: by 2002:a05:6830:14d3:: with SMTP id t19mr4810268otq.278.1576106981557; Wed, 11 Dec 2019 15:29:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576106981; cv=none; d=google.com; s=arc-20160816; b=vALLTjQIgmXR6LJfQCAGe0nEidxmERTVZAdPrlzHmjht3snQZ+5aF8hAiGHnACHxjD k5jZgBtIInkSeAx3wQbpibfqGkgKbP2f6gBKmqJj93NqmF9NzM+8D+aZiSyJYywICiiC Ow+CpJd+sfBujyrgpYjUVaI97BLHXwhmzbeVHGKuhRWqQNJdXObRVzZJhY4UBHGO3S/R nE9YFhq21IvzzuR2WZlxV+x2ok+Lpe32bSsNrOitMMG4v9W8uBsxz7foKa4jgzRC7VdR NJ+xcSWKVjLzOEmk7pkh81SmiL6caHEzgRJndlOqRXzP1ehfEpxWG856B/4rCzmT8lh9 ENOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=HokJgdh9/u93f4vw2HLgHs0fghGmzz1Azp02MC4Bb9Y=; b=JfSDF4TLlnc0vE7W3F1ijP884fW1flAtbu2H5tj+YaGC8VQn/j1KtFAEO/DmR3OwVf 20v2VpvNgpjG4aIEl0sOJko/1paJbBcIdblnNZzu2VBaGR0bjjesMm7hIqficBUF/w9z xKXYR/WXW5YR2EmnUNqCVpRQlyfLJ2nUWuhFteMajZEeeB2xeNK2kLpyDgjb8+mxUHOE ANRQ84WW7SCy8nFcXN1tY8vUY3HF+4wSaF4Yy5avhtbHhvx+fKvCdPjzSokD5mhyys+u zsnaVNwQ76estw9aN4Gznc3wruzx41fHm6m1kmtjPkgxBWtHnLfaMEIMkBBcTkpTOyRl 0YIQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w4si2118666otl.214.2019.12.11.15.29.16; Wed, 11 Dec 2019 15:29:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726971AbfLKX2u (ORCPT + 99 others); Wed, 11 Dec 2019 18:28:50 -0500 Received: from mga12.intel.com ([192.55.52.136]:52050 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726911AbfLKX2u (ORCPT ); Wed, 11 Dec 2019 18:28:50 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2019 15:28:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,303,1571727600"; d="scan'208";a="265038899" Received: from ingas-nuc1.sea.intel.com ([10.251.159.74]) by FMSMGA003.fm.intel.com with ESMTP; 11 Dec 2019 15:28:48 -0800 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, michal.lowas-rzechonek@silvair.com, Inga Stotland Subject: [PATCH BlueZ] mesh: Add more checks for element properties Date: Wed, 11 Dec 2019 15:28:47 -0800 Message-Id: <20191211232847.31501-1-inga.stotland@intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds consistency checks for mandatory properties on org.bluez.mesh.Element1 interface: - disallow duplicate models on the same element - disallow elements with duplicate indices - disallow configuration server model on any element but primary --- mesh/node.c | 52 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/mesh/node.c b/mesh/node.c index f8acc78c3..1f328bd21 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -1081,7 +1081,7 @@ static void app_disc_cb(struct l_dbus *bus, void *user_data) free_node_dbus_resources(node); } -static void get_sig_models_from_properties(struct node_element *ele, +static bool get_sig_models_from_properties(struct node_element *ele, struct l_dbus_message_iter *property) { struct l_dbus_message_iter ids; @@ -1091,24 +1091,31 @@ static void get_sig_models_from_properties(struct node_element *ele, ele->models = l_queue_new(); if (!l_dbus_message_iter_get_variant(property, "aq", &ids)) - return; + return false; /* Bluetooth SIG defined models */ while (l_dbus_message_iter_next_entry(&ids, &mod_id)) { struct mesh_model *mod; uint32_t id = mod_id | VENDOR_ID_MASK; + /* Allow Config Server Model only on the primary element */ + if (ele->idx != PRIMARY_ELE_IDX && id == CONFIG_SRV_MODEL) + return false; + + /* Disallow duplicates */ if (l_queue_find(ele->models, match_model_id, L_UINT_TO_PTR(id))) - continue; + return false; mod = mesh_model_new(ele->idx, id); l_queue_insert(ele->models, mod, compare_model_id, NULL); } + + return true; } -static void get_vendor_models_from_properties(struct node_element *ele, +static bool get_vendor_models_from_properties(struct node_element *ele, struct l_dbus_message_iter *property) { struct l_dbus_message_iter ids; @@ -1118,21 +1125,24 @@ static void get_vendor_models_from_properties(struct node_element *ele, ele->models = l_queue_new(); if (!l_dbus_message_iter_get_variant(property, "a(qq)", &ids)) - return; + return false; /* Vendor defined models */ while (l_dbus_message_iter_next_entry(&ids, &vendor_id, &mod_id)) { struct mesh_model *mod; uint32_t id = mod_id | (vendor_id << 16); + /* Disallow duplicates */ if (l_queue_find(ele->models, match_model_id, L_UINT_TO_PTR(id))) - continue; + return false; mod = mesh_model_new(ele->idx, id); l_queue_insert(ele->models, mod, compare_model_id, NULL); } + + return true; } static bool get_element_properties(struct mesh_node *node, const char *path, @@ -1150,34 +1160,36 @@ static bool get_element_properties(struct mesh_node *node, const char *path, ele->location = DEFAULT_LOCATION; while (l_dbus_message_iter_next_entry(properties, &key, &var)) { - if (!idx && !strcmp(key, "Index")) { - if (!l_dbus_message_iter_get_variant(&var, "y", + if (!strcmp(key, "Index")) { + + if (idx || !l_dbus_message_iter_get_variant(&var, "y", &ele->idx)) goto fail; + idx = true; - continue; - } - if (!mods && !strcmp(key, "Models")) { - get_sig_models_from_properties(ele, &var); + } else if (!strcmp(key, "Models")) { + + if (mods || !get_sig_models_from_properties(ele, &var)) + goto fail; + mods = true; - continue; - } + } else if (!strcmp(key, "VendorModels")) { + + if (vendor_mods || + !get_vendor_models_from_properties(ele, &var)) + goto fail; - if (!vendor_mods && !strcmp(key, "VendorModels")) { - get_vendor_models_from_properties(ele, &var); vendor_mods = true; - continue; - } - if (!strcmp(key, "Location")) { + } else if (!strcmp(key, "Location")) { if (!l_dbus_message_iter_get_variant(&var, "q", &ele->location)) goto fail; - continue; } } + /* Check for the presence of the required properties */ if (!idx || !mods || !vendor_mods) goto fail; -- 2.21.0