From patchwork Fri Apr 16 00:12:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Ren X-Patchwork-Id: 12206405 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=-13.7 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_GIT 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 A9B16C433B4 for ; Fri, 16 Apr 2021 00:14:12 +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 31AEC610E6 for ; Fri, 16 Apr 2021 00:14:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 31AEC610E6 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:MIME-Version:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-Id:Date:Subject:Cc:To:From:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=ExT49v2SLlp1fyNo0wlwWIzAKC1OBo7/SfKR0nT33zE=; b=ZODKKei9ws1rPcIsDWeDz/z5Ao 7p6k7P7scsKr7ULxWFU0oiavNCJDRQBpvw2Zqf86AJcrpRF4Y0R37x1bJ4R/Xl3nFjPC3G5VHA0x7 Vnjc/01m7ro6J/PQ5gWsh0ylzZ33L/BK7JPaW3+Nj3FCbrqrELtTdRWPDoOcdWBnGcm/bPNlzlYAZ Bh71g6KTMaOJGGC2o3vomVQL/uPhfkbN9di57mv3rkJ/p1ouF6HqdlQx3h6S3MSuebPdzd+o4C5AD Sg30aqgCHHx/6RJkKMOBnyXxPRYHovXWcGLvc5VFWun5qxXCZy5AquqFk8awFaLGgWwokDKYVb3U8 jo458fqQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lXC65-000BnM-2L; Fri, 16 Apr 2021 00:12:33 +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 1lXC5u-000BmT-TS for linux-arm-kernel@desiato.infradead.org; Fri, 16 Apr 2021 00:12:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To:References; bh=uOD33pWWzSYPL/0r0lD9kRWmPd2Gntdg/sWshNtZopQ=; b=0SMcIhmiQPjibhMT842EcQPt7e a+8LPZMSxnu53UUiRJsPIx/3/kM+VECgJn9I5OEuJZ+RLsvOQesNrpIlSMbx8S2cQ4AKY8tMJO4ic GuaYCGlNIxAcD3vNfij0KQnoALpH3aSAcgTKrs/bVH/0oB4GG4am+SUnpTIGZOqhPvwobCCWcgE/I UL58JvWqg4A5jgqHg8jMC1APxrF9G1FZtGph63OmiMvR3MFd7E1vra2lOX8L63HTTqzrMRY+e0BtH IRvkW0nwBpXZvgD/wESbFg3FF3PoRB0+o07Xbf2hN21z+4JzbBvU1PeFjpPxIfsgd0m2c/9AJJUjX PwY0JP1g==; Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lXC5s-008zju-IF for linux-arm-kernel@lists.infradead.org; Fri, 16 Apr 2021 00:12:21 +0000 Received: by mail-pj1-x102a.google.com with SMTP id u11so9324330pjr.0 for ; Thu, 15 Apr 2021 17:12:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=uOD33pWWzSYPL/0r0lD9kRWmPd2Gntdg/sWshNtZopQ=; b=s1H68uyiA8xZr1m0pvhQEKXukTF7w0kdfEjKzTB7M0AslrsTUFnckgp6j5PjoMi0/V A8dClVXat85tcE1+h1Ph0Hw6PXrknoaUDXPzKC61pdls3wN9f0zxSent7iHTnrdPKFcn Q84fWDl6P8WNvpLENrboT274s5+HBcrh+Nbm8gkmR8QRXLo5Z8uokTjva9/txgahX9FT LjGeOYsbxQ4dgHZ81c6ejSDhWkGp6dJhFg9KYB37298PzoiDSVEWKfZf3qcflyZtcZZF mTr5EaoKarVxSTmYVAuxQXwdw44T/B1WdhxrF8ATzLdPusShyX3JHN4rB5eU2VsLUNIF tPmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=uOD33pWWzSYPL/0r0lD9kRWmPd2Gntdg/sWshNtZopQ=; b=Hvlk4MGLhmhJ+7uRu4dAKbIeNFlxfUX3K9WFXNifZer0xIe7FqFKxw0m+EyMCO5KUB LNfRtoM7kvDZf7FvGfLb5WCdrSgl7LCBUK7NTuEXeeQb78GcDt0O5NOZZw9yXV45VvwG MdWI8rZmtTMnT0YQp+Pxfyhkw848Yr/pA5uECnsHiV6rliMrSt64K+29vHZAkqMk/Rqz Zk5kF+Hj76VWS9KylUvTxZzpjlb7kTJxBrSH/9sfNZxaUV4lPF8aqeBjzYP2NFSfBhU7 Lg7YXvfkfH611ksouJBZJ5wfrGBOKLlfFGu9z21u04Rnf1U5vBU8YAxX1HbF7T2/4fLy VgxQ== X-Gm-Message-State: AOAM531y5dXg1+YXozERHWkr3k06Vvf8XD6GL0qzTHONg75x42XWyYeZ HgKH0LjcEL3oSQAAsqogqKI= X-Google-Smtp-Source: ABdhPJziviff8FmqFA3GpFk3TKqox3jUoOSSMevoRcrU2y1YmgbUbciZYiBwxLlCoVyAGMxBE42qVw== X-Received: by 2002:a17:90a:352:: with SMTP id 18mr6329781pjf.223.1618531939116; Thu, 15 Apr 2021 17:12:19 -0700 (PDT) Received: from taoren-ubuntu-R90MNF91.thefacebook.com (c-73-252-146-110.hsd1.ca.comcast.net. [73.252.146.110]) by smtp.gmail.com with ESMTPSA id p10sm3312611pgn.85.2021.04.15.17.12.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Apr 2021 17:12:18 -0700 (PDT) From: rentao.bupt@gmail.com To: Wim Van Sebroeck , Guenter Roeck , 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 Cc: Tao Ren Subject: [PATCH] watchdog: aspeed: fix integer overflow in set_timeout handler Date: Thu, 15 Apr 2021 17:12:08 -0700 Message-Id: <20210416001208.16788-1-rentao.bupt@gmail.com> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210415_171220_622564_176C3EA8 X-CRM114-Status: GOOD ( 10.23 ) 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: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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);