Skip to contentSkip to conversation

possible locking bug in tty_open

DISCUSSION Arnd Bergmann 2 participants 4 messages May 2, 2010 – May 4, 2010 Char and misc drivers

lore
Share & tools
lore

Arnd Bergmann

author maintainer
#0 lore raw

While playing some more with my TTY BKL patches, I stumbled over what looks like a bug in tty_open, introduced in e8c6210 "tty: push the BKL down into the handlers a bit":

After the "retry_open:" label, we first get the tty_mutex and then the BKL. However a the end of tty_open, we jump back to retry_open with the BKL still held. If we run into this case, the tty_open function will be left with the BKL still held.

It may be impossible to actually trigger this bug, because the path is only taken if a tty driver open function returns -ERESTARTSYS without setting signal_pending().

Arnd

#1 lore raw
Quoted 10 lines · On Sun, 2 May 2010 22:47:33 +0200 Arnd Bergmann <[email protected]> wrote:

While playing some more with my TTY BKL patches, I stumbled over what looks like a bug in tty_open, introduced in e8c6210 "tty: push the BKL down into the handlers a bit":

After the "retry_open:" label, we first get the tty_mutex and then the BKL. However a the end of tty_open, we jump back to retry_open with the BKL still held. If we run into this case, the tty_open function will be left with the BKL still held.

Quoted 3 lines

It may be impossible to actually trigger this bug, because the path is only taken if a tty driver open function returns -ERESTARTSYS without setting signal_pending().

It looks pretty much impossible to trigger but it's definitely a bug. I'll send Greg a patch

#2 lore raw
In reply to Arnd Bergmann
Quoted 10 lines · On Sun, 2 May 2010 22:47:33 +0200 Arnd Bergmann <[email protected]> wrote:

While playing some more with my TTY BKL patches, I stumbled over what looks like a bug in tty_open, introduced in e8c6210 "tty: push the BKL down into the handlers a bit":

After the "retry_open:" label, we first get the tty_mutex and then the BKL. However a the end of tty_open, we jump back to retry_open with the BKL still held. If we run into this case, the tty_open function will be left with the BKL still held.

Quoted 5 lines

It may be impossible to actually trigger this bug, because the path is only taken if a tty driver open function returns -ERESTARTSYS without setting signal_pending().

Arnd

I think all we need is probably this

tty: Fix unbalanced BKL handling in error path

Arnd noted:

After the "retry_open:" label, we first get the tty_mutex and then the BKL. However a the end of tty_open, we jump back to retry_open with the BKL still held. If we run into this case, the tty_open function will be left with the BKL still held.

drivers/char/tty_io.c +1 -0
index 6da962c..fe810a7 100644
@@ -1875,6 +1875,7 @@ got_driver:
 		 */
 		if (filp->f_op == &hung_up_tty_fops)
 			filp->f_op = &tty_fops;
+		unlock_kernel();
 		goto retry_open;
 	}
 	unlock_kernel();
author maintainer Acked-by
#3 lore raw
Quoted 13 lines · On Tuesday 04 May 2010 21:42:36 Alan Cox wrote:
Quoted 5 lines · On Sun, 2 May 2010 22:47:33 +0200 Arnd Bergmann <[email protected]> wrote:

After the "retry_open:" label, we first get the tty_mutex and then the BKL. However a the end of tty_open, we jump back to retry_open with the BKL still held. If we run into this case, the tty_open function will be left with the BKL still held.

I think all we need is probably this

tty: Fix unbalanced BKL handling in error path

Quoted 7 lines

Arnd noted:

After the "retry_open:" label, we first get the tty_mutex and then the BKL. However a the end of tty_open, we jump back to retry_open with the BKL still held. If we run into this case, the tty_open function will be left with the BKL still held.

Yes, looks good.

Quoted 2 lines