Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1236917pxb; Fri, 1 Apr 2022 08:07:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8EbZdMZUI1p8zop7jAFhKNefKl1UP5GxuzJK7fqOM2m7ItyaEebWXh117myWawADR2Ey3 X-Received: by 2002:a17:906:c104:b0:6e4:a223:1af9 with SMTP id do4-20020a170906c10400b006e4a2231af9mr184488ejc.441.1648825628228; Fri, 01 Apr 2022 08:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648825628; cv=none; d=google.com; s=arc-20160816; b=bYBLEbycIHUrUmTPt6ykA596e4POBhkeNYmfu3tlahJAsk9S/VqYdrWIAEYtYbvXSN wj0GdB2MsfW2OBW9Pa1HfzYUsX4k2yqBw6uQ0/ZUE1KBj/5qqMNbR5sVj1Wp2pzr617m eZ4L4LnWWEQ+sMWaquWM4KHRYxrTAItMK8SjjQau28e9mBkLJrxx8gw7eBLT40oTmcWA phkETFcbHlrdhlnsSSeWIJ+m7cuRQGQln4iwAMJzwKevRhQdH2hHBqjwRqpX7Ou/da7Q jmz7Kv5wxiy5DKB0uKBgAsn/ouCwYX9g45vGtpI1WpMCYX87uJky5ntkzaEy4mD0T63A qa5g== 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=k8fWeVyDn5SJvkGIXKrdRBjaiLFNBCCV/aNb7vp3IqHLjwDzBXWDuoG15Q7yeBg/ZJ UpfWgHK25pzWdklxPTiQ2HOopXuC8LIZiw/E3wP0vOV6JCxd8Zcxw+iLoVDuPhfhqbMp V4x1cJAfrE9xjzklSeWwJt9UozNsG48VrBZ74bkZONYn+ow8maRPPb/r/RsxlYL/iThY QRMQeX8ZKxJ014570dKN0EnxpsLysCtZ7Elcp/SKxJcToOOMojlcuOopxmwkUVc1d9Ml Uex2LdgPfQJgzAWDIf8AgqAUczjlqX1Gf0Zp+Gp0faaGjxCWA3yliTvsy1+chAqJGzCi 3khQ== 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 f6-20020a50e086000000b0041b60dcde7csi1694922edl.147.2022.04.01.08.06.40; Fri, 01 Apr 2022 08:07:08 -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 S1345799AbiDAMSn (ORCPT + 99 others); Fri, 1 Apr 2022 08:18:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235252AbiDAMSm (ORCPT ); Fri, 1 Apr 2022 08:18:42 -0400 Received: from mxout04.lancloud.ru (mxout04.lancloud.ru [45.84.86.114]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F7FF276FBE for ; Fri, 1 Apr 2022 05:16:52 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout04.lancloud.ru DC58920D308E Received: from LanCloud Received: from LanCloud Received: from LanCloud From: Ildar Kamaletdinov To: CC: Ildar Kamaletdinov Subject: [PATCH BlueZ 1/6] monitor: Fix out-of-bound read in print_le_states Date: Fri, 1 Apr 2022 15:16:42 +0300 Message-ID: <20220401121647.3985682-2-i.kamaletdinov@omp.ru> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401121647.3985682-1-i.kamaletdinov@omp.ru> References: <20220401121647.3985682-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: LFEXT02.lancloud.ru (fd00:f066::142) 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