Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp626481pxx; Mon, 26 Oct 2020 17:20:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzY2SuqFPJfFGwfxw8XtMH4K6ZyuvIAQ0GFUcF4Ntu4OtbPo2Vi4R4OeJoXVQd/HoH4tz3L X-Received: by 2002:a17:906:3cc:: with SMTP id c12mr18006841eja.210.1603758018358; Mon, 26 Oct 2020 17:20:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603758018; cv=none; d=google.com; s=arc-20160816; b=RmV1T5YugARGBvtFq3CRcmEEebHFs1H/kyzPdYTreH6igyJ9NLPPdTQefevUwS9sZM CJEj4QIo8lmYsAqtBFsKRyNi5ERQHOy5R1YR9nvg10lP2SNitbJLDypOgt5DKvgIbG0B Ftzds4rIWI60iMol9FIJggumk0XlIv/NGv2MDgaSOM45M6Eu82DHbkRgYwFQK7OHK/cP Jf6PH4HVz4mCIugtFlOJ20WavxIHYZPNqJQgVns4dddkuDjRXHCZw3E0BY0Flc63lSkv hhGsCBWOf/WVEfV14RH6bXjC8HRrJ0wJAuuxCoVA1wJbZFy9nonrE+U4DS1n5D7rjYH+ SK9A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6q6kU8QEYmWOpw2NAsNGZ5S9qKfw2g5WzaUkWzH9vFc=; b=pWaJ6izS29cbvhZaeGJpjTvi56To4+Fjho99y25YwtvzsjY7QwNPGdmMkgYPUWmX33 Wt0N6ZJQ0ESIiFYaFNBx9wfZYl86yi+iJEBTEBU75R8ZTQQ+mGGXvlJPzztCzkgUT4bS 3kH9V7likNWSYKLcFoPunBV+Mu8mbKOhxVSxo8nH1wJKolbKXQYSaNqUJ5NGVwDvQ5Km tpDvY1NmD1tL7y/2yuC5+m2xzB8sNg5G5KUoM9mU4GolucR0jZ07brHLxABNqOilC+qq N5bq1D0khddHob//0qOAoaqvc4h1kPyZAZLTmLeMHC+nF/fXFbcpZ+3As0tohgU86xIx 7OMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iYO9YCL9; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b8si8230605ejp.403.2020.10.26.17.19.56; Mon, 26 Oct 2020 17:20:18 -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=@kernel.org header.s=default header.b=iYO9YCL9; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437275AbgJ0AAw (ORCPT + 99 others); Mon, 26 Oct 2020 20:00:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:36548 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436492AbgJZX4e (ORCPT ); Mon, 26 Oct 2020 19:56:34 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0C0C920770; Mon, 26 Oct 2020 23:56:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603756593; bh=rF3Bs3s+nWvLHxRMvK0zTH0TD+YotFbPgtNExKl6fUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iYO9YCL9Bb2EgEM3ouoOwqSqwIp6qoHsbY9BcENCEnyjXNSuvMEuRj408HFqrLThY /qvky6ZHcMRXC1osw6LMC9aiR8iwahsQYTD3Ppn2EOg5RZU8KJ97CJKOGbWYxYZccv Z4yXzgzHHrPudIqE8vZZqgpoa7laztmmBd8i7RNY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Madhuparna Bhowmik , Guenter Roeck , Florian Fainelli , Wim Van Sebroeck , Sasha Levin , linux-watchdog@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 64/80] drivers: watchdog: rdc321x_wdt: Fix race condition bugs Date: Mon, 26 Oct 2020 19:55:00 -0400 Message-Id: <20201026235516.1025100-64-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201026235516.1025100-1-sashal@kernel.org> References: <20201026235516.1025100-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 2e608ae6cbc78..e0efbc5831986 100644 --- a/drivers/watchdog/rdc321x_wdt.c +++ b/drivers/watchdog/rdc321x_wdt.c @@ -230,6 +230,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) { @@ -244,14 +246,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); timer_setup(&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.25.1