lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230427133350.31064-3-oneukum@suse.com>
Date:   Thu, 27 Apr 2023 15:33:44 +0200
From:   Oliver Neukum <oneukum@...e.com>
To:     wim@...ux-watchdog.org, linux@...ck-us.net,
        linux-watchdog@...r.kernel.org, linux-kernel@...r.kernel.org
Cc:     Oliver Neukum <oneukum@...e.com>
Subject: [PATCH 2/8] pcwd_usb: stop open race disconnect

There is a mutex already taken in disconnect.
And it even has the correct comment.
It just has to be taken in open and disconnect, too,
to prevent the race.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Oliver Neukum <oneukum@...e.com>
---
 drivers/watchdog/pcwd_usb.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/watchdog/pcwd_usb.c b/drivers/watchdog/pcwd_usb.c
index 3a22291d633b..d5d68a529620 100644
--- a/drivers/watchdog/pcwd_usb.c
+++ b/drivers/watchdog/pcwd_usb.c
@@ -476,14 +476,21 @@ static long usb_pcwd_ioctl(struct file *file, unsigned int cmd,
 
 static int usb_pcwd_open(struct inode *inode, struct file *file)
 {
+	int retval = -EBUSY;
+
+	mutex_lock(&disconnect_mutex);
 	/* /dev/watchdog can only be opened once */
 	if (test_and_set_bit(0, &is_active))
-		return -EBUSY;
+		goto error;
 
 	/* Activate */
 	usb_pcwd_start(usb_pcwd_device);
 	usb_pcwd_keepalive(usb_pcwd_device);
-	return stream_open(inode, file);
+	retval = stream_open(inode, file);
+
+error:
+	mutex_unlock(&disconnect_mutex);
+	return retval;
 }
 
 static int usb_pcwd_release(struct inode *inode, struct file *file)
@@ -522,7 +529,13 @@ static ssize_t usb_pcwd_temperature_read(struct file *file, char __user *data,
 
 static int usb_pcwd_temperature_open(struct inode *inode, struct file *file)
 {
-	return stream_open(inode, file);
+	int retval;
+
+	mutex_lock(&disconnect_mutex);
+	retval = stream_open(inode, file);
+	mutex_unlock(&disconnect_mutex);
+
+	return retval;
 }
 
 static int usb_pcwd_temperature_release(struct inode *inode, struct file *file)
-- 
2.40.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