Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3185833pxb; Mon, 9 Nov 2020 05:07:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwT2EEDAdheiGHAiBLd6cYt43RT3nYhdfG7/jPpgKJyYZ5Kk7U6lu8ul1CIZDAT6b3B6ZuL X-Received: by 2002:a17:906:26c2:: with SMTP id u2mr14244373ejc.529.1604927236954; Mon, 09 Nov 2020 05:07:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604927236; cv=none; d=google.com; s=arc-20160816; b=MmlWxRvr+Q4DyOn8uA1HsVbRbWJK087+S+LM6z/43F3A/A3TkKS8NQqUO98DR3WLs+ RIRAqmwguO2JcsY4wBaUkIs0m5IE8Gjl3w5sD5/y7zyHwMu/IRcKawfO/LCpsyhjVm8V XSFabNl/YuV4GKIjoQaLVINfo/p0Kjje87uCT9R5r+SUcoHjVzyTE7WobWlvcAIQvuuy JN4aS3XjEpTLZajozfx1d2FgFVaPbhUS4fupX07jU8JxpnBxZIgsd8zHGmrC5w2k94YH BLz28hfzGPwbvwDDwmG2d8P0rZGDHvrDfgV9EEnpOryYB1o7ZXciVWRFSDQP97xCQ7uS V0Wg== 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=PVLE26BXu1eiLLeFA+DE22QcSSWTBFBhEaYxMbk3Py8=; b=F/pd5j/708jB1kJ70v4O7U8FduDNgU8fe5hzDOvnugsy5+V6yBcANPhfuBF+zaP8D6 GopRPaZ1PIAPPS1ZLVYHnBQ5VD5LAU8/tFIVToU4qOVCLELCRvO+S8eyptDlMg1qR3mV ag8zZES/ctOsD7Qpl18HkqoXgiIbBkYQpma9yxQRLxBepWbg/mG9CitRExKdIVeVPddt 7DUD50YhKJhymDtAvFqj+at6xUMM7drek+fEpMXdrFFr7XCngnZYWpI4fZZ0PUQqRpvu /yiREs4JNwrx3u0XOPoN5KwIlEdMie9B2s3b8TK7fz9zEMMj4wHRIZ4Ekh0MKxwVHIb7 4f1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lDPsocbD; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f4si7350790eja.252.2020.11.09.05.06.52; Mon, 09 Nov 2020 05:07:16 -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=@kernel.org header.s=default header.b=lDPsocbD; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730699AbgKINDm (ORCPT + 99 others); Mon, 9 Nov 2020 08:03:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:55454 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730563AbgKINB3 (ORCPT ); Mon, 9 Nov 2020 08:01:29 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F1DCB20679; Mon, 9 Nov 2020 13:01:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604926888; bh=T4o0DXs6wtfVp+UjtIlSWtuCUVCA119VN3WbpaeLBak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lDPsocbDrZv+xzVUHgJ+MYHhBYyTr1Xu9e/ts8j647PGtAl1/syH7WNCkpYd0WTGB I78pdG6n/7xVHjKZ+Hfpj6N5DbAuQ4Ofv0Ol8Wmj51oQtVKUYsXGxltclMKTHC0Zo1 dA8MhsZono8rQpVKWUAPDFEOXrAVriKpxBYyQzfw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Madhuparna Bhowmik , Guenter Roeck , Florian Fainelli , Wim Van Sebroeck , Sasha Levin Subject: [PATCH 4.9 038/117] drivers: watchdog: rdc321x_wdt: Fix race condition bugs Date: Mon, 9 Nov 2020 13:54:24 +0100 Message-Id: <20201109125027.460261273@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125025.630721781@linuxfoundation.org> References: <20201109125025.630721781@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: Madhuparna Bhowmik [ Upstream commit 4b2e7f99cdd314263c9d172bc17193b8b6bba463 ] In rdc321x_wdt_probe(), rdc321x_wdt_device.queue is initialized after misc_register(), hence if ioctl is called before its initialization which can call rdc321x_wdt_start() function, it will see an uninitialized value of rdc321x_wdt_device.queue, hence initialize it before misc_register(). Also, rdc321x_wdt_device.default_ticks is accessed in reset() function called from write callback, thus initialize it before misc_register(). Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Madhuparna Bhowmik Reviewed-by: Guenter Roeck Reviewed-by: Florian Fainelli Link: https://lore.kernel.org/r/20200807112902.28764-1-madhuparnabhowmik10@gmail.com Signed-off-by: Guenter Roeck Signed-off-by: Wim Van Sebroeck Signed-off-by: Sasha Levin --- drivers/watchdog/rdc321x_wdt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/watchdog/rdc321x_wdt.c b/drivers/watchdog/rdc321x_wdt.c index 47a8f1b1087d4..4568af9a165be 100644 --- a/drivers/watchdog/rdc321x_wdt.c +++ b/drivers/watchdog/rdc321x_wdt.c @@ -244,6 +244,8 @@ static int rdc321x_wdt_probe(struct platform_device *pdev) rdc321x_wdt_device.sb_pdev = pdata->sb_pdev; rdc321x_wdt_device.base_reg = r->start; + rdc321x_wdt_device.queue = 0; + rdc321x_wdt_device.default_ticks = ticks; err = misc_register(&rdc321x_wdt_misc); if (err < 0) { @@ -258,14 +260,11 @@ static int rdc321x_wdt_probe(struct platform_device *pdev) rdc321x_wdt_device.base_reg, RDC_WDT_RST); init_completion(&rdc321x_wdt_device.stop); - rdc321x_wdt_device.queue = 0; clear_bit(0, &rdc321x_wdt_device.inuse); setup_timer(&rdc321x_wdt_device.timer, rdc321x_wdt_trigger, 0); - rdc321x_wdt_device.default_ticks = ticks; - dev_info(&pdev->dev, "watchdog init success\n"); return 0; -- 2.27.0