From patchwork Tue Jan 5 10:45:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 59177 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp5889666lbb; Tue, 5 Jan 2016 02:46:08 -0800 (PST) X-Received: by 10.66.218.170 with SMTP id ph10mr133649448pac.58.1451990768450; Tue, 05 Jan 2016 02:46:08 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fn1si66398591pad.82.2016.01.05.02.46.08; Tue, 05 Jan 2016 02:46:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752009AbcAEKqG (ORCPT + 11 others); Tue, 5 Jan 2016 05:46:06 -0500 Received: from mail-pa0-f50.google.com ([209.85.220.50]:34499 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751927AbcAEKqF (ORCPT ); Tue, 5 Jan 2016 05:46:05 -0500 Received: by mail-pa0-f50.google.com with SMTP id uo6so194082138pac.1 for ; Tue, 05 Jan 2016 02:46:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=rWhHRtji4kWDY4DuRcwebQvRkLMGoYiAoVmLJcWU04g=; b=bb+gzeZQu63RLoZjqjuugvIem7JDFitZehOzNSWqni5ZW5GvA7UwVEXN72A5PAF4mW b+l2AUbgS9RmjPWES6ApsjRRpqH3GkoO9WRUj6Vlmvd3fnZuQrGPujxbqWRoibuMl600 23N5XotE3oFlUogyj6JCMiSNSCjiXeWHAkjkM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rWhHRtji4kWDY4DuRcwebQvRkLMGoYiAoVmLJcWU04g=; b=AZUYwpKuyqzYl70skDkcz6Ppbv8EYaUrXV1XcPKhJGtSlXvk3lJNAzWzwxppLeOffh 5mH1zEBcc/QM/thnwP7dd8f83MhkCoZ4KDi4iOHlgIVWY5wG88d217hasfbMYZcYGM/Y tGdXYVsalGLqvWwnfP+nZECZRxXgBzBTZJSdz50/ZY6dCIIM/3fk8RucZrdLwd1VKRJl +LWFaP3ba1g0wM+otbe0rb06BdzrU7VwY9ktiLpSifgSxRp74NrMGUVRPaJNv5/T8oCM kTGHixFsETX020rUPPZpp30j1r1dbi4CeFQEl0/TxNQ22SqmGHh/5GRyCrVroykwLJx3 cvQw== X-Gm-Message-State: ALoCoQmvjh2s5eW7JTHQAcfiU/UFUssO3+/WKywdCln/KbWQJVnL5zOOgsQ5cnXvwwMhgKFr9iX08FA3SUku1I7z5BIe9GbunA== X-Received: by 10.66.156.134 with SMTP id we6mr62479261pab.92.1451990764089; Tue, 05 Jan 2016 02:46:04 -0800 (PST) Received: from localhost ([122.171.80.25]) by smtp.gmail.com with ESMTPSA id rt6sm132669915pab.17.2016.01.05.02.46.02 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 05 Jan 2016 02:46:03 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, Viresh Kumar , Geert Uytterhoeven , Greg Kroah-Hartman , Len Brown , linux-kernel@vger.kernel.org (open list), Nishanth Menon , Pavel Machek , Stephen Boyd , Viresh Kumar Subject: [PATCH] PM / OPP: Use snprintf() instead of sprintf() Date: Tue, 5 Jan 2016 16:15:54 +0530 Message-Id: X-Mailer: git-send-email 2.7.0.rc1.186.g94414c4 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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 Signed-off-by: Viresh Kumar --- drivers/base/power/opp/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) -- 2.7.0.rc1.186.g94414c4 -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index cd230c63aee6..cf351d3dab1c 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -808,7 +808,8 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev, /* Search for "opp-microvolt-" */ 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-" */ 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); }