Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1234445pxb; Fri, 1 Apr 2022 08:04:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYJMaNcgKUeyYq1FK3RpArs5nc00xWOWuv+33CaZVQ5/lwFmBR91Mzcp9qouCgBT4FzLoB X-Received: by 2002:a17:907:2ce3:b0:6df:d4a8:9039 with SMTP id hz3-20020a1709072ce300b006dfd4a89039mr162915ejc.697.1648825483913; Fri, 01 Apr 2022 08:04:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648825483; cv=none; d=google.com; s=arc-20160816; b=IFkLwIFMEXVnJrOC5MUZmVHwvoSLpYUOl0a6FcT4TTSI4cBRAfVgnO68x07KVnhykt UppKEyjFEYOkZaveqsOGYoq7Mvq8AXfYjy9Pd9MfeRcpULZP5hQvDcjTQr+JEzbi3lCG rl6ROlpYGTpUOftcfqxMrMbnuf19y479WhdOYk4XalmLSLKszdUqO32GAtElQkPUkoON DaokbNwnrsUqUmdTxcjZy9Klay8KBq5HjiQNqHoyAKPxjFMmUk9MdmoeJRzAkjvSOsPj dJzecAVQgbqhll3j3veFv5/N4RF6ZBRuxEUellvBEJDXS+TmCm98geaQICZBNcozryrR mT8A== 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=hABerABWM15n/Dy3jrExG97UjcKAfGdWCYyEIvHll64=; b=I2aJYthII/h/CF8GSITNXQVxky5ZKiyxxvPflZVg0/9O7bkB9yFTlff8VeF7NHaauO K3JHpv7G8Yz806Hm0RwuBhcGHVXeu7EMydldMhwhLsMNnX5fYrZZU15BteYxUWuSrfhP rusD6yW5Rd6CUJtPs9Rs6pWeFp95Zx+lO7ak6p/0kQxDAQr65OxWa0Vo/a7dMgKLz4NH Ja3GJ1PGJjFPrxxBCdgEdE8N/kFwTDQPZuWO1BYucE1NclclgSlpTZZq/+znG501g1Im Jn19cAn6cLbutKx8W0QdmUvNm/lAww8lqX1M6l4zctj8+lvOycxens/bMN82RM9fxrXx utyA== 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 h14-20020a1709063b4e00b006df76385d76si1666264ejf.534.2022.04.01.08.04.18; Fri, 01 Apr 2022 08:04:43 -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 S1343675AbiDAHyk (ORCPT + 99 others); Fri, 1 Apr 2022 03:54:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243482AbiDAHyj (ORCPT ); Fri, 1 Apr 2022 03:54:39 -0400 Received: from mxout02.lancloud.ru (mxout02.lancloud.ru [45.84.86.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF14F26240B for ; Fri, 1 Apr 2022 00:52:50 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout02.lancloud.ru 4A8962297C51 Received: from LanCloud Received: from LanCloud Received: from LanCloud From: Ildar Kamaletdinov To: CC: Ildar Kamaletdinov Subject: [PATCH BlueZ 3/7] tools: Fix signed interger overflow in btsnoop.c Date: Fri, 1 Apr 2022 10:46:36 +0300 Message-ID: <20220401074640.3956695-4-i.kamaletdinov@omp.ru> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401074640.3956695-1-i.kamaletdinov@omp.ru> References: <20220401074640.3956695-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 If malformed packet is proceed with zero 'size' field we will face with wrong behaviour of write() call. Value 'toread - 1' gives wrong sign for value 'written' (-1) in write() call. To prevent this we should check that 'toread' is not equal to zero. Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool. --- tools/btsnoop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/btsnoop.c b/tools/btsnoop.c index 738027dfc..a0d6cf356 100644 --- a/tools/btsnoop.c +++ b/tools/btsnoop.c @@ -193,7 +193,7 @@ next_packet: flags = be32toh(input_pkt[select_input].flags); len = read(input_fd[select_input], buf, toread); - if (len < 0 || len != (ssize_t) toread) { + if (toread == 0 || len < 0 || len != (ssize_t) toread) { close(input_fd[select_input]); input_fd[select_input] = -1; goto next_packet; -- 2.34.0