Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1267878pxb; Thu, 15 Apr 2021 19:31:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziVjOwboodyroy/uQBWm37gQ/6Xm6WRE1Z/ZG4Q2sqBehbJz1RlEPVzTv2lyNIi9KAl2XM X-Received: by 2002:aa7:c3c3:: with SMTP id l3mr7588988edr.103.1618540294237; Thu, 15 Apr 2021 19:31:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618540294; cv=none; d=google.com; s=arc-20160816; b=dsTrSYXY0aoage6+Sfr2SHYVtD9kAVy4Gp40iikwNxaCT6o5uGJNWNncSWFpFD+oar mc4Wv9x3wV+nCMnBxgDbysJMDeJTvYq+8KgsUagIjN9hot7wLYajLDNPyd9KZ0FaIifW or6VIxAoZnmM96Ns2utQAykfbHdmpdYcH7YisI1cJ6zVOxmTB8tAV/klfi6m0Bn3KPsk xLJvAKc2g3t4r31P77n743+bRPL/awJ81aSORVFt3IcdUDPPzf23mltJ2Ohal7cskx38 PStQgVjkUBSkjveyqfbXvJBAIMkkGlwexEh9DgwktmPYWyOUIsvZvQRSLwZ0fyGiYu9p gItA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=zW+2RjEmQ33ClxtXsyeF3sXRy7GheA02ksCqVa3Oi5o=; b=h89OgkLt8I/Hu/Zr83WuebcviTx+BF9Emp+EuXyEBwruYkAgQN6wFVHdQNjY+Y43sf 5dXGDzrRU2/1GaH+RjW1YPMOedqzZSf9+sCC14TWbEMD+h4FbI1ljCZg3amH4ZH4fbAz S8Pw6D2/f9++77pYzJiGpsxd7guKlv26rBMm2jJzQ/ZS7grhdZ1G056aLG4U/CbEqpME 4a64U/RK0FqRq+xTZ4tFh+UYWciNaVnyUWcpbbmTc5pvpwe1E13FwEngFtRNIucC1q+D JFf6xzDg6XLiPT6yexYZv8FFyDEJV4Gf0YyswRd0lHysixI8A+jovPzwUhGm4CYSbob6 1qkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Vx/hKylt"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bd14si3702237edb.229.2021.04.15.19.31.08; Thu, 15 Apr 2021 19:31:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Vx/hKylt"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235418AbhDPBFS (ORCPT + 99 others); Thu, 15 Apr 2021 21:05:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234548AbhDPBFS (ORCPT ); Thu, 15 Apr 2021 21:05:18 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DBB4C061574; Thu, 15 Apr 2021 18:04:52 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id t22so12755606ply.1; 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=Brxw3daqSFhiu5AK1RUZNogrDQ1BPLE866EJIg51x2CsepIjLlPp4iNzzpXbyL+nQ0 3S7DhAnAQmZRLbeSJM0C5QYiJ1PuseCRUs0ERfc0AIEhdggaDYtlQzzCuLdOYmUdF+tY a3IV+Xgejz/pJc0Mh7PsexhLceLvjA09XxsYg4Q8IJSBpjYJwZzkqaeokdSaeG9QQRKl rBfnYT5XX3mv7mcr8Jp5ZVmFTXfxv6T0aSqVRl2AF4/vFeyfwKufSfPpEzd4R6lacqm4 dJlkkj4scFXJADtm6LdkpBnAGWWYeJVFO2sN+JilNpJm1rwyPUMMKkYtS5+VqS9pNvJe 4x6w== X-Gm-Message-State: AOAM532hEfO6wEjrGNACoIMWEXfUpNVDzzvNpnZOBD0B50rKFlaMpiVD 6db1dV/Tdx+3Be1VYpyyDLY= 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <469ac948-d65b-471f-102f-726466c19c5c@roeck-us.net> User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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