Message ID | 20230418130743.67024-1-n.zhandarovich@fintech.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2845309vqo; Tue, 18 Apr 2023 06:21:24 -0700 (PDT) X-Google-Smtp-Source: AKy350ZXTZ4zV59Q3/or/lAnhlAddKky2hGDV5EcLIdmKzY16pGfN5h9iA43W2hcmQyNFNzU1kb5 X-Received: by 2002:a05:6a21:99a0:b0:ee:e719:7a9b with SMTP id ve32-20020a056a2199a000b000eee7197a9bmr14480172pzb.21.1681824084213; Tue, 18 Apr 2023 06:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681824084; cv=none; d=google.com; s=arc-20160816; b=bBc2R0r45tzNZWk/TcN+zgzdrM8ar/gaEKzaXDOaGlrh9I43GJPJTjFsz5eJ+ycFFr HtxSRG2c9kKHOeU85Y9Il5LB00WpkzZpP02T9RWz7ggOSSA/CrnObczWuUuXYUuw+u1X xeSMVE/jsb0pdMUn8kWeqHSl28IRCE+X/sE64hLnGjF7GsPGuN91lRXIe6dscEx69NFF qAUNeGNu//gvCUiZrCKQ4663YbraK10qE1bJAPzuY+AOuGZcpM6KRrt702ACXF1DQ96P zZtN1hxF4bRWJ1xMApocFT4Ji14TiE7WqdzGeEpvOiMCT4DE0E2W2sr+Xxwiyk1BOLOs oL2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=PFutZKB789lgbJIHVExt/58X9sr6xXt+vyymG8I337o=; b=0shAKVYqnyrq19GkK7NLsRuSSQyFRStGdEBMwLmA2sSnj8lEex/gDq+HV4xP7rhz/h o5ORM26QcywXhTDbjPuz5wslLKeCC2sRyGKgA6/EHXd4POQzvVfrqOJ9oYGrxQvNTxai IfyMniPSUHrZup/xwwu7K8dYPfREJt28mym3lZLHkppir6Yg5WZ3fjXUdI2cck6zfX5v UGIcDkr/VDtZLMhdE6+kkzp+NqpiQsosHzUI8QO85VJrgoZ8lLru30P2R45RCQNEWg1P VL3RaZlJ/5JwJjsnRGkPxS/VgJ+x5r+Blpv19xr8krozc85BjoBPYm7h2xhI5m9a+hlF l23A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j186-20020a638bc3000000b0051377671b30si10734050pge.900.2023.04.18.06.21.09; Tue, 18 Apr 2023 06:21:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232358AbjDRNIB (ORCPT <rfc822;leviz.kernel.dev@gmail.com> + 99 others); Tue, 18 Apr 2023 09:08:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232203AbjDRNHx (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 18 Apr 2023 09:07:53 -0400 Received: from exchange.fintech.ru (e10edge.fintech.ru [195.54.195.159]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F63115A25; Tue, 18 Apr 2023 06:07:50 -0700 (PDT) Received: from Ex16-01.fintech.ru (10.0.10.18) by exchange.fintech.ru (195.54.195.159) with Microsoft SMTP Server (TLS) id 14.3.498.0; Tue, 18 Apr 2023 16:07:47 +0300 Received: from localhost (10.0.253.138) by Ex16-01.fintech.ru (10.0.10.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Tue, 18 Apr 2023 16:07:47 +0300 From: Nikita Zhandarovich <n.zhandarovich@fintech.ru> To: "Rafael J. Wysocki" <rafael@kernel.org> CC: Nikita Zhandarovich <n.zhandarovich@fintech.ru>, Kevin Hilman <khilman@kernel.org>, Ulf Hansson <ulf.hansson@linaro.org>, Len Brown <len.brown@intel.com>, Pavel Machek <pavel@ucw.cz>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, <linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <lvc-project@linuxtesting.org> Subject: [PATCH] PM: domains: fix integer overflow issues in genpd_parse_state() Date: Tue, 18 Apr 2023 06:07:43 -0700 Message-ID: <20230418130743.67024-1-n.zhandarovich@fintech.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.0.253.138] X-ClientProxiedBy: Ex16-02.fintech.ru (10.0.10.19) To Ex16-01.fintech.ru (10.0.10.18) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763520370810574740?= X-GMAIL-MSGID: =?utf-8?q?1763520370810574740?= |
Series |
PM: domains: fix integer overflow issues in genpd_parse_state()
|
|
Commit Message
Nikita Zhandarovich
April 18, 2023, 1:07 p.m. UTC
Currently, while calculating residency and latency values, right
operands may overflow if resulting values are big enough.
To prevent this, albeit unlikely case, play it safe and convert
right operands to left ones' type s64.
Found by Linux Verification Center (linuxtesting.org) with static
analysis tool SVACE.
Fixes: 30f604283e05 ("PM / Domains: Allow domain power states to be read from DT")
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
---
drivers/base/power/domain.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Comments
On Tue, 18 Apr 2023 at 15:07, Nikita Zhandarovich <n.zhandarovich@fintech.ru> wrote: > > Currently, while calculating residency and latency values, right > operands may overflow if resulting values are big enough. > > To prevent this, albeit unlikely case, play it safe and convert > right operands to left ones' type s64. > > Found by Linux Verification Center (linuxtesting.org) with static > analysis tool SVACE. > > Fixes: 30f604283e05 ("PM / Domains: Allow domain power states to be read from DT") > Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru> Acked-by: Ulf Hansson <ulf.hansson@linaro.org> Kind regards Uffe > --- > drivers/base/power/domain.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c > index 32084e38b73d..51b9d4eaab5e 100644 > --- a/drivers/base/power/domain.c > +++ b/drivers/base/power/domain.c > @@ -2939,10 +2939,10 @@ static int genpd_parse_state(struct genpd_power_state *genpd_state, > > err = of_property_read_u32(state_node, "min-residency-us", &residency); > if (!err) > - genpd_state->residency_ns = 1000 * residency; > + genpd_state->residency_ns = 1000LL * residency; > > - genpd_state->power_on_latency_ns = 1000 * exit_latency; > - genpd_state->power_off_latency_ns = 1000 * entry_latency; > + genpd_state->power_on_latency_ns = 1000LL * exit_latency; > + genpd_state->power_off_latency_ns = 1000LL * entry_latency; > genpd_state->fwnode = &state_node->fwnode; > > return 0; > -- > 2.25.1 >
On Mon, May 8, 2023 at 12:37 PM Ulf Hansson <ulf.hansson@linaro.org> wrote: > > On Tue, 18 Apr 2023 at 15:07, Nikita Zhandarovich > <n.zhandarovich@fintech.ru> wrote: > > > > Currently, while calculating residency and latency values, right > > operands may overflow if resulting values are big enough. > > > > To prevent this, albeit unlikely case, play it safe and convert > > right operands to left ones' type s64. > > > > Found by Linux Verification Center (linuxtesting.org) with static > > analysis tool SVACE. > > > > Fixes: 30f604283e05 ("PM / Domains: Allow domain power states to be read from DT") > > Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru> > > Acked-by: Ulf Hansson <ulf.hansson@linaro.org> Applied as 6.5 material, thanks! And sorry for the delay.
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 32084e38b73d..51b9d4eaab5e 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2939,10 +2939,10 @@ static int genpd_parse_state(struct genpd_power_state *genpd_state, err = of_property_read_u32(state_node, "min-residency-us", &residency); if (!err) - genpd_state->residency_ns = 1000 * residency; + genpd_state->residency_ns = 1000LL * residency; - genpd_state->power_on_latency_ns = 1000 * exit_latency; - genpd_state->power_off_latency_ns = 1000 * entry_latency; + genpd_state->power_on_latency_ns = 1000LL * exit_latency; + genpd_state->power_off_latency_ns = 1000LL * entry_latency; genpd_state->fwnode = &state_node->fwnode; return 0;