Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp451770lqo; Fri, 10 May 2024 05:14:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWyC8ZeOcoRpXdBLpbzDdogGCcN/7v5r6BYC6tT3ZO+7QlWMJjCdz+XC/YAjCVN7s7HB6IpQtvPFyolZ0g+fgAsrMKU1Rpw2kNlXHCs4Q== X-Google-Smtp-Source: AGHT+IEOjUq2yPO1YSM1EmlwjOXfyrkEnrS3Z5/NZRTjGF08twdE8MzjWWEAga/gcYaNUOFX9YoH X-Received: by 2002:a50:9f4e:0:b0:56e:2bfe:cdcd with SMTP id 4fb4d7f45d1cf-5734d597e89mr1497062a12.1.1715343268891; Fri, 10 May 2024 05:14:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715343268; cv=pass; d=google.com; s=arc-20160816; b=n6sqTIIrWQu2G/xSUYqC1yUvZzX9jgRDki+DjWopE4emPrIDw1OOJBU2rP9QTDA7Gb C1Tuu/4GVRRLpC9Tv41Nu+Hj6EO1SDbmzEd3R+5I21etksnXZSzwIcGTt+i5jOMDhvmH h5bKrnGnNoGHlX3o5NQoq961TPb9c/q6U89SLX7XoCe8YFpXh3CXAlwDlmNMld2N555Q gaDim6sLX/SVyIZYxyG2fDQK2R19fpjtvbPpyvM7hyIdopQZBAgRP4kL9KSB5y8eNfAZ /ChVnu96vuXfUc4l2VOFutfoHNREal46j4/xuvJs/FAenGaEsP6FNNc5KaZDDULSAfeo CTgw== 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:cc:to:from; bh=6cn2Pa07Q5le0+ceac9GZnMMYR+VJRYOsgxxPkEDE8k=; fh=uo5u2TQK/HQlhydMwGLjBAnuDwaLxndJ/cgWTjIagS8=; b=BMEGqwiH/6Wcd1lsGzr3TYJ0BR8x5csEmarOpeUg3xDBFry6JSL19pvM1IL6LJdzK1 KhcgaG3M+cYSvZwz269QDx9I3k/fYPd7wTMR6XJ8OTFxz9oxtHE2Jg2a9IsvZ5Q+502A 3YzPWY8PsbTQgSB/FGIlRjIx/9OJxlQwdk/LKFxBrSjHdNYSX5X65biRH9Yiu3LrRMw1 nexVQ1ZcVI1WV0nQY6W/6u9CXrN0zNoHMkJmN1rVUMcXFJYNpJRnzO9xcEJLELdDulRk aJp+xyJAD8WwYh2pWAMnop4lqTgiekeHNuze1zA9xDHkCzXmeK8k87FkbDck4uPNPbIs 0d+Q==; 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-4469-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4469-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733c2e45e6si1896547a12.206.2024.05.10.05.14.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 05:14:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-4469-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-4469-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4469-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 9D82D1F21AB5 for ; Fri, 10 May 2024 12:14:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 076C6170884; Fri, 10 May 2024 12:14:15 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (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 49674170889 for ; Fri, 10 May 2024 12:14:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715343253; cv=none; b=mgofisy0Nr5zmi88ePf3AcsjqahgKXIHvJNeZ1qCHU+wa/1SvtVc359imDmjMvKgNA5pce8ZVJad6cH0+JEJnwg5tzo4+oj2HlUAxYnyyPk973doX/5oCfiVh2XXRG8HwlSReRzbbyNDTm4NsQvPrao0MByHs5yW+wOM0QD6ACQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715343253; c=relaxed/simple; bh=qz8dsn86PoKyiEMWJOJVKAKfMqx70ZUJV6tnXXFCHS0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qqMG5kcRWHZf90j592THZ4lQPb+pFvIOJ/rXD78Jx2oZHiDB1ENoL0vmAuJyqmoSCdrOgy3QUHjFgCii1mj88HeF/7+qIJwXsFRO3Q6moA/e5yPaxCjmkCno4QevhUy4pb3u9PhlB5atTRBZKCEnmRIJDI4TURhw1AzBs2XCw9w= 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.195 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 40E7560002; Fri, 10 May 2024 12:13:56 +0000 (UTC) From: Bastien Nocera To: linux-bluetooth@vger.kernel.org Cc: Bastien Nocera Subject: [BlueZ v2 02/20] attrib/gatt: Guard against possible integer overflow Date: Fri, 10 May 2024 14:10:12 +0200 Message-ID: <20240510121355.3241456-3-hadess@hadess.net> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240510121355.3241456-1-hadess@hadess.net> References: <20240510121355.3241456-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