Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1299064pxb; Fri, 1 Apr 2022 09:33:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3hDl4rKfSU3uP95w0oAADK4RCMNwV3ip7S9cZlVWlugT3eB+PRUn7pRDbSfANO3BIn5DA X-Received: by 2002:a17:90b:357:b0:1c6:d666:b08 with SMTP id fh23-20020a17090b035700b001c6d6660b08mr12843726pjb.27.1648830818200; Fri, 01 Apr 2022 09:33:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648830818; cv=none; d=google.com; s=arc-20160816; b=VT8NWuBKhkwtmpV70Lg/ZRa84j5Y3M6tVYRSyi//DMjoEE9LMI5KVVDyQRw9LV9tYF 8Ye1vulit3QDmhT5rB/ADXz9K2x5QuTjme44CPDGPwJWMcesbY1TV9tgpgdZ4HLEAfFN MKbd2Ur8G0Q2FMjltQZvvs65oF4PumgBm1zxwhOrwJBGEb9jOj7PEcz02nPN9+3YrtV5 pR2IMVS6Yh5jQLihladme7AshR1Mjh4hGimjQMIpOhVfrYMYUWtWHCkUZldLjeXHFhkY LdwGsaor5M74zI4qZwlzO32VTcor1vsRx0kBWAuhDOTHojBpe00ijwk6JgTO25oN0Lrk /hqw== 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=FBmYif9d9YllRkNlrjvbN+oa/RPpyMLG4vS3ELrncv4=; b=AxP12nFQM+/jiClv3ifJoZ/Cj/RmYTi7/yYC1NcikBzkb8lrwI7A4Elj4zvmRNjdUo QDcB6Xmyu0vyHTjDuRQGY4N7lxfz0DwRb2+AAzaBOyMb5ENNgwmGG/zYwM068bHHQOht 92WA1knRg9g1Vax2701iVv7B2q3gVeMLqwH+UGffv6RLUliaiwGqY04pug7ejgmAvL0Y nKFwHbRsZXtRfJta+rxCqdotv0eWViIlW1X91jM+XUxrQ7Np3xKTDn3FW8pR9W95wzTM 19l54v5ronfKhFyrxeNT66DWOEdQ12aCIgDIcBTRKcPiixgogM0v0RGg5n4GINmzVQ3t owcQ== 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 f20-20020a635114000000b003816043f120si3172382pgb.789.2022.04.01.09.33.21; Fri, 01 Apr 2022 09:33:38 -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 S1343626AbiDAK35 (ORCPT + 99 others); Fri, 1 Apr 2022 06:29:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343542AbiDAK34 (ORCPT ); Fri, 1 Apr 2022 06:29:56 -0400 Received: from mxout04.lancloud.ru (mxout04.lancloud.ru [45.84.86.114]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0B9C26E57B for ; Fri, 1 Apr 2022 03:28:05 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout04.lancloud.ru 1779520CAB74 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 13:27:51 +0300 Message-ID: <20220401102757.3960551-2-i.kamaletdinov@omp.ru> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401102757.3960551-1-i.kamaletdinov@omp.ru> References: <20220401102757.3960551-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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/monitor/packet.c b/monitor/packet.c index b7431b57d..15d629e2d 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); @@ -2833,7 +2834,7 @@ static void print_le_states(const uint8_t *states_array) 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