All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jörg Rödel" <joro@8bytes.org>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3 7/8] KVM: selftests: Test the SNP APIC-ID-list GHCB request
Date: Mon, 02 Nov 2026 11:56:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-193358@kernel.org> (raw)
In-Reply-To: <20261102114137.1198982-8-joro@8bytes.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] KVM: selftests: 32-bit nr_vcpus passed to 64-bit va_arg in run_apic_id_test()
--

commit 3cc5f05e1197383f380887a6674ec843f8015520
Author: Joerg Roedel <joerg.roedel@amd.com>

KVM: selftests: Test the SNP APIC-ID-list GHCB request

This commit adds a KVM selftest exercising the GET_AP_APIC_IDS NAE event from
an SNP guest, testing valid requests, missing RAX validity, zero-sized
requests, invalid GPAs, and the 1024-vCPU descriptor boundary.

> diff --git a/tools/testing/selftests/kvm/x86/sev_snp_apic_id_test.c b/tools/testing/selftests/kvm/x86/sev_snp_apic_id_test.c
> new file mode 100644
> index 0000000000000..8ad9c15091c2d
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/x86/sev_snp_apic_id_test.c

[ ... ]

> +static void guest_code(void *ghcb, gpa_t ghcb_gpa, void *list,
> +		       gpa_t list_gpa, struct apic_id_results *results,
> +		       u64 expected_vcpus)
> +{

[ ... ]

> +	do_get_apic_ids(ghcb, list_gpa, 2, true);
> +	results->valid_info1 = ghcb_get_field(ghcb, GHCB_SAVE_SW_EXIT_INFO_1_OFFSET);
> +	results->valid_info2 = ghcb_get_field(ghcb, GHCB_SAVE_SW_EXIT_INFO_2_OFFSET);
> +	results->nr_entries = desc->nr_entries;
> +	results->first_apic_id = desc->apic_ids[0];
> +	results->last_apic_id = desc->apic_ids[expected_vcpus - 1];
> +
> +terminate:
> +	wrmsr(MSR_AMD64_SEV_ES_GHCB, GHCB_MSR_TERM_REQ);
> +	vmgexit();
> +}
> +
> +static void run_apic_id_test(unsigned int nr_vcpus)
> +{
> +	struct apic_id_results *results;
> +	struct kvm_vcpu *vcpu;
> +	struct kvm_vm *vm;
> +	gva_t ghcb_gva, list_gva, results_gva;
> +	gpa_t ghcb_gpa, list_gpa;
> +	unsigned int i;
> +
> +	kvm_set_files_rlimit(nr_vcpus);
> +	vm = vm_sev_create_with_one_vcpu(KVM_X86_SNP_VM, guest_code, &vcpu);
> +	for (i = 1; i < nr_vcpus; i++)
> +		__vm_vcpu_add(vm, i);
> +
> +	ghcb_gva = vm_alloc_shared(vm, PAGE_SIZE, KVM_UTIL_MIN_VADDR,
> +				   MEM_REGION_TEST_DATA);
> +	list_gva = vm_alloc_shared(vm, 2 * PAGE_SIZE, KVM_UTIL_MIN_VADDR,
> +				   MEM_REGION_TEST_DATA);
> +	results_gva = vm_alloc_shared(vm, PAGE_SIZE, KVM_UTIL_MIN_VADDR,
> +				      MEM_REGION_TEST_DATA);
> +	ghcb_gpa = addr_gva2gpa(vm, ghcb_gva);
> +	list_gpa = addr_gva2gpa(vm, list_gva);
> +	results = addr_gva2hva(vm, results_gva);
> +
> +	vcpu_args_set(vcpu, 6, ghcb_gva, ghcb_gpa, list_gva, list_gpa,
> +		      results_gva, nr_vcpus);

[Severity: Medium]
In run_apic_id_test(), nr_vcpus is declared as unsigned int (32-bit) and
passed without a cast as the 6th variadic argument to vcpu_args_set().

In C, default argument promotions do not widen unsigned int to 64 bits, while
tools/testing/selftests/kvm/lib/x86/processor.c:vcpu_args_set() extracts all
variadic arguments as 64-bit u64 values:

    if (num >= 6)
        regs.r9 = va_arg(ap, u64);

Because the first six arguments to vcpu_args_set() consume all six integer
argument registers on x86-64, nr_vcpus is passed on the stack. A 32-bit store
to that stack slot leaves the upper 32 bits uninitialized, and va_arg(ap, u64)
loads all 64 bits into regs.r9, which guest_code() receives as u64
expected_vcpus and uses to index desc->apic_ids[expected_vcpus - 1].

Can this result in reading uninitialized upper bits in expected_vcpus and
indexing out of bounds in desc->apic_ids[]? Should nr_vcpus be cast to u64 (or
declared as u64) when passed to vcpu_args_set()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261102114137.1198982-1-joro@8bytes.org?part=7

  reply	other threads:[~2026-11-02 11:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02 11:41 [PATCH v3 0/8] KVM: SVM: Support direct setting of VMSA for SEV-SNP guests Jörg Rödel
2026-11-02 11:41 ` [PATCH v3 1/8] KVM: SEV: Document SNP direct VMSA userspace ABI Jörg Rödel
2026-11-02 11:41 ` [PATCH v3 2/8] KVM: SVM: Implement GET_AP_APIC_IDS NAE event Jörg Rödel
2026-11-02 11:52   ` sashiko-bot
2026-11-02 12:22     ` Jörg Rödel
2026-11-04 20:20       ` Sean Christopherson
2026-11-02 11:41 ` [PATCH v3 3/8] KVM: SVM: Hold SRCU while reloading guest-owned VMSAs Jörg Rödel
2026-11-02 11:53   ` sashiko-bot
2026-11-02 12:29     ` Jörg Rödel
2026-11-02 11:41 ` [PATCH v3 4/8] KVM: SEV: Add direct VMSA capability Jörg Rödel
2026-11-02 12:02   ` sashiko-bot
2026-11-03  4:51   ` kernel test robot
2026-11-02 11:41 ` [PATCH v3 5/8] KVM: SEV: Allow VMSA pages in SNP launch updates Jörg Rödel
2026-11-02 11:41 ` [PATCH v3 6/8] KVM: SEV: Add SNP vCPU state get and set commands Jörg Rödel
2026-11-02 12:07   ` sashiko-bot
2026-11-02 11:41 ` [PATCH v3 7/8] KVM: selftests: Test the SNP APIC-ID-list GHCB request Jörg Rödel
2026-11-02 11:56   ` sashiko-bot [this message]
2026-11-02 11:41 ` [PATCH v3 8/8] KVM: selftests: Test SNP vCPU state and direct VMSA launch Jörg Rödel

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-193358@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=joro@8bytes.org \
    --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 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.