* [PATCH master] rtc: pcf85063: fix potential OOB write in PCF85063 NVMEM read
@ 2024-12-17 11:52 Ahmad Fatoum
2024-12-20 8:51 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-12-17 11:52 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
From: Oleksij Rempel <o.rempel@pengutronix.de>
The nvmem interface supports variable buffer sizes, while the regmap
interface operates with fixed-size storage. If an nvmem client uses a
buffer size less than 4 bytes, regmap_read will write out of bounds
as it expects the buffer to point at an unsigned int.
Fix this by using an intermediary unsigned int to hold the value.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/rtc/rtc-pcf85063.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/rtc/rtc-pcf85063.c b/drivers/rtc/rtc-pcf85063.c
index 82d8d22029f0..55257dc6b1c4 100644
--- a/drivers/rtc/rtc-pcf85063.c
+++ b/drivers/rtc/rtc-pcf85063.c
@@ -168,7 +168,16 @@ static const struct rtc_class_ops pcf85063_rtc_ops = {
static int pcf85063_nvmem_read(void *priv, unsigned int offset,
void *val, size_t bytes)
{
- return regmap_read(priv, PCF85063_REG_RAM, val);
+ unsigned int tmp;
+ int ret;
+
+ ret = regmap_read(priv, PCF85063_REG_RAM, &tmp);
+ if (ret < 0)
+ return ret;
+
+ *(u8 *)val = tmp;
+
+ return 0;
}
static int pcf85063_nvmem_write(void *priv, unsigned int offset,
--
2.39.5
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH master] rtc: pcf85063: fix potential OOB write in PCF85063 NVMEM read
2024-12-17 11:52 [PATCH master] rtc: pcf85063: fix potential OOB write in PCF85063 NVMEM read Ahmad Fatoum
@ 2024-12-20 8:51 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2024-12-20 8:51 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Tue, 17 Dec 2024 12:52:52 +0100, Ahmad Fatoum wrote:
> The nvmem interface supports variable buffer sizes, while the regmap
> interface operates with fixed-size storage. If an nvmem client uses a
> buffer size less than 4 bytes, regmap_read will write out of bounds
> as it expects the buffer to point at an unsigned int.
>
> Fix this by using an intermediary unsigned int to hold the value.
>
> [...]
Applied, thanks!
[1/1] rtc: pcf85063: fix potential OOB write in PCF85063 NVMEM read
https://git.pengutronix.de/cgit/barebox/commit/?id=e3de867716e9 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-12-20 8:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-17 11:52 [PATCH master] rtc: pcf85063: fix potential OOB write in PCF85063 NVMEM read Ahmad Fatoum
2024-12-20 8:51 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox