Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4809687pxj; Tue, 22 Jun 2021 08:28:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1t40T9DnqqhWoPmme2Js68Z8tLfSNvDhkz31y9M8qXlLCUp4zMl7XFerTowa2JOQA+Lcx X-Received: by 2002:a05:6402:11d3:: with SMTP id j19mr5798264edw.247.1624375737028; Tue, 22 Jun 2021 08:28:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624375737; cv=none; d=google.com; s=arc-20160816; b=Mv4PggoLTpXUiFhU3NSUZiqpLE84ltAbs4PO9sMBl/syG/RwpV7fvH+bOf+GN4xvtk dOpJKxxXC9NVAwGbdPxbuiK+cGtNRV29v+ZAdNTWrwJbt1JQ/VcbdgLpQYiB4dcF0vH9 C0iUVHOCE8490HdOx48BasvYO6PZ8KYzmPhPCxLPxZh3dfTgshlgg0UlUCZjOpT95HTi ACqgiOUacBYMUtwFAC+Fhaciik3lQ5bmbeHbGFChLdUx2kbz5IcWw6wyumfHEs93KVuF tmZBNiwPfRt893MnCJNwP1iiBVXU8oDrlpIZ38hH809AwL9PkweMrVRZ4oTK1FNPZYPn GJFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:user-agent:date:message-id:cc:subject:from:to; bh=uI+ebT4ymxjkTadwBpEAFWc7DwRHHkRRA3nN1v7G274=; b=JU7L0OTyLbhfifqA35pQMQFjLgvRrOkt1gvKeUl7BiSJZdNKDr95rwLe4Lg02x2sMh KZePzl5m9a+9wF5tipGArZPBDe9L6HI1vklJGyzpUH+VaD19Kzhi4D2WqWb2sVO8/1H5 FcenN2KPhFU2qA2+kgkp5sNxuNUI0MFPS6Bh1CiyMqgAmQEn6i1SB9MAoJOJ/+OXZbFf ifU3DfXusekoQUygPsAFaXFAwys2yCP9f76knkNZYNaPeWQihrmULXtKb8XU1RjsQxOM rXFFDIMLGfJoQswGIbuRboeGQDUvkh/YO6RsEl8IOXtKVsk3jzT/GGo8gPRgfO0NZJ/T VQ/w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a26si14352550edr.500.2021.06.22.08.28.33; Tue, 22 Jun 2021 08:28:57 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232279AbhFVP3y (ORCPT + 99 others); Tue, 22 Jun 2021 11:29:54 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:57599 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232241AbhFVP3w (ORCPT ); Tue, 22 Jun 2021 11:29:52 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212]) by youngberry.canonical.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lviJK-00027K-ME; Tue, 22 Jun 2021 15:27:34 +0000 To: Curtis Klein From: Colin Ian King Subject: re: watchdog: Add hrtimer-based pretimeout feature Cc: Wim Van Sebroeck , Guenter Roeck , linux-watchdog@vger.kernel.org, "linux-kernel@vger.kernel.org" Message-ID: <244ef2f1-9dfb-6ac3-3ab8-f8f0cabda93f@canonical.com> Date: Tue, 22 Jun 2021 16:27:34 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Static analysis using Coverity on linux-next has found an issue in function watchdog_cdev_unregister in source drivers/watchdog/watchdog_dev.c with the following commit: commit 7b7d2fdc8c3e3f9fdb3558d674e1eeddc16c7d9e Author: Curtis Klein Date: Wed Feb 3 12:11:30 2021 -0800 watchdog: Add hrtimer-based pretimeout feature The analysis is as follows: 1084 static void (struct watchdog_device *wdd) 1085 { 1086 struct watchdog_core_data *wd_data = wdd->wd_data; 1087 1088 cdev_device_del(&wd_data->cdev, &wd_data->dev); 1. Condition wdd->id == 0, taking true branch. 1089 if (wdd->id == 0) { 1090 misc_deregister(&watchdog_miscdev); 1091 old_wd_data = NULL; 1092 } 1093 2. Condition watchdog_active(wdd), taking true branch. 3. Condition test_bit(4, &wdd->status), taking true branch. 1094 if (watchdog_active(wdd) && 1095 test_bit(WDOG_STOP_ON_UNREGISTER, &wdd->status)) { 1096 watchdog_stop(wdd); 1097 } 1098 1099 mutex_lock(&wd_data->lock); 1100 wd_data->wdd = NULL; 4. assign_zero: Assigning: wdd->wd_data = NULL. 1101 wdd->wd_data = NULL; 1102 mutex_unlock(&wd_data->lock); 1103 1104 hrtimer_cancel(&wd_data->timer); 1105 kthread_cancel_work_sync(&wd_data->work); Explicit null dereferenced (FORWARD_NULL) 5. var_deref_model: Passing wdd to watchdog_hrtimer_pretimeout_stop, which dereferences null wdd->wd_data. 1106 watchdog_hrtimer_pretimeout_stop(wdd); 1107 1108 put_device(&wd_data->dev); 1109 } The call to watchdog_hrtimer_pretimeout_stop dereferences wdd as follows: 41 void watchdog_hrtimer_pretimeout_stop(struct watchdog_device *wdd) 42 { 1. deref_parm_field_in_call: Function hrtimer_cancel dereferences an offset off wdd->wd_data. 43 hrtimer_cancel(&wdd->wd_data->pretimeout_timer); 44 } Since wdd->wd_data is set to NULL on line 1101, the call to watchdog_hrtimer_pretimeout_stop will always trip a null pointer dereference. Shall we just remove that call? Colin