Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Amit Machhiwal" <amachhiw@linux.ibm.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v4 3/3] KVM: PPC: Fix get_d_signext() 12-bit displacement for paired-single D-form
Date: Wed, 07 Oct 2026 18:35:35 +0000	[thread overview]
Message-ID: <sashiko-outbox-163294@kernel.org> (raw)
In-Reply-To: <20261007182608.17188-1-amachhiw@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] kvm: ppc: out-of-bounds host memory access in magic page emulation
--

commit 7a374e4096a679cdf2566d00b45341748bfbac50
Author: Amit Machhiwal <amachhiw@linux.ibm.com>

KVM: PPC: Fix get_d_signext() 12-bit displacement for paired-single D-form

This commit fixes two compounding bugs in get_d_signext() related to
12-bit D-form displacements for paired-single instructions. It replaces
open-coded logic with sign_extend32 to correctly handle bit extraction
and two's-complement sign extension.

> diff --git a/arch/powerpc/kvm/book3s_paired_singles.c b/arch/powerpc/kvm/book3s_paired_singles.c
> index bc39c76c9d9fe..532f96293de0f 100644
> --- a/arch/powerpc/kvm/book3s_paired_singles.c
> +++ b/arch/powerpc/kvm/book3s_paired_singles.c
> @@ -479,12 +479,7 @@ static bool kvmppc_inst_is_paired_single(struct kvm_vcpu *vcpu, u32 inst)
>  
>  static int get_d_signext(u32 inst)
>  {
> -	int d = inst & 0x8ff;
> -
> -	if (d & 0x800)
> -		return -(d & 0x7ff);
> -
> -	return (d & 0x7ff);
> +	return sign_extend32(inst & 0xfff, 11);
>  }

[Severity: Critical]
By fixing the negative displacement calculation here, does this allow 
negative displacements (like -4 encoding to 0xffc) to reach the magic page 
emulation in kvmppc_st() and kvmppc_ld() without bounds checking?

For example, in arch/powerpc/kvm/powerpc.c:kvmppc_st():

	/* Magic page override */
	if (kvmppc_supports_magic_page(vcpu) && mp_pa &&
	    ((pte.raddr & KVM_PAM & PAGE_MASK) == mp_pa) &&
	    !(kvmppc_get_msr(vcpu) & MSR_PR)) {
		void *magic = vcpu->arch.shared;
		magic += pte.eaddr & 0xfff;
		memcpy(magic, ptr, size);
		return EMULATE_DONE;
	}

If a guest VM sets up a base register pointing to the magic page and 
executes an 8-byte memory access instruction (like psq_st or lfd) with an 
offset that translates to 0xffc, could this memcpy copy 8 bytes starting 
at offset 0xffc, overflowing the 4096-byte vcpu->arch.shared page?

A similar situation appears to exist in kvmppc_ld():

	/* Magic page override */
	if (kvmppc_supports_magic_page(vcpu) && mp_pa &&
	    ((pte.raddr & KVM_PAM & PAGE_MASK) == mp_pa) &&
	    !(kvmppc_get_msr(vcpu) & MSR_PR)) {
		void *magic = vcpu->arch.shared;
		magic += pte.eaddr & 0xfff;
		memcpy(ptr, magic, size);
		return EMULATE_DONE;
	}

Could this allow an 8-byte copy to read out-of-bounds host memory when 
the offset is 0xffc?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261007182116.12479-1-amachhiw@linux.ibm.com?part=3

      reply	other threads:[~2026-10-07 18:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07 18:21 [PATCH v4 0/3] KVM: PPC: Fixes for Book3S HV HPT locking and paired-single decoding Amit Machhiwal
2026-10-07 18:21 ` [PATCH v4 1/3] KVM: PPC: Book3S HV: Add SRCU protection for virtual-mode HPT hcalls Amit Machhiwal
2026-10-07 18:21 ` [PATCH v4 2/3] KVM: PPC: Book3S HV: Add preempt_disable() around virtual-mode HPTE bit-lock users Amit Machhiwal
2026-10-07 18:47   ` sashiko-bot
2026-10-07 19:30     ` Amit Machhiwal
2026-10-07 18:26 ` [PATCH v4 3/3] KVM: PPC: Fix get_d_signext() 12-bit displacement for paired-single D-form Amit Machhiwal
2026-10-07 18:35   ` sashiko-bot [this message]

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=sashiko-outbox-163294@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amachhiw@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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