Re: possible locking bug in tty_open

Previous thread: About the best internet brand for you:pkmap.cn by jacalyngeorgesf6n on Sunday, May 2, 2010 - 11:40 am. (1 message)

Next thread: [PATCH] MIPS: nofpu and nodsp only affect CPU0 by Kevin Cernekee on Sunday, May 2, 2010 - 2:43 pm. (3 messages)
From: Arnd Bergmann
Date: Sunday, May 2, 2010 - 1:47 pm

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
--

From: Alan Cox
Date: Tuesday, May 4, 2010 - 2:43 am

On Sun, 2 May 2010 22:47:33 +0200

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

From: Alan Cox
Date: Tuesday, May 4, 2010 - 12:42 pm

On Sun, 2 May 2010 22:47:33 +0200

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.
    
Signed-off-by: Alan Cox <alan@linux.intel.com>

diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 6da962c..fe810a7 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -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();
--

From: Arnd Bergmann
Date: Tuesday, May 4, 2010 - 1:26 pm

Acked-by: Arnd Bergmann <arnd@arndb.de>
--

Previous thread: About the best internet brand for you:pkmap.cn by jacalyngeorgesf6n on Sunday, May 2, 2010 - 11:40 am. (1 message)

Next thread: [PATCH] MIPS: nofpu and nodsp only affect CPU0 by Kevin Cernekee on Sunday, May 2, 2010 - 2:43 pm. (3 messages)