Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9422070pxu; Mon, 28 Dec 2020 16:00:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJz2Jhb1Hty2Zd0G9giP+YHYjTLBhTnnSzy1mfCw1krRS1zbli9BkXv8RPs7THBDi7aJEhfu X-Received: by 2002:a17:906:3d62:: with SMTP id r2mr44649476ejf.295.1609200031412; Mon, 28 Dec 2020 16:00:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609200031; cv=none; d=google.com; s=arc-20160816; b=uFcnncwmhCjkTTjxWR5+V3fCXQqcbwmxTionHY7vrnkorcJ8Bmgq+1307x1YT53OZp OPGtjhscQDhOKLr4EM4QfFG2h0kO4dAX3D7Ao2oIcOrKFTTB/Fx04QDaX6pAyLgWHPST HR2oN48rBzh5KTnFf5OLbm6/dc1rXmtlVnN29stH5jyqeZQYGC0W4WlmVMMgYz7QXezY Y3cut0RFHOGzHerxpR8g0cyxFcHS7cgOwZqypiKmmgCUHTR1nEbsZMs90o3Qp8hNy7h0 6jcs/Mfm8OlODtrw0lKmM1oltbxt2KQGMdEoRK/ts/MxbRwBcJmZgSIXIUFRmS6xHvGP opUg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2PbHsOOEv/QV2hAtOrkkRWI1CXd/XBvBYshV0FC7W40=; b=Je4znALGDmeW56tqpxh2Kmm/9U3P7IGUI4ZPy2mTKdQ7TaokeCug8zZJU+93eoMgbj PaGDSGHeAOZw5+kpU1UVgr9xE5rMUlxE287t4wEq8PsdxwwvhDlTMnu4+pO8y9951dOh syE49GKpbm4rK9OlRNudE44RaKqHQMmlz8kTwGIBuyitjOcndi+VLKPPX4ktKZRISdJy FW9WHRd6rPEELZm+4zIv3wNLliSdTO3nsCagflj+QFk/OIZkChlTVhSLJZjKmxS05Ax3 fVGINu345O54cTAZUAIuI8lcWCFUU0RhA+YMI8YzfjyhnWYSnzdcxmAXUUKPExJZzSlz /NVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BrbL3+av; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c24si21296216edj.459.2020.12.28.16.00.09; Mon, 28 Dec 2020 16:00:31 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=BrbL3+av; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2504832AbgL1Ovk (ORCPT + 99 others); Mon, 28 Dec 2020 09:51:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:54422 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2502095AbgL1OTd (ORCPT ); Mon, 28 Dec 2020 09:19:33 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A898121D94; Mon, 28 Dec 2020 14:19:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165158; bh=ixOEE7phzSi3SLivtlBc9MuGcz4AkwIHzh0zfDAMKDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BrbL3+avqfy5YT2+2JEY6tuIxmF3A44NtiXg+IzgrnskNOj9NeZaQXBKx9FPq3Lwt 4gadxJOBupHlb59uidANhEHc/KsNRA2iNqoy3pfjP7dDI3xj3Ol/F+zNEFcW/AZXz1 gXr9xAIqiSsbbOJ0vYmK09V/YxK2K9b6T/3x4kXs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wang Wensheng , Guenter Roeck , Wim Van Sebroeck , Sasha Levin Subject: [PATCH 5.10 432/717] watchdog: Fix potential dereferencing of null pointer Date: Mon, 28 Dec 2020 13:47:10 +0100 Message-Id: <20201228125041.668154203@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wang Wensheng [ Upstream commit 6f733cb2e7db38f8141b14740bcde577844a03b7 ] A reboot notifier, which stops the WDT by calling the stop hook without any check, would be registered when we set WDOG_STOP_ON_REBOOT flag. Howerer we allow the WDT driver to omit the stop hook since commit "d0684c8a93549" ("watchdog: Make stop function optional") and provide a module parameter for user that controls the WDOG_STOP_ON_REBOOT flag in commit 9232c80659e94 ("watchdog: Add stop_on_reboot parameter to control reboot policy"). Together that commits make user potential to insert a watchdog driver that don't provide a stop hook but with the stop_on_reboot parameter set, then dereferencing of null pointer occurs on system reboot. Check the stop hook before registering the reboot notifier to fix the issue. Fixes: d0684c8a9354 ("watchdog: Make stop function optional") Signed-off-by: Wang Wensheng Reviewed-by: Guenter Roeck Link: https://lore.kernel.org/r/20201109130512.28121-1-wangwensheng4@huawei.com Signed-off-by: Guenter Roeck Signed-off-by: Wim Van Sebroeck Signed-off-by: Sasha Levin --- drivers/watchdog/watchdog_core.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c index 4238447578128..0e9a99559609c 100644 --- a/drivers/watchdog/watchdog_core.c +++ b/drivers/watchdog/watchdog_core.c @@ -267,15 +267,19 @@ static int __watchdog_register_device(struct watchdog_device *wdd) } if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) { - wdd->reboot_nb.notifier_call = watchdog_reboot_notifier; - - ret = register_reboot_notifier(&wdd->reboot_nb); - if (ret) { - pr_err("watchdog%d: Cannot register reboot notifier (%d)\n", - wdd->id, ret); - watchdog_dev_unregister(wdd); - ida_simple_remove(&watchdog_ida, id); - return ret; + if (!wdd->ops->stop) + pr_warn("watchdog%d: stop_on_reboot not supported\n", wdd->id); + else { + wdd->reboot_nb.notifier_call = watchdog_reboot_notifier; + + ret = register_reboot_notifier(&wdd->reboot_nb); + if (ret) { + pr_err("watchdog%d: Cannot register reboot notifier (%d)\n", + wdd->id, ret); + watchdog_dev_unregister(wdd); + ida_simple_remove(&watchdog_ida, id); + return ret; + } } } -- 2.27.0