linux/drivers/char
Linus Torvalds 80e1e82398 Fix race in tty_fasync() properly
This reverts commit 7036251180 ("tty: fix race in tty_fasync") and
commit b04da8bfdf ("fnctl: f_modown should call write_lock_irqsave/
restore") that tried to fix up some of the fallout but was incomplete.

It turns out that we really cannot hold 'tty->ctrl_lock' over calling
__f_setown, because not only did that cause problems with interrupt
disables (which the second commit fixed), it also causes a potential
ABBA deadlock due to lock ordering.

Thanks to Tetsuo Handa for following up on the issue, and running
lockdep to show the problem.  It goes roughly like this:

 - f_getown gets filp->f_owner.lock for reading without interrupts
   disabled, so an interrupt that happens while that lock is held can
   cause a lockdep chain from f_owner.lock -> sighand->siglock.

 - at the same time, the tty->ctrl_lock -> f_owner.lock chain that
   commit 7036251180 introduced, together with the pre-existing
   sighand->siglock -> tty->ctrl_lock chain means that we have a lock
   dependency the other way too.

So instead of extending tty->ctrl_lock over the whole __f_setown() call,
we now just take a reference to the 'pid' structure while holding the
lock, and then release it after having done the __f_setown.  That still
guarantees that 'struct pid' won't go away from under us, which is all
we really ever needed.

Reported-and-tested-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Acked-by: Américo Wang <xiyou.wangcong@gmail.com>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-02-07 10:26:01 -08:00
..
agp x86/agp: Fix agp_amd64_init regression 2010-01-31 07:52:26 +01:00
hw_random virtio: fix section mismatch warnings 2010-01-16 12:15:39 -08:00
ip2
ipmi ACPI: fix ACPI=n allmodconfig build 2009-12-30 01:24:25 -05:00
mwave
pcmcia
rio
tpm
xilinx_hwicap
.gitignore
amiserial.c
apm-emulation.c
applicom.c
applicom.h
bfin_jtag_comm.c
bfin-otp.c
briq_panel.c
bsr.c
cd1865.h
ChangeLog
consolemap.c
cp437.uni
cs5535_gpio.c
cyclades.c
defkeymap.c_shipped
defkeymap.map
digi1.h
digiFep1.h
digiPCI.h
ds1302.c
ds1620.c
dsp56k.c
dtlk.c
efirtc.c efirtc: explicitly set llseek to no_llseek 2009-12-16 07:19:59 -08:00
epca.c
epca.h
epcaconfig.h
generic_nvram.c
generic_serial.c
genrtc.c
hangcheck-timer.c
hpet.c
hvc_beat.c
hvc_console.c
hvc_console.h
hvc_irq.c
hvc_iseries.c
hvc_iucv.c const: constify remaining dev_pm_ops 2009-12-15 08:53:25 -08:00
hvc_rtas.c
hvc_udbg.c
hvc_vio.c
hvc_xen.c
hvcs.c
hvsi.c
i8k.c
isicom.c
istallion.c
Kconfig powerpc/hvc: Driver build breaks with !HVC_CONSOLE 2010-01-15 13:26:13 +11:00
keyboard.c Input: keyboard - don't override beep with a bell 2009-12-15 21:48:55 -08:00
lp.c
Makefile
mbcs.c
mbcs.h
mem.c devmem: fix kmem write bug on memory holes 2010-02-02 18:11:22 -08:00
misc.c drivers/char/misc.c: use bitmap/bitops functions for dynamic minor number allocation 2009-12-15 08:53:27 -08:00
mmtimer.c
moxa.c
moxa.h
mspec.c
mxser.c
mxser.h
n_hdlc.c
n_r3964.c
n_tty.c
nozomi.c nozomi: quick fix for the close/close bug 2010-01-20 15:03:27 -08:00
nsc_gpio.c
nvram.c
nwbutton.c
nwbutton.h
nwflash.c ARM: add missing include to nwflash.c 2009-12-19 23:36:00 +00:00
pc8736x_gpio.c
ppdev.c
ps3flash.c
pty.c
random.c random: Remove unused inode variable 2010-02-02 06:50:27 +11:00
raw.c
riscom8_reg.h
riscom8.c
riscom8.h
rocket_int.h
rocket.c
rocket.h
rtc.c
scc.h
scx200_gpio.c
selection.c
ser_a2232.c
ser_a2232.h
ser_a2232fw.ax
ser_a2232fw.h
serial167.c
snsc_event.c
snsc.c
snsc.h
sonypi.c sony_pi: Remove the BKL from open and ioctl 2010-01-04 12:31:20 -08:00
specialix_io8.h
specialix.c
stallion.c
sx.c
sx.h
sxboards.h
sxwindow.h
synclink_gt.c
synclink.c
synclinkmp.c
sysrq.c oom-kill: fix NUMA constraint check with nodemask 2009-12-16 07:19:57 -08:00
tb0219.c
tlclk.c
toshiba.c tosh: Use non bkl ioctl 2010-01-04 12:31:21 -08:00
tty_audit.c
tty_buffer.c
tty_io.c Fix race in tty_fasync() properly 2010-02-07 10:26:01 -08:00
tty_ioctl.c
tty_ldisc.c
tty_port.c
uv_mmtimer.c x86, UV: Fix RTC latency bug by reading replicated cachelines 2010-01-27 11:33:53 +01:00
vc_screen.c
viotape.c
virtio_console.c
vme_scc.c
vt_ioctl.c
vt.c vt: make the default cursor shape configurable 2009-12-16 07:19:57 -08:00