* [PATCH 4/8] regulator: tps65910: Fix OOB read and bit shift in external sleep config
2026-11-27 18:35 [PATCH 0/8] regulator: Fix locking, OOB read, lifetime, and global state bugs (batch 2) Lee Jones
@ 2026-11-27 18:35 ` Lee Jones
0 siblings, 0 replies; 2+ messages in thread
From: Lee Jones @ 2026-11-27 18:35 UTC (permalink / raw)
To: lee, Aaro Koskinen, Andreas Kemnade, Kevin Hilman, Roger Quadros,
Tony Lindgren, Liam Girdwood, Mark Brown, Graeme Gregory,
Eduardo Candelaria, Markus Schneider-Pargmann, linux-omap,
linux-kernel
Cc: stable
tps65910_regs contains 14 regulators including VBB at index 13, whereas
tps65910_ext_sleep_control has only 13 elements. Both tps65910_probe()
and tps65910_shutdown() iterate up to pmic->num_regulators and index
pmic->ext_sleep_control[id] out of bounds for VBB.
In addition, unsupported rails such as VRTC use 0, which collides with
VMMC and LDO6 (offset 0, bit 0), and computing
(1 << pmic->ext_sleep_control[id] & 0xFF) shifts by more than 31 bits
whenever regs_offs is non-zero because << binds tighter than &.
Introduce EXT_CONTROL_REG_NONE as a distinct sentinel for rails without
external sleep control (VRTC and VBB), add BUILD_BUG_ON() array-size
checks, return early in tps65910_set_ext_sleep_config() for unsupported
rails, and use BIT(pmic->ext_sleep_control[id] & 0xFF) for bit_pos.
Fixes: 03746dcbde75 ("regulator: tps65910: Add backup battery regulator")
Closes: https://sashiko.dev/#/bug/linux-ed3bcc60-149e-497b-93aa-50138953c49a
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/regulator/tps65910-regulator.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
index b99923773701..d42ffc237bf4 100644
--- a/drivers/regulator/tps65910-regulator.c
+++ b/drivers/regulator/tps65910-regulator.c
@@ -271,9 +271,10 @@ static struct tps_info tps65911_regs[] = {
},
};
+#define EXT_CONTROL_REG_NONE (~0U)
#define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
static unsigned int tps65910_ext_sleep_control[] = {
- 0,
+ EXT_CONTROL_REG_NONE,
EXT_CONTROL_REG_BITS(VIO, 1, 0),
EXT_CONTROL_REG_BITS(VDD1, 1, 1),
EXT_CONTROL_REG_BITS(VDD2, 1, 2),
@@ -286,10 +287,11 @@ static unsigned int tps65910_ext_sleep_control[] = {
EXT_CONTROL_REG_BITS(VAUX2, 0, 4),
EXT_CONTROL_REG_BITS(VAUX33, 0, 5),
EXT_CONTROL_REG_BITS(VMMC, 0, 0),
+ EXT_CONTROL_REG_NONE,
};
static unsigned int tps65911_ext_sleep_control[] = {
- 0,
+ EXT_CONTROL_REG_NONE,
EXT_CONTROL_REG_BITS(VIO, 1, 0),
EXT_CONTROL_REG_BITS(VDD1, 1, 1),
EXT_CONTROL_REG_BITS(VDD2, 1, 2),
@@ -822,10 +824,16 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
int id, int ext_sleep_config)
{
struct tps65910 *mfd = pmic->mfd;
- u8 regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF;
- u8 bit_pos = (1 << pmic->ext_sleep_control[id] & 0xFF);
+ u8 regoffs;
+ u8 bit_pos;
int ret;
+ if (pmic->ext_sleep_control[id] == EXT_CONTROL_REG_NONE)
+ return 0;
+
+ regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF;
+ bit_pos = BIT(pmic->ext_sleep_control[id] & 0xFF);
+
/*
* Regulator can not be control from multiple external input EN1, EN2
* and EN3 together.
@@ -1104,6 +1112,8 @@ static int tps65910_probe(struct platform_device *pdev)
switch (tps65910_chip_id(tps65910)) {
case TPS65910:
BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65910_regs));
+ BUILD_BUG_ON(ARRAY_SIZE(tps65910_regs) !=
+ ARRAY_SIZE(tps65910_ext_sleep_control));
pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
pmic->num_regulators = ARRAY_SIZE(tps65910_regs);
pmic->ext_sleep_control = tps65910_ext_sleep_control;
@@ -1117,6 +1127,8 @@ static int tps65910_probe(struct platform_device *pdev)
break;
case TPS65911:
BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65911_regs));
+ BUILD_BUG_ON(ARRAY_SIZE(tps65911_regs) !=
+ ARRAY_SIZE(tps65911_ext_sleep_control));
pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
pmic->num_regulators = ARRAY_SIZE(tps65911_regs);
pmic->ext_sleep_control = tps65911_ext_sleep_control;
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread