android_kernel_samsung_msm8976/block
Dan Williams 058bd7b503 block: fix del_gendisk() vs blkdev_ioctl crash
commit ac34f15e0c6d2fd58480052b6985f6991fb53bcc upstream.

When tearing down a block device early in its lifetime, userspace may
still be performing discovery actions like blkdev_ioctl() to re-read
partitions.

The nvdimm_revalidate_disk() implementation depends on
disk->driverfs_dev to be valid at entry.  However, it is set to NULL in
del_gendisk() and fatally this is happening *before* the disk device is
deleted from userspace view.

There's no reason for del_gendisk() to clear ->driverfs_dev.  That
device is the parent of the disk.  It is guaranteed to not be freed
until the disk, as a child, drops its ->parent reference.

We could also fix this issue locally in nvdimm_revalidate_disk() by
using disk_to_dev(disk)->parent, but lets fix it globally since
->driverfs_dev follows the lifetime of the parent.  Longer term we
should probably just add a @parent parameter to add_disk(), and stop
carrying this pointer in the gendisk.

 BUG: unable to handle kernel NULL pointer dereference at           (null)
 IP: [<ffffffffa00340a8>] nvdimm_revalidate_disk+0x18/0x90 [libnvdimm]
 CPU: 2 PID: 538 Comm: systemd-udevd Tainted: G           O    4.4.0-rc5 #2257
 [..]
 Call Trace:
  [<ffffffff8143e5c7>] rescan_partitions+0x87/0x2c0
  [<ffffffff810f37f9>] ? __lock_is_held+0x49/0x70
  [<ffffffff81438c62>] __blkdev_reread_part+0x72/0xb0
  [<ffffffff81438cc5>] blkdev_reread_part+0x25/0x40
  [<ffffffff8143982d>] blkdev_ioctl+0x4fd/0x9c0
  [<ffffffff811246c9>] ? current_kernel_time64+0x69/0xd0
  [<ffffffff812916dd>] block_ioctl+0x3d/0x50
  [<ffffffff81264c38>] do_vfs_ioctl+0x308/0x560
  [<ffffffff8115dbd1>] ? __audit_syscall_entry+0xb1/0x100
  [<ffffffff810031d6>] ? do_audit_syscall_entry+0x66/0x70
  [<ffffffff81264f09>] SyS_ioctl+0x79/0x90
  [<ffffffff81902672>] entry_SYSCALL_64_fastpath+0x12/0x76

Cc: Jan Kara <jack@suse.cz>
Cc: Jens Axboe <axboe@fb.com>
Reported-by: Robert Hu <robert.hu@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>
2019-07-27 21:43:29 +02:00
..
partitions This is the 3.10.99 stable release 2017-04-18 17:17:46 +02:00
Kconfig
Kconfig.iosched block: cgroups, kconfig, build bits for BFQ-v7r8-3.10.8+ 2017-04-18 04:37:19 +02:00
Makefile block: cgroups, kconfig, build bits for BFQ-v7r8-3.10.8+ 2017-04-18 04:37:19 +02:00
bfq-cgroup.c block: introduce the BFQ-v7r8 I/O sched for 3.10.8+ 2017-04-18 04:37:19 +02:00
bfq-ioc.c block: introduce the BFQ-v7r8 I/O sched for 3.10.8+ 2017-04-18 04:37:19 +02:00
bfq-iosched.c block, bfq: add Early Queue Merge (EQM) to BFQ-v7r8 for 3.10.8+ 2017-04-18 04:37:20 +02:00
bfq-sched.c block, bfq: add Early Queue Merge (EQM) to BFQ-v7r8 for 3.10.8+ 2017-04-18 04:37:20 +02:00
bfq.h block, bfq: add Early Queue Merge (EQM) to BFQ-v7r8 for 3.10.8+ 2017-04-18 04:37:20 +02:00
blk-cgroup.c blkcg: fix gendisk reference leak in blkg_conf_prep() 2015-08-10 12:20:30 -07:00
blk-cgroup.h
blk-core.c BACKPORT: block: add blk_rq_set_block_pc() 2017-04-22 23:03:01 +02:00
blk-exec.c
blk-flush.c
blk-integrity.c
blk-ioc.c
blk-iopoll.c
blk-lib.c Import latest Samsung release 2017-04-18 03:43:52 +02:00
blk-map.c
blk-merge.c
blk-settings.c This is the 3.10.67 stable release 2015-04-24 18:04:40 -07:00
blk-softirq.c
blk-sysfs.c Import latest Samsung release 2017-04-18 03:43:52 +02:00
blk-tag.c
blk-throttle.c blk-throttle: check stats_cpu before reading it from sysfs 2015-03-06 14:40:54 -08:00
blk-timeout.c
blk.h
bsg-lib.c
bsg.c BACKPORT: block: add blk_rq_set_block_pc() 2017-04-22 23:03:01 +02:00
cfq-iosched.c cfq: fix starvation of asynchronous writes 2019-07-27 21:42:46 +02:00
compat_ioctl.c
deadline-iosched.c
elevator.c
genhd.c block: fix del_gendisk() vs blkdev_ioctl crash 2019-07-27 21:43:29 +02:00
ioctl.c Import latest Samsung release 2017-04-18 03:43:52 +02:00
noop-iosched.c
partition-generic.c This is the 3.10.67 stable release 2015-04-24 18:04:40 -07:00
row-iosched.c
scsi_ioctl.c block: allow WRITE_SAME commands with the SG_IO ioctl 2019-07-27 21:43:28 +02:00
test-iosched.c