linux-stable/drivers/nvdimm
Dan Williams a7db24bcee libnvdimm/dimm: Avoid race between probe and available_slots_show()
commit 7018c897c2 upstream

Richard reports that the following test:

(while true; do
     cat /sys/bus/nd/devices/nmem*/available_slots 2>&1 > /dev/null
 done) &

while true; do
     for i in $(seq 0 4); do
         echo nmem$i > /sys/bus/nd/drivers/nvdimm/bind
     done
     for i in $(seq 0 4); do
         echo nmem$i > /sys/bus/nd/drivers/nvdimm/unbind
     done
 done

...fails with a crash signature like:

    divide error: 0000 [#1] SMP KASAN PTI
    RIP: 0010:nd_label_nfree+0x134/0x1a0 [libnvdimm]
    [..]
    Call Trace:
     available_slots_show+0x4e/0x120 [libnvdimm]
     dev_attr_show+0x42/0x80
     ? memset+0x20/0x40
     sysfs_kf_seq_show+0x218/0x410

The root cause is that available_slots_show() consults driver-data, but
fails to synchronize against device-unbind setting up a TOCTOU race to
access uninitialized memory.

Validate driver-data under the device-lock.

Fixes: 4d88a97aa9 ("libnvdimm, nvdimm: dimm driver and base libnvdimm device-driver infrastructure")
Cc: <stable@vger.kernel.org>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Coly Li <colyli@suse.com>
Reported-by: Richard Palethorpe <rpalethorpe@suse.com>
Acked-by: Richard Palethorpe <rpalethorpe@suse.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
[sudip: use device_lock()]
Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-03-03 18:22:54 +01:00
..
blk.c
btt.c libnvdimm: Fix endian conversion issues 2020-06-11 09:22:55 +02:00
btt.h libnvdimm/btt: Fix LBA masking during 'free list' population 2020-05-27 16:43:09 +02:00
btt_devs.c libnvdimm/btt: Fix LBA masking during 'free list' population 2020-05-27 16:43:09 +02:00
bus.c libnvdimm: Out of bounds read in __nd_ioctl() 2020-04-24 08:01:22 +02:00
claim.c
core.c
dax_devs.c libnvdimm/pfn: fix fsdax-mode namespace info-block zero-fields 2019-07-31 07:28:41 +02:00
dimm.c
dimm_devs.c libnvdimm/dimm: Avoid race between probe and available_slots_show() 2021-03-03 18:22:54 +01:00
e820.c
Kconfig
label.c libnvdimm/namespace: Fix reaping of invalidated block-window-namespace labels 2020-12-29 13:47:11 +01:00
label.h libnvdimm: Fix compilation warnings with W=1 2019-06-19 08:20:57 +02:00
Makefile
namespace_devs.c libnvdimm: Fix endian conversion issues 2020-06-11 09:22:55 +02:00
nd-core.h
nd.h block: Move SECTOR_SIZE and SECTOR_SHIFT definitions into <linux/blkdev.h> 2020-09-09 19:03:12 +02:00
pfn.h libnvdimm/pfn: fix fsdax-mode namespace info-block zero-fields 2019-07-31 07:28:41 +02:00
pfn_devs.c libnvdimm/pfn: fix fsdax-mode namespace info-block zero-fields 2019-07-31 07:28:41 +02:00
pmem.c libnvdimm/pmem: Bypass CONFIG_HARDENED_USERCOPY overhead 2019-05-31 06:47:11 -07:00
pmem.h
region.c
region_devs.c