Skip to contentSkip to conversation

platform/x86: oxpec: Add a lower bounds check in oxp_psy_ext_set_prop()

PATCH In review Dan Carpenter 3 participants 3 messages May 2, 2025 – May 5, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86: oxpec: Add a lower bounds check in oxp_psy_ext_set_prop()

The "val->intval" variable is an integer which comes from the user. This code has an upper bounds check but the lower bounds check was accidentally omitted. The write_to_ec() take a u8 value as a parameter so negative values would be truncated to positive values in the 0-255 range.

Return -EINVAL if the user passes a negative value.

Fixes 202593d1e86b ("platform/x86: oxpec: Add charge threshold and behaviour to OneXPlayer")
---
 drivers/platform/x86/oxpec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/oxpec.c +1 -1
index 4b48f4571b09..de70ca7e8493 100644
@@ -582,7 +582,7 @@ static int oxp_psy_ext_set_prop(struct power_supply *psy,
 
 	switch (psp) {
 	case POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD:
-		if (val->intval > 100)
+		if (val->intval < 0 || val->intval > 100)
 			return -EINVAL;
 		return write_to_ec(OXP_X1_CHARGE_LIMIT_REG, val->intval);
 	case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
Signature · 1 line
2.47.2
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Dan Carpenter

The "val->intval" variable is an integer which comes from the user. This code has an upper bounds check but the lower bounds check was accidentally omitted. The write_to_ec() take a u8 value as a parameter so negative values would be truncated to positive values in the 0-255 range.

Return -EINVAL if the user passes a negative value.

Fixes 202593d1e86b ("platform/x86: oxpec: Add charge threshold and behaviour to OneXPlayer")

Thanks,
Antheas

Quoted 21 lines
---
 drivers/platform/x86/oxpec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/oxpec.c +1 -2
index 4b48f4571b09..de70ca7e8493 100644
@@ -582,7 +582,7 @@ static int oxp_psy_ext_set_prop(struct power_supply *psy,
 
        switch (psp) {
        case POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD:
-               if (val->intval > 100)
+               if (val->intval < 0 || val->intval > 100)
                        return -EINVAL;
                return write_to_ec(OXP_X1_CHARGE_LIMIT_REG, val->intval);
        case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
--

2.47.2

maintainer
#2 lore raw
In reply to Dan Carpenter
Quoted 9 lines · Dan Carpenter

The "val->intval" variable is an integer which comes from the user. This code has an upper bounds check but the lower bounds check was accidentally omitted. The write_to_ec() take a u8 value as a parameter so negative values would be truncated to positive values in the 0-255 range.

Return -EINVAL if the user passes a negative value.

[...]

Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.

The list of commits applied:
[1/1] platform/x86: oxpec: Add a lower bounds check in oxp_psy_ext_set_prop()

      commit: 55cd5e760618b3bca5b8ab63fe65ab78a753adf8

--
i.