Patch "watchdog: set cdev owner before adding" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    watchdog: set cdev owner before adding

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     watchdog-set-cdev-owner-before-adding.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 1b4b8761dbd517d7c2aeb4a9653e226d12909970
Author: Curtis Klein <curtis.klein@xxxxxxx>
Date:   Tue Dec 5 11:05:22 2023 -0800

    watchdog: set cdev owner before adding
    
    [ 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 <curtis.klein@xxxxxxx>
    Reviewed-by: Guenter Roeck <linux@xxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20231205190522.55153-1-curtis.klein@xxxxxxx
    Signed-off-by: Guenter Roeck <linux@xxxxxxxxxxxx>
    Signed-off-by: Wim Van Sebroeck <wim@xxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index 5eec84fa6517..d3b5aa87c141 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -1035,6 +1035,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);
@@ -1049,8 +1050,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);




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux