Skip to content

Commit

Permalink
PM / OPP: Use snprintf() instead of sprintf()
Browse files Browse the repository at this point in the history
commit 5ff24d6 upstream.

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]>
Signed-off-by: Dave Gerlach <[email protected]>
  • Loading branch information
vireshk authored and Tero Kristo committed Apr 28, 2016
1 parent 02ffa49 commit 10aa4d4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/base/power/opp/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,8 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev,

/* Search for "opp-microvolt-<name>" */
if (dev_opp->prop_name) {
sprintf(name, "opp-microvolt-%s", dev_opp->prop_name);
snprintf(name, sizeof(name), "opp-microvolt-%s",
dev_opp->prop_name);
prop = of_find_property(opp->np, name, NULL);
}

Expand Down Expand Up @@ -849,7 +850,8 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev,
/* Search for "opp-microamp-<name>" */
prop = NULL;
if (dev_opp->prop_name) {
sprintf(name, "opp-microamp-%s", dev_opp->prop_name);
snprintf(name, sizeof(name), "opp-microamp-%s",
dev_opp->prop_name);
prop = of_find_property(opp->np, name, NULL);
}

Expand Down

0 comments on commit 10aa4d4

Please sign in to comment.