+ do_tty_write-can-block-even-with-o_nonblock.patch added to -mm tree

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

 



The patch titled
     do_tty_write() can block even with O_NONBLOCK?
has been added to the -mm tree.  Its filename is
     do_tty_write-can-block-even-with-o_nonblock.patch

*** Remember to use Documentation/SubmitChecklist when testing your code ***

See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find
out what to do about this

------------------------------------------------------
Subject: do_tty_write() can block even with O_NONBLOCK?
From: Dave Johnson <djohnson+linux-kernel@xxxxxxxxxxxxxxxxxxxxxx>

I have two processes with the same tty open, one opens blocking and one
opens nonblocking.

If the blocking process blocks doing a write (due to flow control, just
going to fast, etc...) the nonblocking process will also block when it
writes until the blocking process unblocks.

This seems to occur because do_tty_write() isn't checking for O_NONBLOCK
when taking the tty's write mutex.

Signed-off-by: Dave Johnson <djohnson+linux-kernel@xxxxxxxxxxxxxxxxxxxxxx>
Acked-by: Alan Cox <alan@xxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

 drivers/char/tty_io.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff -puN drivers/char/tty_io.c~do_tty_write-can-block-even-with-o_nonblock drivers/char/tty_io.c
--- a/drivers/char/tty_io.c~do_tty_write-can-block-even-with-o_nonblock
+++ a/drivers/char/tty_io.c
@@ -1699,9 +1699,13 @@ static inline ssize_t do_tty_write(
 	ssize_t ret = 0, written = 0;
 	unsigned int chunk;
 	
-	/* FIXME: O_NDELAY ... */
-	if (mutex_lock_interruptible(&tty->atomic_write_lock)) {
-		return -ERESTARTSYS;
+	if (file->f_flags & O_NONBLOCK) {
+		if (!mutex_trylock(&tty->atomic_write_lock))
+			return -EAGAIN;
+	}
+	else {
+		if (mutex_lock_interruptible(&tty->atomic_write_lock))
+			return -ERESTARTSYS;
 	}
 
 	/*
_

Patches currently in -mm which might be from djohnson+linux-kernel@xxxxxxxxxxxxxxxxxxxxxx are

do_tty_write-can-block-even-with-o_nonblock.patch
do_tty_write-can-block-even-with-o_nonblock-tidy.patch

-
To unsubscribe from this list: send the line "unsubscribe mm-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Kernel Newbies FAQ]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Photo]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux