Re: [PATCH v6 28/33] KVM: s390: Add basic arm64 kvm module

[email protected]
Newsgroups dev.linux.lists.kvmarm,org.kernel.vger.kvm,org.kernel.vger.linux-s390
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Integer underflow in `kvm_max_guest_address()` bypasses KVM IPA limit validation for systems with less than 1GB of max address.
--

--- Patch [28]: [PATCH v6 28/33] KVM: s390: Add basic arm64 kvm module ---
commit 57ce89696f07b8212cf2fc85a369b60b1ec4f89b
Author: Steffen Eiden <[email protected]>

KVM: s390: Add basic arm64 kvm module

This commit adds the initial architecture-specific KVM infrastructure for
supporting arm64 guests on s390 hosts. It includes basic module
initialization, tracepoint scaffolding, and API skeleton functions.

> diff --git a/arch/s390/kvm/arm64/arm.c b/arch/s390/kvm/arm64/arm.c
> new file mode 100644
> index 0000000000000..8e17b7eef8131
> --- /dev/null
> +++ b/arch/s390/kvm/arm64/arm.c

[ ... ]

> +static u64 kvm_max_guest_address(void)
> +{
> +	u64 max_addr;
> +
> +	if (sclp.hamax == U64_MAX)
> +		max_addr = TASK_SIZE_MAX;
> +	else
> +		max_addr = min_t(u64, TASK_SIZE_MAX, sclp.hamax);
> +	return ALIGN_DOWN(max_addr + 1, 1 << 30) - 1;

[Severity: High]
Can this underflow if max_addr + 1 is less than 1GB (1 << 30)?

On a system with a small maximum address limit, ALIGN_DOWN() will evaluate 
to 0. Subtracting 1 from 0 will result in a U64_MAX return value, bypassing 
the intended limit.

> +}

[ ... ]

> +u32 get_kvm_ipa_limit(void)
> +{
> +	return fls64(kvm_max_guest_address() + 1) - 1;

[Severity: High]
If kvm_max_guest_address() underflows to U64_MAX as mentioned above, does 
this cause get_kvm_ipa_limit() to return U32_MAX?

Adding 1 to U64_MAX wraps to 0. Calling fls64(0) - 1 would then evaluate
to U32_MAX. This effectively disables the IPA size limit validation in
kvm_vm_type_ipa_size_shift(), allowing userspace to request unsupported
IPA sizes during VM creation.

> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=28
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.