Skip to contentSkip to conversation

tty: Prevent hw state corruption in exclusive mode reopen

PATCH Superseded Peter Hurley 2 participants 4 messages Dec 30, 2014 – Jan 7, 2015 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tty: Prevent hw state corruption in exclusive mode reopen

Exclusive mode ttys (TTY_EXCLUSIVE) do not allow further reopens; fail the condition before associating the file pointer and calling the driver open() method.

Prevents DTR programming when the tty is already in exclusive mode.

---
 drivers/tty/tty_io.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/tty/tty_io.c +5 -4
index 4f35b43..8629087 100644
@@ -2091,6 +2091,11 @@ retry_open:
 		goto err_file;
 	}
 
+	if (test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS_ADMIN)) {
+		retval = -EBUSY;
+		goto err_file;
+	}
+
 	tty_add_file(tty, filp);
 
 	check_tty_count(tty, __func__);
@@ -2106,10 +2111,6 @@ retry_open:
 		retval = -ENODEV;
 	filp->f_flags = saved_flags;
 
-	if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) &&
-						!capable(CAP_SYS_ADMIN))
-		retval = -EBUSY;
-
 	if (retval) {
 #ifdef TTY_DEBUG_HANGUP
 		printk(KERN_DEBUG "%s: error %d in opening %s...\n", __func__,
Signature · 1 line
2.2.1
#1 lore raw
Quoted 5 lines · Peter Hurley

Exclusive mode ttys (TTY_EXCLUSIVE) do not allow further reopens; fail the condition before associating the file pointer and calling the driver open() method.

Prevents DTR programming when the tty is already in exclusive mode.

Greg,

Please disregard. I'll redo a v2 that isn't broken.

Regards,
Peter Hurley

#2 lore raw

PATCH v2 1/1 tty: Prevent hw state corruption in exclusive mode reopen

In reply to Peter Hurley

Exclusive mode ttys (TTY_EXCLUSIVE) do not allow further reopens; fail the condition before associating the file pointer and calling the driver open() method.

Prevents DTR programming when the tty is already in exclusive mode.

---
 drivers/tty/tty_io.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/tty/tty_io.c +3 -4
index 4f35b43..51f066a 100644
@@ -1464,6 +1464,9 @@ static int tty_reopen(struct tty_struct *tty)
 	    driver->subtype == PTY_TYPE_MASTER)
 		return -EIO;
 
+	if (test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS_ADMIN))
+		return -EBUSY;
+
 	tty->count++;
 
 	WARN_ON(!tty->ldisc);
@@ -2106,10 +2109,6 @@ retry_open:
 		retval = -ENODEV;
 	filp->f_flags = saved_flags;
 
-	if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) &&
-						!capable(CAP_SYS_ADMIN))
-		retval = -EBUSY;
-
 	if (retval) {
 #ifdef TTY_DEBUG_HANGUP
 		printk(KERN_DEBUG "%s: error %d in opening %s...\n", __func__,
Signature · 1 line
2.2.1
Acked-by on v2 1/1
#3 lore raw

Peter Hurley <[email protected]> wrote on 12/30/2014 09:39:25 AM:

Quoted 7 lines

From: Peter Hurley <[email protected]>
To: Greg Kroah-Hartman <[email protected]>,
Cc: Jiri Slaby <[email protected]>, [email protected], [email protected], Shreyas Bethur <[email protected]>, Peter Hurley <[email protected]>
Date: 12/30/2014 09:39 AM
Subject: [PATCH v2] tty: Prevent hw state corruption in exclusive mode

reopen

Quoted 41 lines

Exclusive mode ttys (TTY_EXCLUSIVE) do not allow further reopens; fail the condition before associating the file pointer and calling the driver open() method.

Prevents DTR programming when the tty is already in exclusive mode.

---
 drivers/tty/tty_io.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/tty/tty_io.c +3 -4
index 4f35b43..51f066a 100644
@@ -1464,6 +1464,9 @@ static int tty_reopen(struct tty_struct *tty)
        driver->subtype == PTY_TYPE_MASTER)
       return -EIO;
 
+   if (test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS_ADMIN))
+      return -EBUSY;
+
    tty->count++;
 
    WARN_ON(!tty->ldisc);
@@ -2106,10 +2109,6 @@ retry_open:
       retval = -ENODEV;
    filp->f_flags = saved_flags;
 
-   if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) &&
-                  !capable(CAP_SYS_ADMIN))
-      retval = -EBUSY;
-
    if (retval) {
 #ifdef TTY_DEBUG_HANGUP
       printk(KERN_DEBUG "%s: error %d in opening %s...\n", __func__,
Signature · 1 line
2.2.1