From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DE5F12F5A7; Tue, 23 Jan 2024 00:16:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705969008; cv=none; b=YshIp6OXHOvLSc4ZWzSlbzhwak4RQ6mb0IPRQWLYpdl6m+C71K7AI9UvjEAEBGAL+X8Fr8ZPBiP+5Cgc707ZYrCFeztiiduzyj2urzcb6RG/tcaAf/kFqsH8AA0PyqH84WKsK3Wqe3/5+k/vuAkx5xDSbAn41Mce/IC2OUlL/4A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705969008; c=relaxed/simple; bh=PS3Nks3T0kECLI2LXnK9sUSvQ0IZIFG/s5YsmJw4Cro=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AOEhrFLia76NhO1Ca+nxKJqPSxwGIZuKpYnemIHgUORGm4lUBxZ3volGWbxKu5JTZlEeRqNv47hfFUmQajOnWMZhFltYv2I6bZLHBTqiNDhBAaojcKICR9RaGB9Fd6ltbAln9V5PR4gyTqN46F2yKM0lr9lPQQCoR51QHVIrIaI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=dl83stve; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="dl83stve" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6737C433F1; Tue, 23 Jan 2024 00:16:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1705969007; bh=PS3Nks3T0kECLI2LXnK9sUSvQ0IZIFG/s5YsmJw4Cro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dl83stvecx9sWGhcTdpYex7bOvJsjgn1WuUiwc3Y/IYmQAmZjdmnClvhPLlljGuFZ nzpIveR0rk9mFl1dJ+Bos6yCidZOzmWuh5rE4r6mtiYf/mGIeaMSQLtLMLP1FakOKZ JT3+kufMKMkQzULFIsKT07+ENLFeZXZhI4l62gJ0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Curtis Klein , Guenter Roeck , Wim Van Sebroeck , Sasha Levin Subject: [PATCH 5.4 132/194] watchdog: set cdev owner before adding Date: Mon, 22 Jan 2024 15:57:42 -0800 Message-ID: <20240122235724.890352577@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122235719.206965081@linuxfoundation.org> References: <20240122235719.206965081@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Curtis Klein [ Upstream commit 38d75297745f04206db9c29bdd75557f0344c7cc ] When the new watchdog character device is registered, it becomes available for opening. This creates a race where userspace may open the device before the character device's owner is set. This results in an imbalance in module_get calls as the cdev_get in cdev_open will not increment the reference count on the watchdog driver module. This causes problems when the watchdog character device is released as the module loader's reference will also be released. This makes it impossible to open the watchdog device later on as it now appears that the module is being unloaded. The open will fail with -ENXIO from chrdev_open. The legacy watchdog device will fail with -EBUSY from the try_module_get in watchdog_open because it's module owner is the watchdog core module so it can still be opened but it will fail to get a refcount on the underlying watchdog device driver. Fixes: 72139dfa2464 ("watchdog: Fix the race between the release of watchdog_core_data and cdev") Signed-off-by: Curtis Klein Reviewed-by: Guenter Roeck Link: https://lore.kernel.org/r/20231205190522.55153-1-curtis.klein@hpe.com Signed-off-by: Guenter Roeck Signed-off-by: Wim Van Sebroeck Signed-off-by: Sasha Levin --- drivers/watchdog/watchdog_dev.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index c670d13ab3d9..6fb860542c86 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -1007,6 +1007,7 @@ static int watchdog_cdev_register(struct watchdog_device *wdd) /* Fill in the data structures */ cdev_init(&wd_data->cdev, &watchdog_fops); + wd_data->cdev.owner = wdd->ops->owner; /* Add the device */ err = cdev_device_add(&wd_data->cdev, &wd_data->dev); @@ -1021,8 +1022,6 @@ static int watchdog_cdev_register(struct watchdog_device *wdd) return err; } - wd_data->cdev.owner = wdd->ops->owner; - /* Record time of most recent heartbeat as 'just before now'. */ wd_data->last_hw_keepalive = ktime_sub(ktime_get(), 1); watchdog_set_open_deadline(wd_data); -- 2.43.0