Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc: pcf85063: fix potential OOB write in PCF85063 NVMEM read

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: fadfd092ee91 ("rtc: pcf85063: add nvram support")
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.kernel.org/r/20241218-rtc-pcf85063-stack-corruption-v1-1-12fd0ee0f046@pengutronix.de
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

authored by

Oleksij Rempel and committed by
Alexandre Belloni
3ab8c5ed 09c4a610

+10 -1
+10 -1
drivers/rtc/rtc-pcf85063.c
··· 322 322 static int pcf85063_nvmem_read(void *priv, unsigned int offset, 323 323 void *val, size_t bytes) 324 324 { 325 - return regmap_read(priv, PCF85063_REG_RAM, val); 325 + unsigned int tmp; 326 + int ret; 327 + 328 + ret = regmap_read(priv, PCF85063_REG_RAM, &tmp); 329 + if (ret < 0) 330 + return ret; 331 + 332 + *(u8 *)val = tmp; 333 + 334 + return 0; 326 335 } 327 336 328 337 static int pcf85063_nvmem_write(void *priv, unsigned int offset,