From: Sean Christopherson <seanjc@google.com>
To: Mathias Krause <minipli@grsecurity.net>
Cc: Paolo Bonzini <pbonzini@redhat.com>, kvm@vger.kernel.org
Subject: Re: [PATCH v3 5/5] KVM: selftests: Test vCPU boot IDs above 2^32
Date: Tue, 18 Jun 2024 14:50:13 -0700 [thread overview]
Message-ID: <ZnIBFWqPmiEKQiTO@google.com> (raw)
In-Reply-To: <20240614202859.3597745-6-minipli@grsecurity.net>
On Fri, Jun 14, 2024, Mathias Krause wrote:
> The KVM_SET_BOOT_CPU_ID ioctl missed to reject invalid vCPU IDs. Verify
> this no longer works and gets rejected with an appropriate error code.
>
> Signed-off-by: Mathias Krause <minipli@grsecurity.net>
> ---
> tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c b/tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c
> index d691d86e5bc3..50a0c3f61baf 100644
> --- a/tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c
> +++ b/tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c
> @@ -33,6 +33,13 @@ static void guest_not_bsp_vcpu(void *arg)
> GUEST_DONE();
> }
>
> +static void test_set_invalid_bsp(struct kvm_vm *vm)
> +{
> + int r = __vm_ioctl(vm, KVM_SET_BOOT_CPU_ID, (void *)(1L << 32));
> +
I also added a test to verify KVM_CAP_MAX_VCPU_ID+1 also fails, because why not.
unsigned long max_vcpu_id = vm_check_cap(vm, KVM_CAP_MAX_VCPU_ID);
int r;
if (max_vcpu_id) {
r = __vm_ioctl(vm, KVM_SET_BOOT_CPU_ID, (void *)(max_vcpu_id + 1));
TEST_ASSERT(r == -1 && errno == EINVAL, "BSP with ID > MAX should fail");
}
r = __vm_ioctl(vm, KVM_SET_BOOT_CPU_ID, (void *)(1L << 32));
TEST_ASSERT(r == -1 && errno == EINVAL, "BSP with ID[63:32]!=0 should fail");
> + TEST_ASSERT(r == -1 && errno == EINVAL, "invalid KVM_SET_BOOT_CPU_ID set");
> +}
> +
> static void test_set_bsp_busy(struct kvm_vcpu *vcpu, const char *msg)
> {
> int r = __vm_ioctl(vcpu->vm, KVM_SET_BOOT_CPU_ID,
> @@ -75,11 +82,15 @@ static void run_vcpu(struct kvm_vcpu *vcpu)
> static struct kvm_vm *create_vm(uint32_t nr_vcpus, uint32_t bsp_vcpu_id,
> struct kvm_vcpu *vcpus[])
> {
> + static int invalid_bsp_tested;
> struct kvm_vm *vm;
> uint32_t i;
>
> vm = vm_create(nr_vcpus);
>
> + if (!invalid_bsp_tested++)
I dropped this and just had every VM run the negative test. There's zero chance
anyone will ever notice an extra failed ioctl() or three, whereas it took me a
second to realize this is just a somewhat lazy way of writing a one-off negative
test.
> + test_set_invalid_bsp(vm);
> +
> vm_ioctl(vm, KVM_SET_BOOT_CPU_ID, (void *)(unsigned long)bsp_vcpu_id);
>
> for (i = 0; i < nr_vcpus; i++)
> --
> 2.30.2
>
next prev parent reply other threads:[~2024-06-18 21:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-14 20:28 [PATCH v3 0/5] KVM: Reject vCPU IDs above 2^32 Mathias Krause
2024-06-14 20:28 ` [PATCH v3 1/5] KVM: Reject overly excessive IDs in KVM_CREATE_VCPU Mathias Krause
2024-06-18 21:43 ` Sean Christopherson
2024-06-14 20:28 ` [PATCH v3 2/5] KVM: x86: Limit check IDs for KVM_SET_BOOT_CPU_ID Mathias Krause
2024-06-14 20:28 ` [PATCH v3 3/5] KVM: x86: Prevent excluding the BSP on setting max_vcpu_ids Mathias Krause
2024-06-14 20:28 ` [PATCH v3 4/5] KVM: selftests: Test max vCPU IDs corner cases Mathias Krause
2024-06-18 21:46 ` Sean Christopherson
2024-06-14 20:28 ` [PATCH v3 5/5] KVM: selftests: Test vCPU boot IDs above 2^32 Mathias Krause
2024-06-18 21:50 ` Sean Christopherson [this message]
2024-06-18 21:41 ` [PATCH v3 0/5] KVM: Reject vCPU " Sean Christopherson
2024-06-19 6:28 ` Mathias Krause
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=ZnIBFWqPmiEKQiTO@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=minipli@grsecurity.net \
--cc=pbonzini@redhat.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.