Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Leonardo Bras" <leo.bras@arm.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v2 2/5] KVM: selftests: memstress: Add option to enable dirty-ring on VM creation
Date: Fri, 09 Oct 2026 13:11:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-165604@kernel.org> (raw)
In-Reply-To: <20261009130054.3312154-4-leo.bras@arm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] kvm: selftests: missing KVM_MAX_VCPUS bounds check in memstress_vm_create_with_vcpus()
--

commit 8f8ed5a2bb5936b315dc077d1f97ad188346d5a2
Author: Leonardo Bras <leo.bras@arm.com>

KVM: selftests: memstress: Add option to enable dirty-ring on VM creation

This commit adds an option to memstress_create_vm() to take a dirty-ring size
and enables it before vCPU creation. It introduces a new function
memstress_vm_create_with_vcpus() to handle this setup correctly.

> diff --git a/tools/testing/selftests/kvm/lib/memstress.c b/tools/testing/selftests/kvm/lib/memstress.c
> index 880657df65e9e..b1f13499e85f4 100644
> --- a/tools/testing/selftests/kvm/lib/memstress.c
> +++ b/tools/testing/selftests/kvm/lib/memstress.c
> @@ -121,6 +121,27 @@ void memstress_setup_vcpus(struct kvm_vm *vm, int nr_vcpus,

[ ... ]

> +static struct kvm_vm *memstress_vm_create_with_vcpus(struct memstress_params *params,
> +						     u64 extra_mem_pages)
> +{
> +	struct kvm_vm *vm;
> +	int i;
> +
> +	TEST_ASSERT(params->nr_vcpus > 0, "Invalid number of vCPUs (%d)",
> +		    params->nr_vcpus);
> +
> +	vm = __vm_create(VM_SHAPE(params->mode), params->nr_vcpus, extra_mem_pages);
> +
> +	if (params->dirty_ring_size)
> +		vm_enable_dirty_ring(vm, params->dirty_ring_size);
> +
> +	for (i = 0; i < params->nr_vcpus; ++i)

[Severity: High]
Can this loop overflow the statically sized vcpus array?

The vcpus array is bounded by KVM_MAX_VCPUS (512). When a user runs a
memstress-based test with an argument greater than 512 on a host kernel where
KVM_CAP_MAX_VCPUS is greater than 512, or runs mmu_stress_test on a host with
more than ~682 physical cores, the option parser checks against
KVM_CAP_MAX_VCPUS but not against KVM_MAX_VCPUS.

Passing this unbounded params->nr_vcpus value to
memstress_vm_create_with_vcpus() will blindly write past the end of the vcpus
array, causing memory corruption and crashing the selftest.

> +		vcpus[i] = vm_vcpu_add(vm, i, memstress_guest_code);
> +
> +	kvm_arch_vm_finalize_vcpus(vm);
> +	return vm;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261009130054.3312154-2-leo.bras@arm.com?part=2

  reply	other threads:[~2026-10-09 13:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09 13:00 [PATCH v2 0/5] KVM: selftests: Add support for dirty-ring on dirty_log_perf_test Leonardo Bras
2026-10-09 13:00 ` [PATCH v2 1/5] KVM: selftests: memstress: Add struct memstress_params, make memstress_create_vm() use it Leonardo Bras
2026-10-09 13:00 ` [PATCH v2 2/5] KVM: selftests: memstress: Add option to enable dirty-ring on VM creation Leonardo Bras
2026-10-09 13:11   ` sashiko-bot [this message]
2026-10-09 13:00 ` [PATCH v2 3/5] KVM: selftests: Introduce kvm_get_dirty_ring_cap() Leonardo Bras
2026-10-09 13:00 ` [PATCH v2 4/5] KVM: selftests: Check dirty-ring size before enabling Leonardo Bras
2026-10-09 13:00 ` [PATCH v2 5/5] KVM: selftests: dirty_log_perf_test: Add dirty-ring support Leonardo Bras

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-165604@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=leo.bras@arm.com \
    --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