linux-stable/drivers/nvdimm
sumiyawang 1f2b324e82 libnvdimm/pmem: Fix crash triggered when I/O in-flight during unbind
commit 32b2397c1e upstream.

There is a use after free crash when the pmem driver tears down its
mapping while I/O is still inbound.

This is triggered by driver unbind, "ndctl destroy-namespace", while I/O
is in flight.

Fix the sequence of blk_cleanup_queue() vs memunmap().

The crash signature is of the form:

 BUG: unable to handle page fault for address: ffffc90080200000
 CPU: 36 PID: 9606 Comm: systemd-udevd
 Call Trace:
  ? pmem_do_bvec+0xf9/0x3a0
  ? xas_alloc+0x55/0xd0
  pmem_rw_page+0x4b/0x80
  bdev_read_page+0x86/0xb0
  do_mpage_readpage+0x5d4/0x7a0
  ? lru_cache_add+0xe/0x10
  mpage_readpages+0xf9/0x1c0
  ? bd_link_disk_holder+0x1a0/0x1a0
  blkdev_readpages+0x1d/0x20
  read_pages+0x67/0x1a0

  ndctl Call Trace in vmcore:
  PID: 23473  TASK: ffff88c4fbbe8000  CPU: 1   COMMAND: "ndctl"
  __schedule
  schedule
  blk_mq_freeze_queue_wait
  blk_freeze_queue
  blk_cleanup_queue
  pmem_release_queue
  devm_action_release
  release_nodes
  devres_release_all
  device_release_driver_internal
  device_driver_detach
  unbind_store

Cc: <stable@vger.kernel.org>
Signed-off-by: sumiyawang <sumiyawang@tencent.com>
Reviewed-by: yongduan <yongduan@tencent.com>
Link: https://lore.kernel.org/r/1629632949-14749-1-git-send-email-sumiyawang@tencent.com
Fixes: 50f44ee724 ("mm/devm_memremap_pages: fix final page put race")
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
[tyhicks: Minor contextual change in pmem_attach_disk() due to the
 transition to 'struct range' not yet taking place. Preserve the
 memcpy() call rather than initializing the range struct. That change
 was introduced in v5.10 with commit a4574f63ed ("mm/memremap_pages:
 convert to 'struct range'")]
Signed-off-by: Tyler Hicks <tyhicks@linux.microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-10-06 15:42:38 +02:00
..
badrange.c
blk.c
btt.c
btt.h
btt_devs.c
bus.c
claim.c
core.c
dax_devs.c
dimm.c
dimm_devs.c libnvdimm/dimm: Avoid race between probe and available_slots_show() 2021-02-10 09:25:30 +01:00
e820.c
Kconfig
label.c libnvdimm/namespace: Fix reaping of invalidated block-window-namespace labels 2020-12-30 11:51:47 +01:00
label.h
Makefile
namespace_devs.c libnvdimm/region: Fix label activation vs errors 2021-08-18 08:56:57 +02:00
nd-core.h
nd.h
nd_virtio.c
of_pmem.c
pfn.h
pfn_devs.c
pmem.c libnvdimm/pmem: Fix crash triggered when I/O in-flight during unbind 2021-10-06 15:42:38 +02:00
pmem.h
region.c
region_devs.c libnvdimm/region: Fix nvdimm_has_flush() to handle ND_REGION_ASYNC 2021-04-21 12:56:16 +02:00
security.c
virtio_pmem.c
virtio_pmem.h