All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Suzuki K Poulose" <suzuki.poulose@arm.com>
Cc: "Oliver Upton" <oupton@kernel.org>,
	kvmarm@lists.linux.dev, "Marc Zyngier" <maz@kernel.org>,
	kvm@vger.kernel.org
Subject: Re: [PATCH v18 01/23] KVM: arm64: protected VM: Handle set_one_reg CNTVCT_EL0/CNTPCT_EL0
Date: Tue, 15 Sep 2026 16:18:54 +0000	[thread overview]
Message-ID: <20260915161855.32AEF1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260915160141.3543048-2-suzuki.poulose@arm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] kvm: arm64: pKVM: protected VM timer offset vulnerable to host TOCTOU
--

commit 960552f9d7645214acac73b01e88ba381530e333
Author: Suzuki K Poulose <suzuki.poulose@arm.com>
Date:   Tue Sep 15 16:01:19 2026 +0000

    KVM: arm64: protected VM: Handle set_one_reg CNTVCT_EL0/CNTPCT_EL0
    
This commit fixes a WARN() in timer_set_offset() caused by userspace writing
to CNTVCT/CNTPCT registers for protected VMs. It accomplishes this by setting
the timer offsets to 0 and marking the offset initialized at pKVM init time,
removing the need for the vm_offset pointer to be NULL.

Link: https://lore.kernel.org/all/20260908164641.416911F00A3A@smtp.kernel.org

[ ... ]
> diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> index 459bd9eb7e4bc..e7b38eff63bd1 100644
> --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c
> +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> @@ -528,19 +528,19 @@ static int init_pkvm_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu,
>  	hyp_vcpu->vcpu.arch.cflags = READ_ONCE(host_vcpu->arch.cflags);
>  	hyp_vcpu->vcpu.arch.mp_state.mp_state = KVM_MP_STATE_STOPPED;
>  
> -	if (!pkvm_hyp_vcpu_is_protected(hyp_vcpu)) {
> -		/*
> -		 * Timer offsets are pointing to the untrusted KVM copy,
> -		 * which is pinned in __pkvm_init_vm() for the VM life time.
> -		 * It is worth noting that hyp_vm->host_kvm points to an EL2
> -		 * linear map address and timer_get_offset() will use
> -		 * kern_hyp_va() which is safe as it is idempotent.
> -		 */
> -		vcpu_vtimer(&hyp_vcpu->vcpu)->offset.vm_offset =
> -			&hyp_vm->host_kvm->arch.timer_data.voffset;
> -		vcpu_ptimer(&hyp_vcpu->vcpu)->offset.vm_offset =
> -			&hyp_vm->host_kvm->arch.timer_data.poffset;
> -	}
> +	/*
> +	 * Timer offsets are pointing to the untrusted KVM copy,
> +	 * which is pinned in __pkvm_init_vm() for the VM life time.
> +	 * It is worth noting that hyp_vm->host_kvm points to an EL2
> +	 * linear map address and timer_get_offset() will use
> +	 * kern_hyp_va() which is safe as it is idempotent.
> +	 * Also for protected VMs the offset is fixed to 0 and is prevented
> +	 * from changing.
> +	 */
> +	vcpu_vtimer(&hyp_vcpu->vcpu)->offset.vm_offset =
> +		&hyp_vm->host_kvm->arch.timer_data.voffset;
> +	vcpu_ptimer(&hyp_vcpu->vcpu)->offset.vm_offset =
> +		&hyp_vm->host_kvm->arch.timer_data.poffset;

[Severity: High]
Does this change introduce a TOCTOU regression for protected VMs? By removing
the !pkvm_hyp_vcpu_is_protected() check in init_pkvm_hyp_vcpu(), the protected
VM's vm_offset is now unconditionally assigned to point to the untrusted host
memory back-pointer (hyp_vm->host_kvm).

Under the pKVM threat model, the host kernel is untrusted. If the host
modifies the voffset or poffset in its timer_data at runtime, EL2 will read
this manipulated value. This could allow a compromised host kernel to alter
the virtual and physical timer offsets observed by a protected VM, violating
guest integrity.

Should the offset instead be derived from the EL2-private &hyp_vm->kvm
structure or statically set to 0 for protected VMs?

[ ... ]
> diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h
> index bc6f2fdd7ad33..4f0aa3bb69f45 100644
> --- a/include/kvm/arm_arch_timer.h
> +++ b/include/kvm/arm_arch_timer.h
> @@ -176,8 +176,7 @@ static inline bool has_cntpoff(void)
>  		if (__ctxt) {						\
>  			struct arch_timer_offset *ato = &__ctxt->offset;\
>  									\
> -			if (ato->vm_offset)				\
> -				off += *KERN_HYP_VA(ato->vm_offset);	\
> +			off += *KERN_HYP_VA(ato->vm_offset);		\
>  			if (ato->vcpu_offset)				\
>  				off += *KERN_HYP_VA(ato->vcpu_offset);	\
>  		}							\

