Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp368271lqo; Fri, 10 May 2024 02:18:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVGgjtCbpUO2oNfR/SdExfdmSiB2EhZlBwgz6jTHmhPMeBSeY4U6NHyLLQScWdHNjAnC3J+VAbRILPrIEwUebGADdhLOG9XH2aY19FbUw== X-Google-Smtp-Source: AGHT+IEPU/+6gOlttsOiDiKC7vsx4y7mG6ksFaY9lISb0mSqV1mTEBPqfw73RIyWvsMVpjd+KIIG X-Received: by 2002:a05:620a:4709:b0:790:f2f5:cbc6 with SMTP id af79cd13be357-792c75af078mr295475785a.36.1715332733563; Fri, 10 May 2024 02:18:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715332733; cv=pass; d=google.com; s=arc-20160816; b=wkUi6LXohRL45HKhKozAxA9AZi2AU++h3/bM1aIaAE/9EqzXetxe3zwcAFIE1nDTsw ZVHCcRj5KoyWqpmjY1EigIzyrb89U729ZvlLiXqVoH+clUGxlxUjdSukfXH5bFYPzjZM ryHniWUj0xuhdDdtl9NZi1SYwGKwIo8iEiEKzXle15B5/8Ud9Z7KEopq0LDg8T3Rn2oR Pq9arNBTS5n9wpvCWVQ+2uTX4E174oiHC933lzC220U9aQ9N7ml03YcGoC/h+5pG/h5E 4ZId4Er4nttrLuLZl5Yw1ENifHdqQVuoezEjbBqeS1ov+PErbiSL/aPMIBpvwzWRBQjj 4CNQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from; bh=6cn2Pa07Q5le0+ceac9GZnMMYR+VJRYOsgxxPkEDE8k=; fh=4lGQI6056MBa4/oovMyIYaKLn+Wz/24RGvUivMmQP8E=; b=GEl72JJXq3oCZddA+9V7kEvvCMYWYjP7gOYwlgxXL97hiIlr32ulwesqdzfbY4HWHx aq75PH0w+44Xs+mUV7BSHED1Jejv5vn3evWKP+VAFdGk4hFxN5IMSoiUCDJRCnNt2eK7 vcWN5f8CWBlzd06ljOv2E22U1MNUceoxRDWjntgI+pNhhqCVUAoBztXdr1cTcGkPZHpB jP5vTM/jnKP9rz2eVzcAB2zKgj85ADIv8ey0BrbBqebvVphaadkrV6JTYH/f9i7inJmV d62VFMjhFTVPS6Vc6A4IQ74IpT93Iw6CcVKdoSajOOqpjpNWJhi/snTAEVJF84/SEstU ZO6w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-4452-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4452-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-792bf33bad1si300665085a.513.2024.05.10.02.18.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 02:18:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-4452-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-4452-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4452-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6F2A41C22171 for ; Fri, 10 May 2024 09:18:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C17C1168AE4; Fri, 10 May 2024 09:18:26 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3793F1635CA for ; Fri, 10 May 2024 09:18:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715332706; cv=none; b=PyhGKnsGE831NUmR9mXOqHfhZP4Y38aUWpJWFu2mPbIjuHj6NxumcphpmcsdePhUYIKGOG4JKJUrnIkIgSObA8tNs1x80kd0bok8cMLRoph8dvJjXDiF+yh6a2dbgobizf7uWwYuLfy0gwV/oClPZkMMaz2REMWXaafiiypUb9I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715332706; c=relaxed/simple; bh=qz8dsn86PoKyiEMWJOJVKAKfMqx70ZUJV6tnXXFCHS0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aJbtMydpaXg9fOshsGKL/lJYubog/fFRKW+qcDF2HBQLhcJa/GO996T2tUKpPZVkKbprVbZnHRj2zbnBiQISAUciVUTXUsYfAF4L90rhqTrpxG9G86IM4H/y812cLN9zSB8PbgR053JD1zbNXcIiddoSe2lbtcAwPjFoJfYNneI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net; spf=pass smtp.mailfrom=hadess.net; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hadess.net Received: by mail.gandi.net (Postfix) with ESMTPSA id BFD8A1BF20A for ; Fri, 10 May 2024 09:18:15 +0000 (UTC) From: Bastien Nocera To: linux-bluetooth@vger.kernel.org Subject: [BlueZ 02/14] attrib/gatt: Guard against possible integer overflow Date: Fri, 10 May 2024 11:11:00 +0200 Message-ID: <20240510091814.3172988-3-hadess@hadess.net> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240510091814.3172988-1-hadess@hadess.net> References: <20240510091814.3172988-1-hadess@hadess.net> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: hadess@hadess.net Error: INTEGER_OVERFLOW (CWE-190): [#def30] bluez-5.75/attrib/gatt.c:1016:2: known_value_assign: "last" = "65535", its value is now 65535. bluez-5.75/attrib/gatt.c:1087:2: overflow_const: Expression "dd->start", which is equal to 65536, where "last + 1" is known to be equal to 65536, overflows the type that receives it, an unsigned integer 16 bits wide. 1085| } 1086| 1087|-> dd->start = last + 1; 1088| 1089| if (last < dd->end && !uuid_found) { --- attrib/gatt.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/attrib/gatt.c b/attrib/gatt.c index b496dd1ebd95..3cedae9d167a 100644 --- a/attrib/gatt.c +++ b/attrib/gatt.c @@ -1076,10 +1076,12 @@ static void desc_discovered_cb(guint8 status, const guint8 *ipdu, att_data_list_free(list); /* - * If last handle is lower from previous start handle then it is smth - * wrong. Let's stop search, otherwise we might enter infinite loop. + * If last handle is lower from previous start handle or if iterating + * to the next handle from the last possible offset would overflow, then + * something is wrong. Let's stop search, otherwise we might enter + * infinite loop. */ - if (last < dd->start) { + if (last < dd->start || last == G_MAXUINT16) { err = ATT_ECODE_UNLIKELY; goto done; } -- 2.44.0