From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.2 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F30AC433B4 for ; Fri, 16 Apr 2021 01:07:01 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 305266102A for ; Fri, 16 Apr 2021 01:07:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 305266102A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=JJaaUyC61luCzyu6f2OjxgFkXfRqJUHMvH1QN+M6Ubo=; b=UKoDWy3TxcWvMBpp9sGX+tLHu kZ8zGCY0h2c+xcPP7fvEjl4RvctHZRzpvLSoeAk4S/ajde9fQHanMcEofj1hl3Pa3Fkh+l3xfLDcA KWlHjzj4U3tndlWVVPyeJDGd9bvlPywaOAScPtfmriHPefg1CAnYx4jPHzXehdGgmk61T69Ft0a94 +hQNcka+DWJPhz83w2DkCVJyWzoaYa9U8YzLiwCBoZCHg8y5HtXSggX32hHJ/LllQCXxonvHfBKij FIwnuVWHVfODvSudukXOqNncg+a5PdGh5DxeOEM5KrTCgwV8/jCFdX7t+m2AJaeLpZ5o5iH3CSppi uT57PiPNQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lXCut-000KfJ-99; Fri, 16 Apr 2021 01:05:04 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lXCum-000KeE-I7 for linux-arm-kernel@desiato.infradead.org; Fri, 16 Apr 2021 01:04:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=zW+2RjEmQ33ClxtXsyeF3sXRy7GheA02ksCqVa3Oi5o=; b=nj8Hk634UI5tagsuleOEgPT3ku 5HniEVbLtdbSMiEIpjEdeVnCLV3naJp0NO9TA6J71qp4AKKKXncMAUS2oG3srN1E7L4STcpW1w6yK R8LR0cxh/ML/kN60eiX+pvRhvEsnmJ8ZNvBI39mfbSATVcPz6LZi2lWGDQzc/zdVxR3oE1L+WrpeM gF25p6EQYw3SEtUNqFis2RutN/t2YQrGA1GHCDRosxuNYE69xC8wxufC3PcWaw16zIa83Ip0UQKT0 FBo67q+c40bOOdG2Rbyi5OPTFHZcnExz8L88LKHJPS4zrjFBD+DiYLAJW69nM2+4s/cWWLOZtUCgk h89+yqFQ==; Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lXCuj-0090uQ-57 for linux-arm-kernel@lists.infradead.org; Fri, 16 Apr 2021 01:04:54 +0000 Received: by mail-pl1-x62e.google.com with SMTP id w8so10743546plg.9 for ; Thu, 15 Apr 2021 18:04:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=zW+2RjEmQ33ClxtXsyeF3sXRy7GheA02ksCqVa3Oi5o=; b=Vx/hKylt6Xe45ZhvpJZhO7s4wZ6BizS8QMcmoPZgyPUMfejuvrZenHFGHS60Bn8mqL bh7NqX1iD9BooWbcvRGv404xaB3c36HSMWkaarH9r+IqZyzJH+0Ukzu2zfwvu9WXOWha TxZQUIchEDefcvolaxckuC+fyn0QatNkk1nSu2NJFyt8d1+t2AvmpN3Ymcz1cMVn/sLu iT/vZpzUyJYUJ5Q0oAX77irBvR2bpX8SD34G/L2iwmZsm/+U9PS2oIrUoozIThGl5cug zZYWdip2Pc6vD42Jbn5tjHKut/J/q1qrUBW4mC8kZ8DQh+pQ8S/hiS9mIO1h3C3Ntuxh aIeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=zW+2RjEmQ33ClxtXsyeF3sXRy7GheA02ksCqVa3Oi5o=; b=iptoYVtEdtTZ0fJZ7ybiLP2g4PcgjqlWjA/GRnZ9t8SZwfBIsGtYEd3fHF70Kg+MGB r+CkVu/0nCbddhtEI5k8Na6oxeJLY03NkULUKzR8H4Riq5CSr++Z7QU1VqQnYiT6kUsZ TPG10Hu3iO/LAO9izkrMNpG0EIuFkr58Ol5/EpMJmyVGlAixqxSwkGxlTNdTd2vILuLi wSMY+Efi6CjApLdExOAYPzKKzBee/OausYEkvX5I0Dz+4XGerI/f1dhgcVd5h5/Kkdo7 ObQYJffGBvVyOIXk92bkvYXusjWf6v+KmGpPTkzx6mB34PHxkmi+EpJ9z9sg4Uh2XhjU Z8fA== X-Gm-Message-State: AOAM533MRMhI7Y4s7UyXaqva/bL5FLvUbYXjmp06yFnk1DuO7iGQP8Cm lRLcdbT4dGf5i6P3ZQScfkI= X-Google-Smtp-Source: ABdhPJz+X7KlZMN9/YSJKDyllmXtRhLjlKGfoKGGlLj+rhTaMtcvGTNXrb0BVe2L4xoHvAe9DXhrAg== X-Received: by 2002:a17:902:c3d4:b029:eb:4d0c:7d1f with SMTP id j20-20020a170902c3d4b02900eb4d0c7d1fmr6952420plj.57.1618535092361; Thu, 15 Apr 2021 18:04:52 -0700 (PDT) Received: from taoren-ubuntu-R90MNF91 (c-73-252-146-110.hsd1.ca.comcast.net. [73.252.146.110]) by smtp.gmail.com with ESMTPSA id c125sm3023843pfa.74.2021.04.15.18.04.51 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 15 Apr 2021 18:04:52 -0700 (PDT) Date: Thu, 15 Apr 2021 18:04:45 -0700 From: Tao Ren To: Guenter Roeck Cc: Wim Van Sebroeck , Joel Stanley , Andrew Jeffery , linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, Tao Ren , Amithash Prasad Subject: Re: [PATCH] watchdog: aspeed: fix integer overflow in set_timeout handler Message-ID: <20210416010444.GA17388@taoren-ubuntu-R90MNF91> References: <20210416001208.16788-1-rentao.bupt@gmail.com> <469ac948-d65b-471f-102f-726466c19c5c@roeck-us.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <469ac948-d65b-471f-102f-726466c19c5c@roeck-us.net> User-Agent: Mutt/1.9.4 (2018-02-28) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210415_180453_217601_AC1700AA X-CRM114-Status: GOOD ( 22.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Apr 15, 2021 at 05:50:32PM -0700, Guenter Roeck wrote: > On 4/15/21 5:12 PM, rentao.bupt@gmail.com wrote: > > From: Tao Ren > > > > Fix the time comparison (timeout vs. max_hw_heartbeat_ms) in set_timeout > > handler to avoid potential integer overflow when the supplied timeout is > > greater than aspeed's maximum allowed timeout (4294 seconds). > > > > Fixes: efa859f7d786 ("watchdog: Add Aspeed watchdog driver") > > Reported-by: Amithash Prasad > > Signed-off-by: Tao Ren > > --- > > drivers/watchdog/aspeed_wdt.c | 5 ++--- > > 1 file changed, 2 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/watchdog/aspeed_wdt.c b/drivers/watchdog/aspeed_wdt.c > > index 7e00960651fa..9f77272dc906 100644 > > --- a/drivers/watchdog/aspeed_wdt.c > > +++ b/drivers/watchdog/aspeed_wdt.c > > @@ -145,9 +145,8 @@ static int aspeed_wdt_set_timeout(struct watchdog_device *wdd, > > struct aspeed_wdt *wdt = to_aspeed_wdt(wdd); > > u32 actual; > > > > - wdd->timeout = timeout; > > - > > - actual = min(timeout, wdd->max_hw_heartbeat_ms * 1000); > > + actual = min(timeout, wdd->max_hw_heartbeat_ms / 1000); > > + wdd->timeout = actual; > > > > writel(actual * WDT_RATE_1MHZ, wdt->base + WDT_RELOAD_VALUE); > > writel(WDT_RESTART_MAGIC, wdt->base + WDT_RESTART); > > > > If the provided timeout is larger than the supported hardware timeout, > the watchdog core will ping the hardware on behalf of userspace. > The above code would defeat that mechanism for no good reason. > > NACK. > > Guenter Thanks Guenter for Joel for the quick review! The integer overflow happens at (actual * WDT_RATE_1MHZ). For example, if a user tries to set timeout to 4295 seconds, then the hardware would be programmed to timeout after about 32 milliseconds. I would say this behavior is not expected? Cheers, Tao _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel