NVMe: Do not open disks that are being deleted
authorKeith Busch <keith.busch@intel.com>
Fri, 3 Oct 2014 17:15:47 +0000 (11:15 -0600)
committerJens Axboe <axboe@fb.com>
Tue, 4 Nov 2014 20:18:32 +0000 (13:18 -0700)
commit9e60352cf83faaba57f99f6960b545687b8bbb20
treeda92850b088a1d975b2f489a67f5583f5f1d273e
parent5940c8578fe720afbf4ef041bad0d72a101f1d88
NVMe: Do not open disks that are being deleted

It is possible the block layer will request to open a block device after
the driver deleted it. Subsequent releases will cause a double free,
or the disk's private_data is pointing to freed memory. This patch
protects the driver's freed disks from being opened and accessed: the
nvme namespaces are freed only when the device's refcount is 0, so at
that moment there were no active openers and no more should be allowed,
and it is safe to clear the disk's private_data that is about to be freed.

Signed-off-by: Keith Busch <keith.busch@intel.com>
Reported-by: Henry Chow <henry.chow@oracle.com>
Signed-off-by: Matthew Wilcox <matthew.r.wilcox@intel.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
drivers/block/nvme-core.c