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 v7 1/4] KVM: PPC: Introduce KVM_CAP_PPC_COMPAT_CAPS and wire up ioctl
Date: Thu, 06 Aug 2026 17:20:31 +0000	[thread overview]
Message-ID: <20260806172032.DC2021F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806170645.11892-2-amachhiw@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] KVM_CAP_PPC_COMPAT_CAPS capability is advertised but the ioctl backend is completely unimplemented, causing unconditional failure.
- [High] The KVM_PPC_GET_COMPAT_CAPS ioctl overwrites the userspace buffer's size field with a value larger than the allocated buffer, creating an out-of-bounds read risk in userspace.
- [Medium] The manual validation block explicitly rejecting `usize > sizeof(host_caps)` defeats the standard forward-compatibility guarantee of `copy_struct_from_user()`.
--

--- Patch [1]: [PATCH v7 1/4] KVM: PPC: Introduce KVM_CAP_PPC_COMPAT_CAPS and wire up ioctl ---
commit 8c51e17a26cbffd727576c50f93a34eea2340547
Author: Amit Machhiwal <amachhiw@linux.ibm.com>

KVM: PPC: Introduce KVM_CAP_PPC_COMPAT_CAPS and wire up ioctl

Introduce a new capability and ioctl to expose CPU compatibility modes
supported by the host processor for nested guests.

> diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
> index 00302399fc37b..ed0cd7b83b63f 100644
> --- a/arch/powerpc/kvm/powerpc.c
> +++ b/arch/powerpc/kvm/powerpc.c
[ ... ]
> @@ -2463,6 +2470,70 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
[ ... ]
> +		/*
> +		 * New userspace with a larger struct called an older kernel.
> +		 * Write back ksize in host_caps.size so userspace knows which
> +		 * older struct to retry with, then fail with -E2BIG.
> +		 */
> +		if (usize > sizeof(host_caps)) {
> +			host_caps.size = sizeof(host_caps);
> +			r = -EFAULT;
> +			if (put_user(host_caps.size, (__u64 __user *)argp))
> +				goto out;
> +			r = -E2BIG;
> +			goto out;
> +		}

[Severity: Medium]
Does this manual size check defeat the standard forward-compatibility
guarantee of copy_struct_from_user()?

Normally, copy_struct_from_user() verifies that any trailing bytes provided
by a newer userspace are zero. By short-circuiting here and unconditionally
returning -E2BIG, aren't we rejecting perfectly valid, zero-initialized
structs and deviating from standard kernel extensible UAPI patterns (like
clone3 or openat2)?

[ ... ]
> +		r = -ENOTTY;
> +		if (!kvm->arch.kvm_ops->get_compat_caps)
> +			goto out;
> +
> +		r = kvm->arch.kvm_ops->get_compat_caps(&host_caps);
> +		if (r)
> +			goto out;

[Severity: High]
Will this ioctl always fail with -ENOTTY?

The capability KVM_CAP_PPC_COMPAT_CAPS is advertised as supported to
userspace (returning 1 on pseries hosts in kvm_vm_ioctl_check_extension()),
but the get_compat_caps backend function pointer is never assigned anywhere
in this patch.

If userspace attempts to use this ioctl based on the capability check,
won't it unconditionally hit this missing backend check and fail, causing
regressions in userspace startup flows?

> +
> +		host_caps.size = sizeof(host_caps);
> +		r = copy_struct_to_user(argp, usize, &host_caps,
> +					sizeof(host_caps), NULL);
> +		break;
> +	}

[Severity: High]
Is it safe to overwrite the userspace size field with the kernel's internal
struct size?

In a forward-compatibility scenario where an older userspace passes a
smaller struct to a newer kernel, usize will be smaller than
sizeof(host_caps). By setting host_caps.size = sizeof(host_caps) and
copying it back, the userspace struct will receive a larger size value than
it actually allocated.

If userspace trusts this size field for bounds checking or iteration, could
this regression lead to an out-of-bounds memory read in userspace? Shouldn't
the kernel preserve the originally requested usize?

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

  reply	other threads:[~2026-08-06 17:20 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06 17:06 [PATCH v7 0/4] KVM: PPC: Expose CPU compatibility modes for nested guests Amit Machhiwal
2026-08-06 17:06 ` [PATCH v7 1/4] KVM: PPC: Introduce KVM_CAP_PPC_COMPAT_CAPS and wire up ioctl Amit Machhiwal
2026-08-06 17:20   ` sashiko-bot [this message]
2026-08-07  3:08   ` Ritesh Harjani
2026-08-07 10:55     ` Amit Machhiwal
2026-08-07 11:36       ` Ritesh Harjani
2026-08-07 12:15         ` Ritesh Harjani
2026-08-07 13:04         ` Amit Machhiwal
2026-08-06 17:06 ` [PATCH v7 2/4] KVM: PPC: Book3S HV: Implement compat CPU capability retrieval for KVM on PowerVM Amit Machhiwal
2026-08-06 17:25   ` sashiko-bot
2026-08-07  4:31   ` Ritesh Harjani
2026-08-07 10:58     ` Amit Machhiwal
2026-08-06 17:06 ` [PATCH v7 3/4] KVM: PPC: Book3S HV: Add support for compat CPU capabilities for KVM on PowerNV Amit Machhiwal
2026-08-07  4:54   ` Ritesh Harjani
2026-08-07 12:07     ` Amit Machhiwal
2026-08-07 12:13       ` Ritesh Harjani
2026-08-06 17:06 ` [PATCH v7 4/4] KVM: PPC: Document KVM_PPC_GET_COMPAT_CAPS ioctl Amit Machhiwal
2026-08-06 17:29   ` sashiko-bot
2026-08-07  4:35   ` Ritesh Harjani
2026-08-07 13:36     ` Amit Machhiwal

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=20260806172032.DC2021F000E9@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