Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp839069lqo; Fri, 17 May 2024 03:13:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWuuEw1q5ppKVxzNoh8fm0vXsTBDJ1D3WIxXwkoTeLgrZE3FfmxGtVs3aK6tkSq3awlq8Id4xDXgTEStR9zUHfj2rfej7wkPfmgLAmgDA== X-Google-Smtp-Source: AGHT+IEU/2Z9SfvVUYV4zNRlO10d0sDUlYdGbbepw+Qxd/hNJnPdysUquKZJPumN6rfNggGOKjO2 X-Received: by 2002:a05:620a:450a:b0:792:eb35:77b0 with SMTP id af79cd13be357-792eb357941mr1471613285a.11.1715940791479; Fri, 17 May 2024 03:13:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715940791; cv=pass; d=google.com; s=arc-20160816; b=e4GT8DWFrpTtaDdvc1YXb7ssaSVtgSRLn+dk9W5PPLOm2oOi+5S5KneyD47cUXGBWp coeHWnGLW9d0iLkvM2OnRWu16qstV8iNQiXgMQr+NGOfPQoLYcn0jT+AtB0kj8A4Vk21 UR2L12vFXOYgAQ8wA6UrIv5AMgHBn0jhn5ORWJvGpAq2/xhwzjQgUQT7V6dFN03cpWmM ARQK6Ue5xaQamzSBawTeOBCjP67aau7tVoPYep+zNdvuyCHRwjwYOEtVkujnP59gW6kX X7QQ2/rmLD9VrhTjQKUTzqGxLNh72SfHbFy68gVpsHwkMieWjP+Olas5TSGaCqvyr+xX TZsA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=DdDjU8RAWsRCjt4a0p8GXfqvpw/fXzr4zK/kj9NVBs0=; fh=oohzykGtsPnPHfHEdUuhEEh8cgI8SmYe7HH3p7haqMw=; b=YVxqDEq+/hHJMe3s2f7wdYs6GrkJHCWOURDSRoLDid9LyUPWtk/3t015JbRxftdRCR SMFinR9JiUlL5m6CuHAQ+zRoFvJqVLPDdNdz1UrJaPYMPREr8f1B2ShAia8yRAUi/lZU LSwdTcwWXpWpm+6wVWvBkyV9Huoz25K2JIZv9Hqdls7wrenOoJC+z99fh+0YXdD38bv9 T7PdNl8Mokr0d+4WmzM6MKK07bLlNuE/sHCu4CBxYUceyhYmtLeefM1iD8zWjaYujYw5 TlvP4PC1yaw05DH2zIRH3QNJrZtAmXfPz2coX7p0kyDKMyCumkTAyLxEmG4tFBAJeiSc rwAQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b="cbZ8dS/o"; arc=pass (i=1 spf=pass spfdomain=amazon.com dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-181983-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181983-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-792bf29a84dsi216561485a.209.2024.05.17.03.13.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 03:13:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181983-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; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b="cbZ8dS/o"; arc=pass (i=1 spf=pass spfdomain=amazon.com dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-181983-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181983-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com 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 1A1161C22F67 for ; Fri, 17 May 2024 10:12:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A98D2E65B; Fri, 17 May 2024 10:12:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="cbZ8dS/o" Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) (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 2B3B7200D2; Fri, 17 May 2024 10:12:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=207.171.190.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715940764; cv=none; b=Z8GbfHgKyXa8TWNJE1i8GvkXDzUsXwVIFIrMiTuO57rC3c8uRnAbjjDj2b7ndfXH3WIUqZbivOw92xe+fGM/UQ2uf9035UEKwOknjlLNUB5gL3YqI9HAooa1e8iSqLxA3Vof/3FE993NY+wAiySE6yQ4vsY3m3XM16hrCkxtkGM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715940764; c=relaxed/simple; bh=DNCDM6IxkJLGGSLYqPfZ1r8XHL+hCpAHIncnxjbHTj4=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=XRDXDcm7EXRc+/H+t4ehPjHEeJ5zJAfwAVvmsYz+CDpnv5p76YksGkLpAuPvz09R31E3l4t+33ChgOtuSulzus6ftbLvKcQ/N2teFQwsshP6RBJ0BTWP3gl1wfXrtfm8g0UlEUlyBDhdpmm5p4B/WHOLQp7XewNIhaZAzIyyFhI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=cbZ8dS/o; arc=none smtp.client-ip=207.171.190.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1715940764; x=1747476764; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=DdDjU8RAWsRCjt4a0p8GXfqvpw/fXzr4zK/kj9NVBs0=; b=cbZ8dS/o3XOfgEmbr9hyYLdpOy/oLlyKpf4tUCw7zK89ZcVxaKfLaK1a YjP4K7nS/owvkDejz7V10czzDtnVaVLhQ//qkEtF9uN6d12TkPoINYx+5 vvt9fdXgdFkA9F7NTl2lf3gtK1wH9xHAwyqL8sRbmI+MwXgVcbOL+vNKh E=; X-IronPort-AV: E=Sophos;i="6.08,167,1712620800"; d="scan'208";a="345036791" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2024 10:12:38 +0000 Received: from EX19MTAEUC002.ant.amazon.com [10.0.10.100:33278] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.12.108:2525] with esmtp (Farcaster) id d0dc88c3-ff31-469a-bfb3-2ca9871ee2a6; Fri, 17 May 2024 10:12:36 +0000 (UTC) X-Farcaster-Flow-ID: d0dc88c3-ff31-469a-bfb3-2ca9871ee2a6 Received: from EX19D002EUA004.ant.amazon.com (10.252.50.181) by EX19MTAEUC002.ant.amazon.com (10.252.51.245) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Fri, 17 May 2024 10:12:35 +0000 Received: from EX19MTAUEC001.ant.amazon.com (10.252.135.222) by EX19D002EUA004.ant.amazon.com (10.252.50.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Fri, 17 May 2024 10:12:35 +0000 Received: from dev-dsk-hagarhem-1b-b868d8d5.eu-west-1.amazon.com (10.253.65.58) by mail-relay.amazon.com (10.252.135.200) with Microsoft SMTP Server id 15.2.1258.28 via Frontend Transport; Fri, 17 May 2024 10:12:35 +0000 Received: by dev-dsk-hagarhem-1b-b868d8d5.eu-west-1.amazon.com (Postfix, from userid 23002382) id EE56320C24; Fri, 17 May 2024 10:12:34 +0000 (UTC) From: Hagar Hemdan To: CC: Norbert Manthey , Hagar Hemdan , Linus Walleij , Bartosz Golaszewski , Kent Gibson , , Subject: [PATCH v3] gpio: prevent potential speculation leaks in gpio_device_get_desc() Date: Fri, 17 May 2024 10:12:27 +0000 Message-ID: <20240517101227.12118-1-hagarhem@amazon.com> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain Userspace may trigger a speculative read of an address outside the gpio descriptor array. Users can do that by calling gpio_ioctl() with an offset out of range. Offset is copied from user and then used as an array index to get the gpio descriptor without sanitization in gpio_device_get_desc(). This change ensures that the offset is sanitized by using array_index_nospec() to mitigate any possibility of speculative information leaks. This bug was discovered and resolved using Coverity Static Analysis Security Testing (SAST) by Synopsys, Inc. Fixes: aad955842d1c ("gpiolib: cdev: support GPIO_V2_GET_LINEINFO_IOCTL and GPIO_V2_GET_LINEINFO_WATCH_IOCTL") Signed-off-by: Hagar Hemdan --- v3: update the commit mesg --- drivers/gpio/gpiolib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index fa50db0c3605..b58e4fe78cec 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -201,7 +202,7 @@ gpio_device_get_desc(struct gpio_device *gdev, unsigned int hwnum) if (hwnum >= gdev->ngpio) return ERR_PTR(-EINVAL); - return &gdev->descs[hwnum]; + return &gdev->descs[array_index_nospec(hwnum, gdev->ngpio)]; } EXPORT_SYMBOL_GPL(gpio_device_get_desc); -- 2.40.1