Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1263234pxb; Thu, 15 Apr 2021 19:20:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnrDMIpYpLHaHvO7NvKO4dR6JjzBGb9udL7lwXl++bT/gFdw8s1FWCo96E0F7rIdJYFFb9 X-Received: by 2002:a17:906:a1c5:: with SMTP id bx5mr6560441ejb.166.1618539651175; Thu, 15 Apr 2021 19:20:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618539651; cv=none; d=google.com; s=arc-20160816; b=ggW8bEOUdSRRmglORgY0UYO0fHxPsAv64XTJYhof9hdetmJuFP40SwEYlQgzmiOQaD iriNd4ZWMAZWmILfVo7jFxbj55uf6h1yZRO9A91JiAoLFUdT3y9oiH09ZYAooc2qRcx7 5PCpFbLREVBn6B7KTqoMUBlQITPJGfAU3LO2hr9Okaqmy3eD3/5YkIslf5xiLeRYPkFh XEc6DtYQj1ygjrV5FN9ZVU45qiUNWuwQysUIfuTP7jpCvJjOuse6VrHvpNIEVtjmWDbf MqNWFoSB4+CNu7tDar1xZ/yWKL+T2dORFx0CZ+wEpqIxf6SdCSqW4DafPW54HKC2dXBs S+ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=eLTCOMBoG9G5S0rXZgVkqicXPZkU4FpglORZGdEuM7k=; b=f/APC+LIvDZsVyEizU7I6Rr6ByJbVv4rcKi4jwsaJ6Kb3s1yveFOsO8QV0ReR+gT37 ZIF1jIj+7FySDgl0RQBaYGopMWZu/yPKIurPuqT2ZV7qUHIK821q4SGix2kVRF+/vyJL 3iweQ1RRzFdsDGcLyZQjvLq+Pnab7Q6BWsr0YgcwuglSNA/DRqEDnspGKFPcLjPWfxrW vUT6IeVAxGz/LcQVnjXSfmni53D0XK0dcgB8oW6Qd3omxSEBEt8qn6jMv93/aaaOYLlS bpKLLnburzItpQWN7P0SJS/5LxD35CreCzHsUYUmnulWDvo9LJ25wAuYe+Jk+7jg8r8B j1yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@jms.id.au header.s=google header.b="mVMp7KJ/"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x2si3385067ejy.213.2021.04.15.19.20.26; Thu, 15 Apr 2021 19:20:51 -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=@jms.id.au header.s=google header.b="mVMp7KJ/"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235809AbhDPAgp (ORCPT + 99 others); Thu, 15 Apr 2021 20:36:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234865AbhDPAgo (ORCPT ); Thu, 15 Apr 2021 20:36:44 -0400 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1D64C061574; Thu, 15 Apr 2021 17:36:19 -0700 (PDT) Received: by mail-qv1-xf31.google.com with SMTP id ef17so7012713qvb.0; Thu, 15 Apr 2021 17:36:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jms.id.au; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eLTCOMBoG9G5S0rXZgVkqicXPZkU4FpglORZGdEuM7k=; b=mVMp7KJ/dQ9aRRQKge8lo8tx7/WB11OnQJJ0EROpsbIrQ1fl21AspBNhSxGRNZesOz buZOd/sbSIniCAoeR6+vwTT99bzq8lq/6pGO0u83vpRBw+D1KcRT+BMR5JYMy3z04uoE C3X6LTONu7HGmhAclPAH5CikO1GdxAK9OD5OU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eLTCOMBoG9G5S0rXZgVkqicXPZkU4FpglORZGdEuM7k=; b=C0mj2kHI8VMttFQpAAGuqjXABiymXGb5a5cpWumjhZX+O/52yNO0Hy+GnQCAKJink8 2Y7chJg4Hmk7Mi4b0W2qXeJx26ujLhZqQVZ1XMardigZVUmrKVuefbwEyhMvt7UiblS0 r4jyvCQgooQqjvqf9jEQqTCsmk0UiFg2d8hK9hyShiviRruhyru8D7GZgiDFM1+IeijL 8b45JH5Ok/wtWcOuR2XRAyFhPxs7cuFkLwvEEhTt9wO3yGKtxIz+P9iRiBKqmg2rX6nl 8c0mIADmjlZlgVse5f7aChYmUTo1IOmhc/i+D14CNqHtl7aGzNg7JqdnY5cUqaMPiBkm /vmg== X-Gm-Message-State: AOAM532dim/4hzL122vlWT8h6C6C0T7iKfshgofNZ5EovgjRKkIle+uL 3j4Um6kbPiAR712GHR1opnwxSQaQJdiFpOy4zdQ= X-Received: by 2002:a0c:e950:: with SMTP id n16mr5882756qvo.43.1618533378768; Thu, 15 Apr 2021 17:36:18 -0700 (PDT) MIME-Version: 1.0 References: <20210416001208.16788-1-rentao.bupt@gmail.com> In-Reply-To: <20210416001208.16788-1-rentao.bupt@gmail.com> From: Joel Stanley Date: Fri, 16 Apr 2021 00:36:06 +0000 Message-ID: Subject: Re: [PATCH] watchdog: aspeed: fix integer overflow in set_timeout handler To: Tao Ren Cc: Wim Van Sebroeck , Guenter Roeck , Andrew Jeffery , LINUXWATCHDOG , Linux ARM , linux-aspeed , Linux Kernel Mailing List , OpenBMC Maillist , Tao Ren , Amithash Prasad Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 16 Apr 2021 at 00:12, 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); The unit of timeout is seconds. You're comparing to ms/1000, which are microseconds. I think the existing test is correct? As far as integer overflow is concerned, max_hw_heartbeat_ms is an unsigned int. We set it to 4294967, which *1000 = 0xfffffed8. This should be fine. > + wdd->timeout = actual; This might be the correct thing to do though. I'll defer to the watchdog maintainers for their input. Cheers, Joel > > writel(actual * WDT_RATE_1MHZ, wdt->base + WDT_RELOAD_VALUE); > writel(WDT_RESTART_MAGIC, wdt->base + WDT_RESTART); > -- > 2.17.1 >