Skip to contentSkip to conversation

PATCH: lock ticogwinsz

PATCH Alan Cox 1 participant 1 message Aug 16, 2006 Char and misc drivers

lore
Share & tools
lore

Alan Cox

author
#0 lore raw

Now we lock the set ioctl its trivial to lock the get one so the data copied is consistent. At the moment we have the BKL here but this removes the need for it and is a step in the right direction

drivers/char/tty_io.c +10 -7
diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla-2.6.18-rc4-mm1/drivers/char/tty_io.c linux-2.6.18-rc4-mm1/drivers/char/tty_io.c
@@ -2746,18 +2742,21 @@
  *	@tty; tty
  *	@arg: user buffer for result
  *
- *	Copies the kernel idea of the window size into the user buffer. No
- *	locking is done.
+ *	Copies the kernel idea of the window size into the user buffer. 
  *
- *	FIXME: Returning random values racing a window size set is wrong
- *	should lock here against that
+ *	Locking: tty->termios_sem is taken to ensure the winsize data
+ *		is consistent.
  */
 
 static int tiocgwinsz(struct tty_struct *tty, struct winsize __user * arg)
 {
-	if (copy_to_user(arg, &tty->winsize, sizeof(*arg)))
-		return -EFAULT;
-	return 0;
+	int err;
+	
+	down(&tty->termios_sem);
+	err = copy_to_user(arg, &tty->winsize, sizeof(*arg));
+	up(&tty->termios_sem);
+	
+	return err ? -EFAULT: 0;
 }
 
 /**