Skip to content

Drivers: hv: vmbus: Harden the ring buffer against a malicious host

Kameron Carr linux-hyperv lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest5 patches 4 repliesIn review
  2. v14 patches 5 repliesSuperseded

Changes in v2 from the cover letter

- hv_ringbuffer_index_valid() -> hv_ringbuffer_indices_invalid() combines read and write checks and reverses the polarity
- hv_pkt_iter_avail() reuses hv_ringbuffer_avail_read() arithmetic
- Document the need to validate ringbuffer indices

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5Drivers: hv: vmbus: Bounds check the shared ring buffer indicesdrivers/hv/ring_buffer.c+16 -130 replies
2/5Drivers: hv: vmbus: Use *_ONCE() to access shared ring buffer indicesdrivers/hv/ring_buffer.c include/linux/hyperv.h+6 -130 replies
3/5Drivers: hv: vmbus: Compute ring byte counts from a caller-held snapshotdrivers/hv/ring_buffer.c include/linux/hyperv.h+61 -571 reply
4/5Drivers: hv: vmbus: Keep the ring byte counts sane for a bad indexdrivers/hv/ring_buffer.c include/linux/hyperv.h+18 -21 reply
5/5Documentation: hyperv: Describe validation of the ring buffer indicesDocumentation/virt/hyperv/coco.rst+4 -11 reply

Reviews trailers per patch

All 5 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchMichael KelleyMitchell Levy (Microsoft)
SeriesR-b
1/5R-b
2/5R-b
3/5R-b
4/5R-b
5/5R-b

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/5] Drivers: hv: vmbus: Harden the ring buffer against a malicious host

In a CoCo VM the host is untrusted. Since the VMBus ring buffer read and write indices live in shared memory, the guest has to treat both as potentially malicious and as changing at any time. This patch series adds bounds checking and reuses the validated indices instead of re-accessing them.

Patch 1 contains the minimum security fix, and is the only patch in the series intended to be backported. hv_ringbuffer_write() copies into the ring at the write index, so a malicious host can make the guest write to memory outside the ring buffer. This is reachable on any channel a CoCo VM accepts.

Patches 2 and 3 add READ/WRITE_ONCE annotations and refactor the helper functions to allow the caller to work with a consistent snapshot of the ring buffer indices.

Patch 4 adds the rest of the bounds checking. The memcopy() in hv_pkt_iter_avail() can only result in an out-of-bounds read if rbi->pkt_buffer_size exceeds the ring's data size. KVP is the only in-tree channel whose max_pkt_size exceeds its ring's data size (16K vs 12K on a 4K page guest). CoCo VMs reject the KVP channel, so this bug is currently unreachable on CoCo VMs. The other paths patch 4 checks can't cause a bad access, only a nonsense byte count or a wrong signaling decision.

Patch 1 applies cleanly to v5.15 and later. The unchecked write goes back to the original driver, but the host is only untrusted in CoCo VMs, which Linux has supported since v5.12, so patch 1's Fixes tag points at the original driver while its stable tag starts at 5.15.x.

---
v2:
- hv_ringbuffer_index_valid() -> hv_ringbuffer_indices_invalid() combines read and write checks and reverses the polarity
- hv_pkt_iter_avail() reuses hv_ringbuffer_avail_read() arithmetic
- Document the need to validate ringbuffer indices

v1: https://lore.kernel.org/all/[email protected]/

Kameron Carr (5):
Drivers: hv: vmbus: Bounds check the shared ring buffer indices
Drivers: hv: vmbus: Use *_ONCE() to access shared ring buffer indices
Drivers: hv: vmbus: Compute ring byte counts from a caller-held snapshot
Drivers: hv: vmbus: Keep the ring byte counts sane for a bad index
Documentation: hyperv: Describe validation of the ring buffer indices

 Documentation/virt/hyperv/coco.rst |   5 +-
 drivers/hv/ring_buffer.c           | 118 ++++++++++++++++---------------------
 include/linux/hyperv.h             |  58 ++++++++++++++----
 3 files changed, 100 insertions(+), 81 deletions(-)

---
base-commit: 72d3fcf802c45d00b300f25b848a93c3a2bd7c7e