]> Git Repo - linux.git/commitdiff
watchdog: Ensure that wdd is not dereferenced if NULL
authorGuenter Roeck <[email protected]>
Wed, 9 Mar 2016 02:46:13 +0000 (18:46 -0800)
committerWim Van Sebroeck <[email protected]>
Wed, 16 Mar 2016 20:11:50 +0000 (21:11 +0100)
Smatch rightfully complains that wdd is dereferenced in the watchdog
release function after being checked for NULL. Also make sure that it
is not accessed outside mutex protection to avoid use-after-free problems.

Fixes: e6c71e84e4c0 ("watchdog: Introduce WDOG_HW_RUNNING flag")
Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
Signed-off-by: Wim Van Sebroeck <[email protected]>
drivers/watchdog/watchdog_dev.c

index 2d6110278eac6869bf1c7b9e7fe08ec8479e0c9c..e2c5abbb45ffd77d0b838fcebdab0536a637af8e 100644 (file)
@@ -711,6 +711,7 @@ static int watchdog_release(struct inode *inode, struct file *file)
        struct watchdog_core_data *wd_data = file->private_data;
        struct watchdog_device *wdd;
        int err = -EBUSY;
+       bool running;
 
        mutex_lock(&wd_data->lock);
 
@@ -742,14 +743,15 @@ static int watchdog_release(struct inode *inode, struct file *file)
        clear_bit(_WDOG_DEV_OPEN, &wd_data->status);
 
 done:
+       running = wdd && watchdog_hw_running(wdd);
        mutex_unlock(&wd_data->lock);
        /*
         * Allow the owner module to be unloaded again unless the watchdog
         * is still running. If the watchdog is still running, it can not
         * be stopped, and its driver must not be unloaded.
         */
-       if (!watchdog_hw_running(wdd)) {
-               module_put(wdd->ops->owner);
+       if (!running) {
+               module_put(wd_data->cdev.owner);
                kref_put(&wd_data->kref, watchdog_core_data_release);
        }
        return 0;
This page took 0.056202 seconds and 4 git commands to generate.