Skip to content

KVM: arm64: Fix a couple of latent bugs in user_mem_abort()

Fuad Tabba kvm kvmarm linux-arm-kernel 1 version Applied

Status from this message: Applied to fixes, thanks!

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 7 repliesApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/2KVM: arm64: Fix page leak in user_mem_abort() on atomic faultarch/arm64/kvm/mmu.c+8 -51 reply
2/2KVM: arm64: Fix vma_shift staleness on nested hwpoison patharch/arm64/kvm/mmu.c+1 -03 replies

Reviews trailers per patch

1 of 2 patches has a Reviewed-by or Acked-by.

PatchYuan Yao
1/2R-b
2/2

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

Read the v1 thread

Cover letter [PATCH v1 0/2] KVM: arm64: Fix a couple of latent bugs in user_mem_abort()

While digging into arch/arm64/kvm/mmu.c with the intention of finally refactoring user_mem_abort(), I ran into a couple of latent bugs that we should probably fix right now before attempting any major plumbing.

You might experience some deja-vu looking at the first patch. A while back (in 5f9466b50c1b), I fixed a struct page reference leak on an early error return in this exact same block. It turns out that another early exit was introduced later on (for exclusive/atomic faults), and it fell into the exact same trap of leaking the page.

The fact that this keeps happening really highlights how dangerous this "danger zone" between faulting in the PFN and taking the MMU lock has become. To stop playing whack-a-mole with inline kvm_release_page_unused() calls, I've routed all the early exits here to a unified out_put_page label so they are handled safely together.

The second patch addresses a staleness bug with vma_shift when handling nested stage-2 faults. We currently truncate the mapping size for the nested guest, but forget to update the shift, which results in us sending the wrong boundaries to userspace if we subsequently trip over a hardware poisoned page.

Finding these issues just reinforces how fragile this 300-line function has become. We really need to refactor it to make the state flow easier to reason about. I'm currently putting together a series to do just that (introducing a proper fault state object), so stay tuned for an RFC on that front.

Based on Linux 7.0-rc2.

Cheers,
/fuad

Fuad Tabba (2):
KVM: arm64: Fix page leak in user_mem_abort() on atomic fault
KVM: arm64: Fix vma_shift staleness on nested hwpoison path

 arch/arm64/kvm/mmu.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

base-commit: 11439c4635edd669ae435eec308f4ab8a0804808

Signature · 1 line
2.53.0.473.g4a7958ca14-goog