Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Amit Machhiwal" <amachhiw@linux.ibm.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v8 4/4] KVM: PPC: Document KVM_PPC_GET_COMPAT_CAPS ioctl
Date: Fri, 07 Aug 2026 17:37:15 +0000	[thread overview]
Message-ID: <20260807173716.030851F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260807172433.82045-5-amachhiw@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Medium] The documentation inaccurately describes how the extensible struct versioning handles trailing fields and truncation.

Pre-existing issues:
- [High] A userspace-reachable WARN_ON_ONCE in kvmppc_get_compat_caps allows unprivileged users to panic the host if panic_on_warn is set.
--

--- Patch [4]: [PATCH v8 4/4] KVM: PPC: Document KVM_PPC_GET_COMPAT_CAPS ioctl ---
commit 991bf5faa645caad474f6369b275de7617351fd0
Author: Amit Machhiwal <amachhiw@linux.ibm.com>

KVM: PPC: Document KVM_PPC_GET_COMPAT_CAPS ioctl

Add documentation for the KVM_PPC_GET_COMPAT_CAPS ioctl to the KVM API
documentation. The ioctl exposes host processor compatibility modes supported
for nested KVM guests on PowerPC systems. The documentation covers error
code descriptions including E2BIG for forward compatibility.

> diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
> index e3003a241d5b0..e656d117cd0b1 100644
> --- a/Documentation/virt/kvm/api.rst
> +++ b/Documentation/virt/kvm/api.rst
> @@ -6566,6 +6566,95 @@ KVM_S390_KEYOP_SSKE
>    Sets the storage key for the guest address ``guest_addr`` to the key
>    specified in ``key``, returning the previous value in ``key``.
>  
> +4.145 KVM_PPC_GET_COMPAT_CAPS
> +-----------------------------

[Severity: High]
This is a pre-existing issue, but does this ioctl handler allow unprivileged
users to panic the host?

Looking at kvmppc_get_compat_caps() in arch/powerpc/kvm/book3s_hv.c:

arch/powerpc/kvm/book3s_hv.c:kvmppc_get_compat_caps() {
	if (kvmhv_on_pseries()) {
		if (kvmhv_is_nestedv2()) {
			WARN_ON_ONCE(!nested_capabilities);
			capabilities = nested_capabilities;
			[ ... ]
}

An unprivileged user with access to /dev/kvm can open a VM file descriptor
and call the KVM_PPC_GET_COMPAT_CAPS ioctl. If the system is a nested guest
(kvmhv_is_nestedv2() is true) but the parent hypervisor advertised no
capabilities (nested_capabilities is 0), the ioctl handler directly triggers
a WARN_ON_ONCE(!nested_capabilities).

This can occur naturally if plpar_guest_set_capabilities(0, 0) succeeds
during kvmhv_nested_init(). This directly violates the KVM subsystem
guidelines which explicitly forbid userspace-reachable WARN_ON assertions,
as it can cause a host kernel panic (Denial of Service) if panic_on_warn is
set.

[ ... ]

> +The ioctl uses ``copy_struct_from_user()`` and ``copy_struct_to_user()``
> +to support extensible versioning across three cases:
> +
> +- If ``size`` is smaller than the kernel's struct size (old userspace,
> +  new kernel), the kernel zero-pads the unknown trailing fields before
> +  returning, and writes back ``size`` unchanged so userspace knows how
> +  many bytes were filled.

[Severity: Medium]
Does this documentation accurately reflect the UAPI contract for struct padding
and truncation on the return path?

The documentation incorrectly states that if the userspace struct is smaller,
the kernel "zero-pads the unknown trailing fields before returning". This
misleadingly implies it pads the userspace buffer (which would be a buffer
overflow). In reality, the kernel strictly truncates trailing fields on output
to userspace using copy_struct_to_user().

Additionally, it fails to document that when userspace provides a larger
struct with zeroed trailing bytes, the kernel actively mutates the userspace
'size' field on success (via host_caps.size = min_t(...)) to reflect the
kernel's smaller struct size.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260807172433.82045-1-amachhiw@linux.ibm.com?part=4

  reply	other threads:[~2026-08-07 17:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-07 17:24 [PATCH v8 0/4] KVM: PPC: Expose CPU compatibility modes for nested guests Amit Machhiwal
2026-08-07 17:24 ` [PATCH v8 1/4] KVM: PPC: Introduce KVM_CAP_PPC_COMPAT_CAPS and wire up ioctl Amit Machhiwal
2026-08-07 17:34   ` sashiko-bot
2026-08-08  1:00   ` Ritesh Harjani
2026-08-07 17:24 ` [PATCH v8 2/4] KVM: PPC: Book3S HV: Implement compat CPU capability retrieval for KVM on PowerVM Amit Machhiwal
2026-08-07 17:39   ` sashiko-bot
2026-08-07 17:24 ` [PATCH v8 3/4] KVM: PPC: Book3S HV: Add support for compat CPU capabilities for KVM on PowerNV Amit Machhiwal
2026-08-07 17:24 ` [PATCH v8 4/4] KVM: PPC: Document KVM_PPC_GET_COMPAT_CAPS ioctl Amit Machhiwal
2026-08-07 17:37   ` sashiko-bot [this message]
2026-08-08  1:15   ` Ritesh Harjani

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=20260807173716.030851F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amachhiw@linux.ibm.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox