From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Hagar Hemdan <hagarhem@amazon.com>,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
Sasha Levin <sashal@kernel.org>,
linus.walleij@linaro.org, brgl@bgdev.pl,
linux-gpio@vger.kernel.org
Subject: [PATCH AUTOSEL 6.6 2/9] gpio: prevent potential speculation leaks in gpio_device_get_desc()
Date: Sat, 27 Jul 2024 20:48:03 -0400 [thread overview]
Message-ID: <20240728004812.1701139-2-sashal@kernel.org> (raw)
In-Reply-To: <20240728004812.1701139-1-sashal@kernel.org>
From: Hagar Hemdan <hagarhem@amazon.com>
[ Upstream commit d795848ecce24a75dfd46481aee066ae6fe39775 ]
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.
Signed-off-by: Hagar Hemdan <hagarhem@amazon.com>
Link: https://lore.kernel.org/r/20240523085332.1801-1-hagarhem@amazon.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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 1c512ed3fa6d9..5c0016c77d2ab 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -15,6 +15,7 @@
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/module.h>
+#include <linux/nospec.h>
#include <linux/of.h>
#include <linux/pinctrl/consumer.h>
#include <linux/seq_file.h>
@@ -164,7 +165,7 @@ struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc,
if (hwnum >= gdev->ngpio)
return ERR_PTR(-EINVAL);
- return &gdev->descs[hwnum];
+ return &gdev->descs[array_index_nospec(hwnum, gdev->ngpio)];
}
EXPORT_SYMBOL_GPL(gpiochip_get_desc);
--
2.43.0
next prev parent reply other threads:[~2024-07-28 0:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-28 0:48 [PATCH AUTOSEL 6.6 1/9] fs: remove accidental overflow during wraparound check Sasha Levin
2024-07-28 0:48 ` Sasha Levin [this message]
2024-07-28 0:48 ` [PATCH AUTOSEL 6.6 3/9] hwmon: corsair-psu: add USB id of HX1200i Series 2023 psu Sasha Levin
2024-07-28 0:48 ` [PATCH AUTOSEL 6.6 4/9] rcutorture: Fix rcu_torture_fwd_cb_cr() data race Sasha Levin
2024-07-28 0:48 ` [PATCH AUTOSEL 6.6 5/9] md: do not delete safemode_timer in mddev_suspend Sasha Levin
2024-07-28 0:48 ` [PATCH AUTOSEL 6.6 6/9] md/raid5: avoid BUG_ON() while continue reshape after reassembling Sasha Levin
2024-07-28 0:48 ` [PATCH AUTOSEL 6.6 7/9] block: change rq_integrity_vec to respect the iterator Sasha Levin
2024-07-28 0:48 ` [PATCH AUTOSEL 6.6 8/9] rcu: Fix rcu_barrier() VS post CPUHP_TEARDOWN_CPU invocation Sasha Levin
2024-07-28 0:48 ` [PATCH AUTOSEL 6.6 9/9] clocksource/drivers/sh_cmt: Address race condition for clock events Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240728004812.1701139-2-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=bartosz.golaszewski@linaro.org \
--cc=brgl@bgdev.pl \
--cc=hagarhem@amazon.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox