linux-stable/drivers/char
Mikulas Patocka b87570f5d3 Fix a crash when block device is read and block size is changed at the same time
The kernel may crash when block size is changed and I/O is issued
simultaneously.

Because some subsystems (udev or lvm) may read any block device anytime,
the bug actually puts any code that changes a block device size in
jeopardy.

The crash can be reproduced if you place "msleep(1000)" to
blkdev_get_blocks just before "bh->b_size = max_blocks <<
inode->i_blkbits;".
Then, run "dd if=/dev/ram0 of=/dev/null bs=4k count=1 iflag=direct"
While it is waiting in msleep, run "blockdev --setbsz 2048 /dev/ram0"
You get a BUG.

The direct and non-direct I/O is written with the assumption that block
size does not change. It doesn't seem practical to fix these crashes
one-by-one there may be many crash possibilities when block size changes
at a certain place and it is impossible to find them all and verify the
code.

This patch introduces a new rw-lock bd_block_size_semaphore. The lock is
taken for read during I/O. It is taken for write when changing block
size. Consequently, block size can't be changed while I/O is being
submitted.

For asynchronous I/O, the patch only prevents block size change while
the I/O is being submitted. The block size can change when the I/O is in
progress or when the I/O is being finished. This is acceptable because
there are no accesses to block size when asynchronous I/O is being
finished.

The patch prevents block size changing while the device is mapped with
mmap.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2012-09-26 07:46:40 +02:00
..
agp drm/i915: fix hsw uncached pte 2012-08-17 09:21:35 +02:00
hw_random omap-rng: fix use of SIMPLE_DEV_PM_OPS 2012-08-10 12:28:05 +02:00
ipmi char/ipmi: remove local ioctl defines replaced by generic ones 2012-07-23 12:48:04 +02:00
mwave Remove all #inclusions of asm/system.h 2012-03-28 18:30:03 +01:00
pcmcia Remove all #inclusions of asm/system.h 2012-03-28 18:30:03 +01:00
tpm tpm_tis / PM: Fix unused function warning for CONFIG_PM_SLEEP 2012-08-10 14:29:50 +02:00
xilinx_hwicap xilinx_hwicap: reset XHI_MAX_RETRIES 2012-04-19 19:09:18 -07:00
apm-emulation.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/apm 2012-04-05 17:34:30 -07:00
applicom.c
applicom.h
bfin-otp.c
bsr.c powerpc/BSR: cleanup the error path of bsr_init 2012-07-17 10:27:38 -07:00
ds1302.c Remove all #inclusions of asm/system.h 2012-03-28 18:30:03 +01:00
ds1620.c
dsp56k.c
dtlk.c
efirtc.c Remove all #inclusions of asm/system.h 2012-03-28 18:30:03 +01:00
generic_nvram.c drivers: fix up various ->llseek() implementations 2011-07-20 20:47:58 -04:00
genrtc.c Remove all #inclusions of asm/system.h 2012-03-28 18:30:03 +01:00
hangcheck-timer.c
hpet.c printk(): add KERN_CONT where needed in hpet and vt code 2012-04-09 10:30:39 -07:00
i8k.c module_param: make bool parameters really bool (drivers & misc) 2012-01-13 09:32:20 +10:30
Kconfig ramoops: Move to fs/pstore/ram.c 2012-05-16 08:06:37 -07:00
lp.c Merge branch 'x86-x32-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2012-03-29 18:12:23 -07:00
Makefile ramoops: Move to fs/pstore/ram.c 2012-05-16 08:06:37 -07:00
mbcs.c Remove all #inclusions of asm/system.h 2012-03-28 18:30:03 +01:00
mbcs.h
mem.c powerpc: Disable /dev/port interface on systems without an ISA bridge 2012-07-11 18:22:32 +10:00
misc.c switch device_get_devnode() and ->devnode() to umode_t * 2012-01-03 22:54:55 -05:00
mmtimer.c
msm_smd_pkt.c drivers/char/msm_smd_pkt.c: don't use IS_ERR() 2011-08-25 16:25:33 -07:00
mspec.c [IA64] Redefine ATOMIC_INIT and ATOMIC64_INIT to drop the casts 2012-07-26 10:55:26 -07:00
nsc_gpio.c
nvram.c Remove all #inclusions of asm/system.h 2012-03-28 18:30:03 +01:00
nwbutton.c
nwbutton.h
nwflash.c Remove all #inclusions of asm/system.h 2012-03-28 18:30:03 +01:00
pc8736x_gpio.c
ppdev.c
ps3flash.c drivers/char: Add module.h to those who were using it implicitly 2011-10-31 19:31:40 -04:00
random.c random: mix in architectural randomness in extract_buf() 2012-07-27 22:37:20 -04:00
raw.c Fix a crash when block device is read and block size is changed at the same time 2012-09-26 07:46:40 +02:00
rtc.c Remove all #inclusions of asm/system.h 2012-03-28 18:30:03 +01:00
scx200_gpio.c
snsc.c
snsc.h
snsc_event.c
sonypi.c sonypi: Use struct dev_pm_ops for power management 2012-07-01 13:31:14 +02:00
tb0219.c
tile-srom.c tile-srom.c driver: minor code cleanup 2012-04-02 12:14:10 -04:00
tlclk.c char: Fix typo in tlclk.c 2012-02-09 23:09:37 +01:00
toshiba.c
ttyprintk.c TTY: remove re-assignments to tty_driver members 2012-03-08 11:37:58 -08:00
uv_mmtimer.c
virtio_console.c virtio: console: tell host of open ports after resume from s3/s4 2012-05-17 12:14:33 +03:00