Skip to content

proc/vmcore: sanitize access to virtio-mem memory

David Hildenbrand kexec linux-fsdevel linux-mm lkml virtualization xen-devel 2 versions – Applied

Status from this message: [merged] virtio-mem-kdump-mode-to-sanitize-proc-vmcore-access.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest9 patches 2 repliesApplied 9/9
  2. v18 patches 7 repliesSuperseded

Changes in v2 from the cover letter

- "x86/xen: simplify xen_oldmem_pfn_is_ram()"
-- Simplify even more
- "x86/xen: print a warning when HVMOP_get_mem_type fails" -- Added
- "virtio-mem: kdump mode to sanitize /proc/vmcore access" -- Fix wrong range check

Patches in v2 All 9 applied

#Subject and filesSizeRepliesApplied
1/9x86/xen: update xen_oldmem_pfn_is_ram() documentationarch/x86/xen/mmu_hvm.c+3 -60 repliesApplied
2/9x86/xen: simplify xen_oldmem_pfn_is_ram()arch/x86/xen/mmu_hvm.c+1 -141 replyApplied
3/9x86/xen: print a warning when HVMOP_get_mem_type failsarch/x86/xen/mmu_hvm.c+3 -11 replyApplied
4/9proc/vmcore: let pfn_is_ram() return a boolfs/proc/vmcore.c+4 -40 repliesApplied
5/9proc/vmcore: convert oldmem_pfn_is_ram callback to more generic vmcore callbacksarch/x86/kernel/aperture_64.c arch/x86/xen/mmu_hvm.c fs/proc/vmcore.c +1 more+111 -380 repliesApplied
6/9virtio-mem: factor out hotplug specifics from virtio_mem_init() into virtio_mem_init_hotplug()drivers/virtio/virtio_mem.c+44 -370 repliesApplied
7/9virtio-mem: factor out hotplug specifics from virtio_mem_probe() into virtio_mem_init_hotplug()drivers/virtio/virtio_mem.c+45 -420 repliesApplied
8/9virtio-mem: factor out hotplug specifics from virtio_mem_remove() into virtio_mem_deinit_hotplug()drivers/virtio/virtio_mem.c+10 -30 repliesApplied
9/9virtio-mem: kdump mode to sanitize /proc/vmcore accessdrivers/virtio/virtio_mem.c+124 -120 repliesApplied

Reviews trailers per patch

3 of 9 patches have a Reviewed-by or Acked-by.

PatchBoris Ostrovsky
1/9R-b
2/9R-b
3/9R-b
4/9
5/9
6/9
7/9
8/9
9/9

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/9] proc/vmcore: sanitize access to virtio-mem memory

As so often with virtio-mem changes that mess with common MM infrastructure, this might be a good candiate to go via Andrew's tree.

--

After removing /dev/kmem, sanitizing /proc/kcore and handling /dev/mem, this series tackles the last sane way how a VM could accidentially access logically unplugged memory managed by a virtio-mem device: /proc/vmcore

When dumping memory via "makedumpfile", PG_offline pages, used by virtio-mem to flag logically unplugged memory, are already properly excluded; however, especially when accessing/copying /proc/vmcore "the usual way", we can still end up reading logically unplugged memory part of a virtio-mem device.

Patch #1-#3 are cleanups. Patch #4 extends the existing oldmem_pfn_is_ram mechanism. Patch #5-#7 are virtio-mem refactorings for patch #8, which implements the virtio-mem logic to query the state of device blocks.

Patch #8:

"
Although virtio-mem currently supports reading unplugged memory in the hypervisor, this will change in the future, indicated to the device via a new feature flag. We similarly sanitized /proc/kcore access recently. [...]
Distributions that support virtio-mem+kdump have to make sure that the virtio_mem module will be part of the kdump kernel or the kdump initrd; dracut was recently [2] extended to include virtio-mem in the generated initrd. As long as no special kdump kernels are used, this will automatically make sure that virtio-mem will be around in the kdump initrd and sanitize /proc/vmcore access -- with dracut.
"

This is the last remaining bit to support VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE [3] in the Linux implementation of virtio-mem.

Note: this is best-effort. We'll never be able to control what runs inside the second kernel, really, but we also don't have to care: we only care about sane setups where we don't want our VM getting zapped once we touch the wrong memory location while dumping. While we usually expect sane setups to use "makedumfile", nothing really speaks against just copying /proc/vmcore, especially in environments where HWpoisioning isn't typically expected. Also, we really don't want to put all our trust completely on the memmap, so sanitizing also makes sense when just using "makedumpfile".

[1] https://lkml.kernel.org/r/[email protected]
[2] https://github.com/dracutdevs/dracut/pull/1157
[3] https://lists.oasis-open.org/archives/virtio-comment/202109/msg00021.html

v1 -> v2:
- "x86/xen: simplify xen_oldmem_pfn_is_ram()"
-- Simplify even more
- "x86/xen: print a warning when HVMOP_get_mem_type fails" -- Added
- "virtio-mem: kdump mode to sanitize /proc/vmcore access" -- Fix wrong range check

Cc Andrew Morton <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Juergen Gross <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Jason Wang <[email protected]>
Cc Dave Young <[email protected]>
Cc Baoquan He <[email protected]>
Cc Vivek Goyal <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>

David Hildenbrand (9):
x86/xen: update xen_oldmem_pfn_is_ram() documentation x86/xen: simplify xen_oldmem_pfn_is_ram()
x86/xen: print a warning when HVMOP_get_mem_type fails proc/vmcore: let pfn_is_ram() return a bool
proc/vmcore: convert oldmem_pfn_is_ram callback to more generic vmcore
callbacks
virtio-mem: factor out hotplug specifics from virtio_mem_init() into
virtio_mem_init_hotplug()
virtio-mem: factor out hotplug specifics from virtio_mem_probe() into
virtio_mem_init_hotplug()
virtio-mem: factor out hotplug specifics from virtio_mem_remove() into
virtio_mem_deinit_hotplug()
virtio-mem: kdump mode to sanitize /proc/vmcore access

 arch/x86/kernel/aperture_64.c |  13 +-
 arch/x86/xen/mmu_hvm.c        |  37 ++---
 drivers/virtio/virtio_mem.c   | 297 ++++++++++++++++++++++++----------
 fs/proc/vmcore.c              | 105 ++++++++----
 include/linux/crash_dump.h    |  26 ++-
 5 files changed, 333 insertions(+), 145 deletions(-)

base-commit: 9e1ff307c779ce1f0f810c7ecce3d95bbae40896

Signature · 1 line
2.31.1