From: Amit Machhiwal <amachhiw@linux.ibm.com>
To: Madhavan Srinivasan <maddy@linux.ibm.com>, linuxppc-dev@lists.ozlabs.org
Cc: Amit Machhiwal <amachhiw@linux.ibm.com>,
Gautam Menghani <gautam@linux.ibm.com>,
Harsh Prateek Bora <harshpb@linux.ibm.com>,
Nicholas Piggin <npiggin@gmail.com>,
Michael Ellerman <mpe@ellerman.id.au>,
"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
Shrikanth Hegde <sshegde@linux.ibm.com>,
Jordan Niethe <jniethe5@gmail.com>,
kvm@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH 1/2] KVM: PPC: Reject unknown guest state IDs in kvmppc_gse_parse()
Date: Wed, 2 Dec 2026 23:46:29 +0530 [thread overview]
Message-ID: <20261202181630.21203-2-amachhiw@linux.ibm.com> (raw)
In-Reply-To: <20261202181630.21203-1-amachhiw@linux.ibm.com>
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: stable@vger.kernel.org
Signed-off-by: Amit Machhiwal <amachhiw@linux.ibm.com>
---
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)
next prev parent reply other threads:[~2026-12-02 18:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 18:16 [PATCH 0/2] KVM: PPC: Don't alias unclassified guest state IDs onto bit 0 Amit Machhiwal
2026-12-02 18:16 ` Amit Machhiwal [this message]
2026-12-02 18:16 ` [PATCH 2/2] KVM: PPC: Don't map " Amit Machhiwal
2026-12-02 18:21 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202181630.21203-2-amachhiw@linux.ibm.com \
--to=amachhiw@linux.ibm.com \
--cc=chleroy@kernel.org \
--cc=gautam@linux.ibm.com \
--cc=harshpb@linux.ibm.com \
--cc=jniethe5@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=ritesh.list@gmail.com \
--cc=sshegde@linux.ibm.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox