kvmppc_gse_parse() validates each element by comparing its length
against kvmppc_gsid_size() for its ID. For an ID that does not belong
to any guest state class, kvmppc_gsid_size() returns 0, so an element
with such an ID and a length of 0 passes the check.
kvmppc_gsp_insert() then calls kvmppc_gse_flatten_iden(), which returns
0 for an unclassified ID. That is the bitmap position of
KVMPPC_GSID_BLANK, so the element is stored in gses[0] and bit 0 is set
in the parser's iterator bitmap.
kvmppc_gsp_for_each() uses ID 0 as its terminator, and bit 0 maps back
to ID 0 in kvmppc_gse_unflatten_iden(). Because bit 0 is the lowest
position, the iteration ends on its first step and none of the other
parsed elements are visited. Callers such as
gs_msg_ops_vcpu_refresh_info() still return 0, so the vCPU state is left
stale without any error.
The buffer contents come from the L0 hypervisor, so L1 should reject an
element it cannot interpret instead of folding it onto an unrelated bit.
Every type in kvmppc_gse_iden_len[] has a non-zero size, so a size of 0
can only mean the ID has no defined type. Treat that as invalid and
return -EINVAL, the same as a length mismatch.
Fixes: 6ccbbc33f06a ("KVM: PPC: Add helper library for Guest State Buffers")
Cc: [email protected]
Signed-off-by: Amit Machhiwal <[email protected]>
---
arch/powerpc/kvm/guest-state-buffer.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/kvm/guest-state-buffer.c
b/arch/powerpc/kvm/guest-state-buffer.c
index aeb586ba4523..21466bc4741e 100644
--- a/arch/powerpc/kvm/guest-state-buffer.c
+++ b/arch/powerpc/kvm/guest-state-buffer.c
@@ -304,10 +304,17 @@ int kvmppc_gse_parse(struct kvmppc_gs_parser *gsp, struct
kvmppc_gs_buff *gsb)
{
struct kvmppc_gs_elem *curr;
int rem, i;
+ u16 size;
kvmppc_gsb_for_each_elem(i, curr, gsb, rem) {
- if (kvmppc_gse_len(curr) !=
- kvmppc_gsid_size(kvmppc_gse_iden(curr)))
+ size = kvmppc_gsid_size(kvmppc_gse_iden(curr));
+
+ /*
+ * A size of 0 means the ID is unknown (or has no defined
+ * type). Don't let a zero length element with such an ID
+ * slip through the length check below.
+ */
+ if (!size || kvmppc_gse_len(curr) != size)
return -EINVAL;
kvmppc_gsp_insert(gsp, kvmppc_gse_iden(curr), curr);
}
--
2.54.0 (Apple Git-157)