kernel-ark/drivers
Paul Mackerras f786648b89 [PATCH] Remove race between con_open and con_close
[ Same race and same patch also by Steven Rostedt <rostedt@goodmis.org> ]

I have a laptop (G3 powerbook) which will pretty reliably hit a race
between con_open and con_close late in the boot process and oops in
vt_ioctl due to tty->driver_data being NULL.

What happens is this: process A opens /dev/tty6; it comes into
con_open() (drivers/char/vt.c) and assign a non-NULL value to
tty->driver_data.  Then process A closes that and concurrently process
B opens /dev/tty6.  Process A gets through con_close() and clears
tty->driver_data, since tty->count == 1.  However, before process A
can decrement tty->count, we switch to process B (e.g. at the
down(&tty_sem) call at drivers/char/tty_io.c line 1626).

So process B gets to run and comes into con_open with tty->count == 2,
as tty->count is incremented (in init_dev) before con_open is called.
Because tty->count != 1, we don't set tty->driver_data.  Then when the
process tries to do anything with that fd, it oopses.

The simple and effective fix for this is to test tty->driver_data
rather than tty->count in con_open.  The testing and setting of
tty->driver_data is serialized with respect to the clearing of
tty->driver_data in con_close by the console_sem.  We can't get a
situation where con_open sees tty->driver_data != NULL and then
con_close on a different fd clears tty->driver_data, because
tty->count is incremented before con_open is called.  Thus this patch
eliminates the race, and in fact with this patch my laptop doesn't
oops.

Signed-off-by: Paul Mackerras <paulus@samba.org>
[ Same patch
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
  in http://marc.theaimsgroup.com/?l=linux-kernel&m=112450820432121&w=2 ]
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-08-27 18:03:42 -07:00
..
acorn
acpi [PATCH] acpi_shutdown: Only prepare for power off on power_off 2005-08-27 10:11:40 -07:00
atm
base [PATCH] Fix manual binding infinite loop 2005-08-17 22:02:25 -07:00
block [PATCH] cfq-iosched.c: minor fixes 2005-08-24 10:22:44 -07:00
bluetooth
cdrom
char [PATCH] Remove race between con_open and con_close 2005-08-27 18:03:42 -07:00
cpufreq
crypto
dio
eisa
fc4
firmware
hwmon [PATCH] I2C hwmon: kfree fixes 2005-08-26 19:37:12 -07:00
i2c [PATCH] Build fix for the Sibyte I2C driver 2005-08-09 12:08:21 -07:00
ide [PATCH] serverworks: add support for new southbridge IDE 2005-08-18 22:30:35 +02:00
ieee1394 [PATCH] late spinlock initialization in ieee1394/ohci 2005-08-26 16:30:30 -07:00
infiniband [PATCH] IB: fix use-after-free in user verbs cleanup 2005-08-26 19:37:12 -07:00
input [PATCH] ns558 list handling fix 2005-08-10 11:03:02 -07:00
isdn [PATCH] Fix capifs bug in initialization error path. 2005-08-27 10:11:40 -07:00
macintosh [PATCH] Kconfig fix (PMAC_BACKLIGHT on ppc64) 2005-08-23 18:43:40 -07:00
mca
md [PATCH] md: clear the 'recovery' flags when starting an md array. 2005-08-26 19:37:13 -07:00
media [PATCH] fix for race problem in DVB USB drivers (dibusb) 2005-08-27 11:03:45 -07:00
message [PATCH] I2O: added pci_request_regions() before using the controller 2005-08-09 17:59:52 -07:00
misc
mmc [PATCH] wbsd version bump 2005-08-10 11:08:56 -07:00
mtd
net Merge HEAD from master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6.git 2005-08-26 16:32:31 -07:00
nubus
oprofile
parisc
parport [PATCH] Kconfig fix (parport_pc on m32r) 2005-08-23 18:43:41 -07:00
pci Ignore disabled ROM resources at setup 2005-08-26 10:49:22 -07:00
pcmcia [PATCH] missing include in pcmcia_resource.c 2005-08-23 18:43:43 -07:00
pnp [PATCH] broken error path in drivers/pnp/card.c 2005-08-18 08:43:59 -07:00
s390 [PATCH] zfcp: add rports to enable scsi_add_device to work again 2005-08-27 11:22:36 -07:00
sbus [SPARC]: envctrl: ERR_PTR() --> PTR_ERR() 2005-08-09 14:43:14 -07:00
scsi [PATCH] sg.c: fix a memory leak in devices seq_file implementation 2005-08-27 11:22:27 -07:00
serial [PATCH] m32r_sio gcc4 fixes 2005-08-23 18:43:44 -07:00
sh
sn
tc
telephony
usb [PATCH] usbnet oops fix 2005-08-23 19:59:38 -07:00
video [PATCH] Kconfig fix (VGA console on arm/versatile) 2005-08-23 18:43:42 -07:00
w1 [PATCH] w1: more debug level decrease. 2005-08-12 12:55:02 -07:00
zorro
Kconfig
Makefile