Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1254661pxb; Fri, 1 Apr 2022 08:29:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkTcRhd/TSutuPgrUrdmFZVa3uKQgXSvDt7iLkkYXHVHBTDWW31qUgLywrODq15kGX2S1p X-Received: by 2002:a05:6402:100e:b0:416:596a:2581 with SMTP id c14-20020a056402100e00b00416596a2581mr21982815edu.181.1648826987531; Fri, 01 Apr 2022 08:29:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648826987; cv=none; d=google.com; s=arc-20160816; b=dmJsjOl2mSNpa+rsn4vXX+T4x7/soHJEYGsjpfuHZ8TgjKIgprmWgna7Ox2LJtNjJO qP8XWb8tveIphSd4Hk9dzZiPBwPhuTjy7T0R8PW/BCueWSI426BPk6VXvyKHl93S6vdF Y8XLd1GRwG1xMXHO1K+1vdDC47uveraRoPcmIYPjwLZqg1goEn/Qle801Eq6Oq8KTjeM r7L1IJVyktq6pZ5KtlboGT7k4xSt1tx6u4Uu+8yvBi2hrSluPE6JyW1fltf/TWpbVfvf f0cUQhot1t6GLcnYAqwiOBfBlzOd0i1yry3nFCmDxBY98bUlsSGFiqkVjhpV5Xrl/3VB 477g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-filter; bh=w1BS5ej3TUunbikyOqcuGXBEkFb0Mvj/LWcb7KlhLyc=; b=oGByHOEnvuWbA+9QfVkYropwxZPsb05CkS5hF853+8vXgB4Gai944W+pIY62ND+9AY 79JEn+MpnQ5HX5n4qDOx6bVeqRyn2xjDLm/bWw2EY+wxsjVoqCZhYWA21crH1ccVzvuZ 6X2hixQnQ2BRUbwLyFlV+uqWfSiDnHs9uvlYJ4x+F3ZpMz7/uhixYT6vWgMUYlQfF2sW NtbxbYyErn68lk4ku9kLkA1JENvSDdGxUTB11lRgzidsiqCMQniI+vbdboswZ73TWQQZ W1g7gXJdOBxZSJCLjkZEtLYtOh9NQ6t641OXF4A/4lnBrzJAvxHipKvGXLyMz2jH8/7d 6d1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv19-20020a170906b1d300b006df76385e6bsi1789518ejb.779.2022.04.01.08.29.04; Fri, 01 Apr 2022 08:29:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345342AbiDALQF (ORCPT + 99 others); Fri, 1 Apr 2022 07:16:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345279AbiDALQF (ORCPT ); Fri, 1 Apr 2022 07:16:05 -0400 Received: from mxout03.lancloud.ru (mxout03.lancloud.ru [45.84.86.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDF58121507 for ; Fri, 1 Apr 2022 04:14:15 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout03.lancloud.ru 5332C20E7852 Received: from LanCloud Received: from LanCloud Received: from LanCloud From: Ildar Kamaletdinov To: CC: Ildar Kamaletdinov Subject: [PATCH BlueZ 1/7] monitor: Fix out-of-bound read in print_le_states Date: Fri, 1 Apr 2022 14:14:02 +0300 Message-ID: <20220401111408.3961844-2-i.kamaletdinov@omp.ru> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401111408.3961844-1-i.kamaletdinov@omp.ru> References: <20220401111408.3961844-1-i.kamaletdinov@omp.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [192.168.11.198] X-ClientProxiedBy: LFEXT01.lancloud.ru (fd00:f066::141) To LFEX1910.lancloud.ru (fd00:f066::80) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Accessing le_states_desc_table array with value 15 can cause out-of-bound read because current size of array is 14. Currently this cannot lead to any problems becase we do no have such state in le_states_comb_table but this could be changed in future and raise described problem. Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool. --- monitor/packet.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/monitor/packet.c b/monitor/packet.c index b7431b57d..1f04063d3 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -2816,7 +2816,8 @@ static const struct { static void print_le_states(const uint8_t *states_array) { uint64_t mask, states = 0; - int i, n; + int i = 0; + size_t n = 0; for (i = 0; i < 8; i++) states |= ((uint64_t) states_array[i]) << (i * 8); @@ -2828,12 +2829,12 @@ static void print_le_states(const uint8_t *states_array) for (i = 0; le_states_comb_table[i].states; i++) { uint64_t val = (((uint64_t) 1) << le_states_comb_table[i].bit); const char *str[3] = { NULL, }; - int num = 0; + size_t num = 0; if (!(states & val)) continue; - for (n = 0; n < 16; n++) { + for (n = 0; n < ARRAY_SIZE(le_states_desc_table); n++) { if (le_states_comb_table[i].states & (1 << n)) str[num++] = le_states_desc_table[n].str; } -- 2.35.1