[Severity: High]
Since the pointer is now unconditionally assigned to host memory for protected
VMs, EL2 will dereference this host-controlled pointer here in
timer_get_offset() via KERN_HYP_VA(). Can this cause the hypervisor to read a
security-sensitive value from untrusted host memory?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260915160141.3543048-1-suzuki.poulose@arm.com?part=1

  reply	other threads:[~2026-09-15 16:18 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15 16:01 [PATCH v18 00/23] KVM: arm64: CCA: Add basic plumbing for Realms Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 01/23] KVM: arm64: protected VM: Handle set_one_reg CNTVCT_EL0/CNTPCT_EL0 Suzuki K Poulose
2026-09-15 16:18   ` sashiko-bot [this message]
2026-09-15 16:46   ` Marc Zyngier
2026-09-15 17:48     ` Suzuki K Poulose
2026-09-15 21:20       ` Suzuki K Poulose
2026-09-16  8:16         ` Marc Zyngier
2026-09-16  8:27           ` Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 02/23] KVM: arm64: Disable Steal time accounting for protected guests Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 03/23] KVM: arm64: Include kvm_emulate.h in kvm/arm_psci.h Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 04/23] KVM: arm64: Avoid including linux/kvm_host.h in kvm_pgtable.h Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 05/23] KVM: arm64: Track the type of VM in kvm_arch Suzuki K Poulose
2026-09-17 11:24   ` Fuad Tabba
2026-09-18  8:59     ` Suzuki K Poulose
2026-09-18  9:14       ` Fuad Tabba
2026-09-18  9:47         ` Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 06/23] KVM: arm64: Refactor the vcpu_load to allow for VM specific callbacks Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 07/23] KVM: arm64: Add vcpu load/put call backs for flavors Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 08/23] KVM: arm64: Reuse kvm_stage2_unmap_range in kvm_unmap_gfn_range Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 09/23] KVM: arm64: Add VM specific callback for S2 MMU operations Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 10/23] KVM: arm64: Abstract out memory abort handling Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 11/23] KVM: arm64: Use kvm_vm_is_unprotected() for !kvm_vm_is_protected() Suzuki K Poulose
2026-09-17 11:47   ` Fuad Tabba
2026-09-17 16:47     ` Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 12/23] KVM: arm64: Widen the scope of "protected" VMs Suzuki K Poulose
2026-09-17 11:44   ` Marc Zyngier
2026-09-17 17:06     ` Suzuki K Poulose
2026-09-17 11:51   ` Fuad Tabba
2026-09-17 16:48     ` Suzuki K Poulose
2026-09-17 14:16   ` Joey Gouly
2026-09-15 16:01 ` [PATCH v18 13/23] KVM: arm64: Add a helper for VMs running on hyp that don't trust the host Suzuki K Poulose
2026-09-17 11:55   ` Fuad Tabba
2026-09-15 16:01 ` [PATCH v18 14/23] KVM: arm64: CCA: Add a new mode for supporting Realm guests Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 15/23] KVM: arm64: CCA: Add VCPU load/put for Realms Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 16/23] KVM: arm64: CCA: Add bare minimal S2 operations for Realm Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 17/23] KVM: arm64: CCA: Introduce Realms Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 18/23] KVM: arm64: CCA: Mandate VGIC_V3 for Realms Suzuki K Poulose
2026-09-17 12:57   ` Fuad Tabba
2026-09-15 16:01 ` [PATCH v18 19/23] KVM: arm64: CCA: Support timers in realm RECs Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 20/23] KVM: arm64: CCA: Don't expose unsupported capabilities for realm guests Suzuki K Poulose
2026-09-15 16:43   ` sashiko-bot
2026-09-15 17:55     ` Suzuki K Poulose
2026-09-16  8:29       ` Suzuki K Poulose
2026-09-17 13:16   ` Fuad Tabba
2026-09-17 14:56     ` Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 21/23] KVM: arm64: CCA: WARN on injected undef exceptions Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 22/23] KVM: arm64: CCA: Expose SVE VL register before VCPU finalization Suzuki K Poulose
2026-09-15 16:01 ` [PATCH v18 23/23] KVM: arm64: CCA: Control user register access for Realms Suzuki K Poulose
2026-09-15 16:49   ` sashiko-bot
2026-09-15 17:51     ` Suzuki K Poulose
2026-09-16 19:23 ` [PATCH v18 00/23] KVM: arm64: CCA: Add basic plumbing " Mathieu Poirier
2026-09-22  9:22   ` Aneesh Kumar K.V
2026-09-23 14:32     ` Mathieu Poirier
2026-09-17 14:32 ` Fuad Tabba

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=20260915161855.32AEF1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=suzuki.poulose@arm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.