PM / OPP: Use snprintf() instead of sprintf()
authorViresh Kumar <viresh.kumar@linaro.org>
Tue, 5 Jan 2016 10:45:54 +0000 (16:15 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 6 Jan 2016 01:38:27 +0000 (02:38 +0100)
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 <geert@linux-m68k.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/power/opp/core.c

index cd230c63aee6106245328ae14d94a03629b79612..cf351d3dab1c3b7a9badf6b468092ca216c47012 100644 (file)
@@ -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);
        }
 
@@ -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);
        }