Skip to content

Commit cf66d4e

Browse files
oleremSherryYang1
authored andcommitted
rtc: pcf85063: fix potential OOB write in PCF85063 NVMEM read
[ Upstream commit 3ab8c5e ] 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. Fixes: fadfd09 ("rtc: pcf85063: add nvram support") Signed-off-by: Oleksij Rempel <[email protected]> Signed-off-by: Ahmad Fatoum <[email protected]> Link: https://lore.kernel.org/r/20241218-rtc-pcf85063-stack-corruption-v1-1-12fd0ee0f046@pengutronix.de Signed-off-by: Alexandre Belloni <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 21cd59fcb9952eb7505da2bdfc1eb9c619df3ff4) Signed-off-by: Sherry Yang <[email protected]>
1 parent 5a5a359 commit cf66d4e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

drivers/rtc/rtc-pcf85063.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,16 @@ static const struct rtc_class_ops pcf85063_rtc_ops_alarm = {
332332
static int pcf85063_nvmem_read(void *priv, unsigned int offset,
333333
void *val, size_t bytes)
334334
{
335-
return regmap_read(priv, PCF85063_REG_RAM, val);
335+
unsigned int tmp;
336+
int ret;
337+
338+
ret = regmap_read(priv, PCF85063_REG_RAM, &tmp);
339+
if (ret < 0)
340+
return ret;
341+
342+
*(u8 *)val = tmp;
343+
344+
return 0;
336345
}
337346

338347
static int pcf85063_nvmem_write(void *priv, unsigned int offset,

0 commit comments

Comments
 (0)