FAILED: patch "[PATCH] RISC-V: KVM: Fix sdata leak and stale snapshot_addr in" failed to apply to 7.2-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 7.2-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-7.2.y
git checkout FETCH_HEAD
git cherry-pick -x b7749531a9b195f4fd7db92ca3cc49bda1a4dc8d
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026092909-encrypt-stainless-6564@gregkh' --subject-prefix 'PATCH 7.2.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From b7749531a9b195f4fd7db92ca3cc49bda1a4dc8d Mon Sep 17 00:00:00 2001
From: Zongmin Zhou <[email protected]>
Date: Wed, 26 Aug 2026 14:41:17 +0800
Subject: [PATCH] RISC-V: KVM: Fix sdata leak and stale snapshot_addr in
snapshot_set_shmem
A guest may call SBI_PMU_SNAPSHOT_SET_SHMEM repeatedly. Each call overwrites kvpmu->sdata without freeing the old buffer (memory leak), and if a later kvm_vcpu_write_guest() fails, the error path frees sdata but leaves snapshot_addr stale. A subsequent SBI_PMU_COUNTER_START then passes the INVALID_GPA check and crashes the host with a NULL buffer in kvm_vcpu_read_guest().
Fix this by clearing the previously installed snapshot area before installing a new one, which keeps sdata and snapshot_addr consistent. The SBI spec suggests a single invocation but defines no error code for repeated calls, so KVM must tolerate them.
arch/riscv/kvm/vcpu_pmu.c +8 -0
@@ -454,6 +454,14 @@ int kvm_riscv_vcpu_pmu_snapshot_set_shmem(struct kvm_vcpu *vcpu, unsigned long s } } +/* +* Clear any previously installed snapshot area to avoid leaking +* the old sdata and to keep sdata/snapshot_addr consistent if +* the re-install fails below. +*/ +if (kvpmu->snapshot_addr !=INVALID_GPA ) +kvm_pmu_clear_snapshot_area (vcpu); + kvpmu->sdata =kzalloc (snapshot_area_size,GFP_ATOMIC | __GFP_ACCOUNT);if (!kvpmu->sdata) { sbiret =SBI_ERR_FAILURE ;