Skip to content

Commit 5ff24d6

Browse files
vireshkrafaeljw
authored andcommitted
PM / OPP: Use snprintf() instead of sprintf()
sprintf() can access memory outside of the range of the character array, and is risky in some situations. The driver specified prop_name string can be longer than NAME_MAX here (only an attacker will do that though) and so blindly copying it into the character array of size NAME_MAX isn't safe. Instead we must use snprintf() here. Reported-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Viresh Kumar <[email protected]> Acked-by: Geert Uytterhoeven <[email protected]> Acked-by: Stephen Boyd <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent d9de19b commit 5ff24d6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/base/power/opp/core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,8 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev,
808808

809809
/* Search for "opp-microvolt-<name>" */
810810
if (dev_opp->prop_name) {
811-
sprintf(name, "opp-microvolt-%s", dev_opp->prop_name);
811+
snprintf(name, sizeof(name), "opp-microvolt-%s",
812+
dev_opp->prop_name);
812813
prop = of_find_property(opp->np, name, NULL);
813814
}
814815

@@ -849,7 +850,8 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev,
849850
/* Search for "opp-microamp-<name>" */
850851
prop = NULL;
851852
if (dev_opp->prop_name) {
852-
sprintf(name, "opp-microamp-%s", dev_opp->prop_name);
853+
snprintf(name, sizeof(name), "opp-microamp-%s",
854+
dev_opp->prop_name);
853855
prop = of_find_property(opp->np, name, NULL);
854856
}
855857

0 commit comments

Comments
 (0)