Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6773120ybi; Mon, 8 Jul 2019 08:25:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxCtIiZxV0pSx28GJN/0VLeQVr2yldnWO4xmiJmuza9cMguGXJyms9ZZIhSfM+0RBtAkxbT X-Received: by 2002:a17:90a:2244:: with SMTP id c62mr27102452pje.29.1562599554430; Mon, 08 Jul 2019 08:25:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562599554; cv=none; d=google.com; s=arc-20160816; b=Cy7lToB9qvJD0XoZFAnq/6uFE1dVGpFMTGKI/KJPsm9j4ggsIsfmgzKCFYHObj6wvt xi0AtQc1UudUwgMUUGb5wUqltQ06D0m4xZyl7qEbOWav7AyiyLXAY0lNgATfFoYwhYZm P47kEINt75xICJJ2H7kIP8SAjgZ0sHY+sEyfkFA5fYaHvhrFp/ELRfeGNYmZ7TTg94Va fVLoHf8Jn04pW2KZSV1/p52jDoy5neNJK5Ra7d2lPnIkQl/JYlSBc8EQu3XcFgw7Sw5M 8rqhpJmC4qbCqV+dhBUYNG5JZEFmZ+1YBnLQyDZAcMxhaA/hXQd7oAMDBpq4nPb/SKc0 WrgA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rNBBTiyJXDCqCL3nhvikdoEual2kbDBe8aidWZ7wvZk=; b=XRsgBWmj/EcNuRL0iYltb/LYc0UrVTZdP+9zLpNQDlpndRkAUKHTw0bYa1YuowgYIv tPzI5bBrE8xD14IncHEGBRuOvC7B8wzxxGaKSAP8tn9SB9CNK1f2TgOjgIms6w0qEOMj BNzE0w3ZMde19r4P4eWo7GBNeuQP3GVbK52RPjM7fpNVK/YAj46ScmZXVJGH4CCKAjsz pnbzwnE5DVt9REJzf+YwmImso5Gf2S9wQPhOTqMmWacZAuC8YMXyLhMPZWl2uzg8kiVd 9k/4cBuyWtmXbvvp4gs96Eshl2Tb826N0jkASi3HWfGdl3C1RfMmv5RiOjCZ9FS8zUgz t/0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=VosmAvcG; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k137si19231534pga.59.2019.07.08.08.25.39; Mon, 08 Jul 2019 08:25:54 -0700 (PDT) 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; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=VosmAvcG; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728941AbfGHONX (ORCPT + 99 others); Mon, 8 Jul 2019 10:13:23 -0400 Received: from mail-wr1-f45.google.com ([209.85.221.45]:40458 "EHLO mail-wr1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729324AbfGHONX (ORCPT ); Mon, 8 Jul 2019 10:13:23 -0400 Received: by mail-wr1-f45.google.com with SMTP id r1so10966957wrl.7 for ; Mon, 08 Jul 2019 07:13:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rNBBTiyJXDCqCL3nhvikdoEual2kbDBe8aidWZ7wvZk=; b=VosmAvcGKTeX9oDKAuUT8v5569xx/H35QO0gQqxlrSLUjNP1M70uLZzKS36KWEpBwG 9c6RDzfzcCQ0nEIIQbK+bxQRO3N7Wty7bLV2c5zzWypTXu9Yi5RiS4hA4vwm6/Lzmwjw oWEhWL//pyzOisQf/loLtHkWcJwn4KBSUHRjpvZjBw07ja2gOptaqc7JoqB98YMh4fgB 6WKGmZhXVv7Poo8KDzqZYVBU68bsRb0g+uFeWEa1sZ26ttKTXvQsbrEuQSskIR7luCYp GB/Qw4099zTrQrPzI13hAAe5kHb6FAP/cmk46tUX68qxU1cKCb2uedWVkCOoKy5tNz52 nO4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rNBBTiyJXDCqCL3nhvikdoEual2kbDBe8aidWZ7wvZk=; b=BLD8PFxgzX0I5Hp47NuxYy5K5+PC34/gYYAT5ZK3BQaFG4C9iphmVaEhUHOvd9Fzwp tZoGaNFR78GusU8jCT+Bb3WvCufuBE3G/ycxYU0XufZg3csH0ccRIrMaIAjMijnThGnx Fhp/uprT/AlYXFS43mqzf1i9BBXRsL3zpgEggkII6lqXnDkxSO6m8uTG8ijAYxM3GkOc sjudHPzaURHhTZYofIzY3nwDnGiEBb1RiBiwls62SJvKc34J7cOftpPmN0s/m02KRv1t 1sxwvjblGwI9JJJcmOLKNZI5qbHmmmOO38pIsArOugWNLgkbMjcI7lnXm8SsWmqYaBB2 S7Zw== X-Gm-Message-State: APjAAAUtSAJG8LSsXytT4/gupMmx+9apuVpH9uLskpnwV9a0b+WPF/TE r2ZGmj00LFh5sY4qWPdB55IVZK8V0AhzWw== X-Received: by 2002:a05:6000:145:: with SMTP id r5mr10045833wrx.208.1562595200864; Mon, 08 Jul 2019 07:13:20 -0700 (PDT) Received: from localhost.localdomain ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id m7sm5392574wrx.65.2019.07.08.07.13.19 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 08 Jul 2019 07:13:20 -0700 (PDT) From: Jakub Witowski To: linux-bluetooth@vger.kernel.org Cc: Inga Stotland Subject: [RFC BlueZ 1/1] mesh: Validate element indexation Date: Mon, 8 Jul 2019 16:13:14 +0200 Message-Id: <20190708141314.13950-2-jakub.witowski@silvair.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190708141314.13950-1-jakub.witowski@silvair.com> References: <20190708141314.13950-1-jakub.witowski@silvair.com> 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 implementation checks if there is no gap between given element_indexes --- mesh/node.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mesh/node.c b/mesh/node.c index 1f781cfe9..35f85b0f2 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -1439,6 +1439,14 @@ static bool add_local_node(struct mesh_node *node, uint16_t unicast, bool kr, return true; } +static void collect_ele_idxs(void *a, void *b) +{ + const struct node_element *element = a; + uint64_t *ele_idx_list = (uint64_t *)b; + + *ele_idx_list |= (1 << element->idx); +} + static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) { struct l_dbus_message_iter objects, interfaces; @@ -1449,6 +1457,7 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) bool have_app = false; bool is_new; uint8_t num_ele; + uint64_t ele_idx_list = 0; is_new = (req->type != REQUEST_TYPE_ATTACH); @@ -1533,6 +1542,12 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) goto fail; } + /* Check for proper element indexation */ + l_queue_foreach(node->elements, collect_ele_idxs, &ele_idx_list); + + if (((ele_idx_list + 1) & ele_idx_list) != 0) + goto fail; + if (req->type == REQUEST_TYPE_ATTACH) { node_ready_func_t cb = req->cb; -- 2.20.1