Kernel KVM virtualization development
 help / color / mirror / Atom feed
* Re: [PATCH 1/2] KVM: arm64: Return -EINVAL for an empty SMCCC filter range at base 0
       [not found] ` <20260829054856.70549-2-kmehltretter@gmail.com>
@ 2026-08-29  5:58   ` sashiko-bot
  2026-08-29 15:04   ` Fuad Tabba
  2026-09-01  7:38   ` Steffen Eiden
  2 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-08-29  5:58 UTC (permalink / raw)
  To: Karl Mehltretter; +Cc: Oliver Upton, kvmarm, kvm, Marc Zyngier

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

Pre-existing issues:
- [High] Unprivileged userspace-reachable WARN_ON_ONCE can be triggered by memory pressure, potentially causing a host panic.
--

commit 7eae467c4f77ea62fe7302656a7c43a21cc35eb0
Author: Karl Mehltretter <kmehltretter@gmail.com>

KVM: arm64: Return -EINVAL for an empty SMCCC filter range at base 0

This commit fixes an issue where an empty SMCCC filter range at base 0
wraps around to U32_MAX, overlapping reserved ranges and incorrectly
returning -EEXIST. It explicitly rejects a zero function count instead.

> diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c
> index b11b8821c9fbc..dfa25bb6f25d4 100644
> --- a/arch/arm64/kvm/hypercalls.c
> +++ b/arch/arm64/kvm/hypercalls.c
> @@ -185,7 +185,8 @@ static int kvm_smccc_set_filter(struct kvm *kvm, struct kvm_smccc_filter __user
>  	start = filter.base;
>  	end = start + filter.nr_functions - 1;
>  
> -	if (end < start || filter.action >= NR_SMCCC_FILTER_ACTIONS)
> +	if (!filter.nr_functions || end < start ||
> +	    filter.action >= NR_SMCCC_FILTER_ACTIONS)
>  		return -EINVAL;
>  
>  	mutex_lock(&kvm->arch.config_lock);

[Severity: High]
This isn't a bug introduced by this patch, but while looking at
kvm_smccc_set_filter(), is it possible for an unprivileged user to trigger
a kernel panic via the WARN_ON_ONCE lower down in this function?

A userspace process can call the KVM_ARM_VM_SMCCC_FILTER ioctl, which
requires /dev/kvm access. The kernel calls
kvm_smccc_filter_insert_reserved(), which in turn invokes
mtree_insert_range() with GFP_KERNEL_ACCOUNT.

If this maple tree node allocation fails due to memory pressure or cgroup
limits, it returns -ENOMEM.

The caller kvm_smccc_set_filter() then unconditionally executes the
warning check:

    if (!kvm_smccc_filter_configured(kvm)) {
            r = kvm_smccc_filter_insert_reserved(kvm);
            if (WARN_ON_ONCE(r))
                    goto out_unlock;
    }

Because KVM subsystem guidelines forbid host-userspace-reachable warnings,
could this lead to a host denial-of-service if panic_on_warn is enabled?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260829054856.70549-1-kmehltretter@gmail.com?part=1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] KVM: arm64: Return -EINVAL for an empty SMCCC filter range at base 0
       [not found] ` <20260829054856.70549-2-kmehltretter@gmail.com>
  2026-08-29  5:58   ` [PATCH 1/2] KVM: arm64: Return -EINVAL for an empty SMCCC filter range at base 0 sashiko-bot
@ 2026-08-29 15:04   ` Fuad Tabba
  2026-08-29 15:53     ` Karl Mehltretter
  2026-09-01  7:38   ` Steffen Eiden
  2 siblings, 1 reply; 7+ messages in thread
From: Fuad Tabba @ 2026-08-29 15:04 UTC (permalink / raw)
  To: Karl Mehltretter
  Cc: Marc Zyngier, Oliver Upton, kvmarm, Joey Gouly, Steffen Eiden,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon,
	Mark Rutland, Paolo Bonzini, Sean Christopherson, Shuah Khan,
	linux-arm-kernel, linux-kernel, kvm, linux-kselftest

On Sat, 29 Aug 2026 at 06:50, Karl Mehltretter <kmehltretter@gmail.com> wrote:
>
> kvm_smccc_set_filter() only rejects a range if its inclusive end,
> base + nr_functions - 1, is below base. That catches an empty range
> (nr_functions == 0) at every nonzero base, but at base 0 the end wraps
> to U32_MAX and KVM tries to insert [0, U32_MAX], which overlaps the
> reserved Arm Architecture Calls ranges. KVM_ARM_VM_SMCCC_FILTER then
> returns -EEXIST instead of the -EINVAL that the smccc_filter selftest
> expects for an empty range.
>
> Reject a zero function count explicitly.
>
> Tested with a userspace reproducer on an arm64 VHE host under QEMU TCG:
> EEXIST before, EINVAL after.
>
> Fixes: 821d935c87bc ("KVM: arm64: Introduce support for userspace SMCCC filtering")
> Assisted-by: LLM

nit: this should be `Assisted-by: AGENT_NAME:MODEL_VERSION [TOOL1]
[TOOL2]` rather than LLM

> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>

I think Sashiko is onto something, but that's for another day.

Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
Tested-by: Fuad Tabba < fuad.tabba@linux.dev>

Cheers,
/fuad


> ---
>  arch/arm64/kvm/hypercalls.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c
> index b11b8821c9fb..dfa25bb6f25d 100644
> --- a/arch/arm64/kvm/hypercalls.c
> +++ b/arch/arm64/kvm/hypercalls.c
> @@ -185,7 +185,8 @@ static int kvm_smccc_set_filter(struct kvm *kvm, struct kvm_smccc_filter __user
>         start = filter.base;
>         end = start + filter.nr_functions - 1;
>
> -       if (end < start || filter.action >= NR_SMCCC_FILTER_ACTIONS)
> +       if (!filter.nr_functions || end < start ||
> +           filter.action >= NR_SMCCC_FILTER_ACTIONS)
>                 return -EINVAL;
>
>         mutex_lock(&kvm->arch.config_lock);
> --
> 2.39.5 (Apple Git-154)
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] KVM: arm64: selftests: Test empty SMCCC filter range at base 0
       [not found] ` <20260829054856.70549-3-kmehltretter@gmail.com>
@ 2026-08-29 15:04   ` Fuad Tabba
  2026-09-01  7:39   ` Steffen Eiden
  1 sibling, 0 replies; 7+ messages in thread
From: Fuad Tabba @ 2026-08-29 15:04 UTC (permalink / raw)
  To: Karl Mehltretter
  Cc: Marc Zyngier, Oliver Upton, kvmarm, Joey Gouly, Steffen Eiden,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon,
	Mark Rutland, Paolo Bonzini, Sean Christopherson, Shuah Khan,
	linux-arm-kernel, linux-kernel, kvm, linux-kselftest

On Sat, 29 Aug 2026 at 06:50, Karl Mehltretter <kmehltretter@gmail.com> wrote:
>
> test_invalid_nr_functions() only checks an empty range at
> PSCI_0_2_FN64_CPU_ON, which KVM's end < start check happens to catch.
> It never exercised base 0, where the inclusive end wraps to U32_MAX
> instead.
>
> Add the base 0 case. Without the preceding fix it fails with EEXIST.
>
> Assisted-by: LLM
> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>

Same nit as before.

Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
Tested-by: Fuad Tabba < fuad.tabba@linux.dev>

Cheers,
/fuad

> ---
>  tools/testing/selftests/kvm/arm64/smccc_filter.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/tools/testing/selftests/kvm/arm64/smccc_filter.c b/tools/testing/selftests/kvm/arm64/smccc_filter.c
> index 21e41880261b..a41ed3e016ba 100644
> --- a/tools/testing/selftests/kvm/arm64/smccc_filter.c
> +++ b/tools/testing/selftests/kvm/arm64/smccc_filter.c
> @@ -140,6 +140,10 @@ static void test_invalid_nr_functions(void)
>         TEST_ASSERT(r < 0 && errno == EINVAL,
>                     "Attempt to filter 0 functions should return EINVAL");
>
> +       r = __set_smccc_filter(vm, 0, 0, KVM_SMCCC_FILTER_DENY);
> +       TEST_ASSERT(r < 0 && errno == EINVAL,
> +                   "Attempt to filter 0 functions at base 0 should return EINVAL");
> +
>         kvm_vm_free(vm);
>  }
>
> --
> 2.39.5 (Apple Git-154)
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] KVM: arm64: Return -EINVAL for an empty SMCCC filter range at base 0
  2026-08-29 15:04   ` Fuad Tabba
@ 2026-08-29 15:53     ` Karl Mehltretter
  2026-08-29 15:55       ` Fuad Tabba
  0 siblings, 1 reply; 7+ messages in thread
From: Karl Mehltretter @ 2026-08-29 15:53 UTC (permalink / raw)
  To: Fuad Tabba
  Cc: Marc Zyngier, Oliver Upton, kvmarm, Joey Gouly, Steffen Eiden,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon,
	Mark Rutland, Paolo Bonzini, Sean Christopherson, Shuah Khan,
	linux-arm-kernel, linux-kernel, kvm, linux-kselftest

On Sat, Aug 29, 2026 at 04:04:01PM +0100, Fuad Tabba wrote:
> > Fixes: 821d935c87bc ("KVM: arm64: Introduce support for userspace SMCCC filtering")
> > Assisted-by: LLM
> 
> nit: this should be `Assisted-by: AGENT_NAME:MODEL_VERSION [TOOL1]
> [TOOL2]` rather than LLM
> 

When I first saw 'LLM' in a patch I thought so too.

But it is now allowed, see recent discussion and merge: 

  https://lore.kernel.org/r/87qzkuahlr.fsf@trenco.lwn.net/

  816d9992d9ed ("coding-assistants: simplify attribution")
 
> Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
> Tested-by: Fuad Tabba < fuad.tabba@linux.dev>

Thanks for the review and also testing!

Karl

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] KVM: arm64: Return -EINVAL for an empty SMCCC filter range at base 0
  2026-08-29 15:53     ` Karl Mehltretter
@ 2026-08-29 15:55       ` Fuad Tabba
  0 siblings, 0 replies; 7+ messages in thread
From: Fuad Tabba @ 2026-08-29 15:55 UTC (permalink / raw)
  To: Karl Mehltretter
  Cc: Marc Zyngier, Oliver Upton, kvmarm, Joey Gouly, Steffen Eiden,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon,
	Mark Rutland, Paolo Bonzini, Sean Christopherson, Shuah Khan,
	linux-arm-kernel, linux-kernel, kvm, linux-kselftest

On Sat, 29 Aug 2026 at 16:53, Karl Mehltretter <kmehltretter@gmail.com> wrote:
>
> On Sat, Aug 29, 2026 at 04:04:01PM +0100, Fuad Tabba wrote:
> > > Fixes: 821d935c87bc ("KVM: arm64: Introduce support for userspace SMCCC filtering")
> > > Assisted-by: LLM
> >
> > nit: this should be `Assisted-by: AGENT_NAME:MODEL_VERSION [TOOL1]
> > [TOOL2]` rather than LLM
> >
>
> When I first saw 'LLM' in a patch I thought so too.
>
> But it is now allowed, see recent discussion and merge:
>
>   https://lore.kernel.org/r/87qzkuahlr.fsf@trenco.lwn.net/

I missed that. Makes sense to be honest. Either way, that was just a nit :)

Thanks!
/fuad

>
>   816d9992d9ed ("coding-assistants: simplify attribution")
>
> > Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
> > Tested-by: Fuad Tabba < fuad.tabba@linux.dev>
>
> Thanks for the review and also testing!
>
> Karl

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] KVM: arm64: Return -EINVAL for an empty SMCCC filter range at base 0
       [not found] ` <20260829054856.70549-2-kmehltretter@gmail.com>
  2026-08-29  5:58   ` [PATCH 1/2] KVM: arm64: Return -EINVAL for an empty SMCCC filter range at base 0 sashiko-bot
  2026-08-29 15:04   ` Fuad Tabba
@ 2026-09-01  7:38   ` Steffen Eiden
  2 siblings, 0 replies; 7+ messages in thread
From: Steffen Eiden @ 2026-09-01  7:38 UTC (permalink / raw)
  To: Karl Mehltretter
  Cc: Marc Zyngier, Oliver Upton, kvmarm, Fuad Tabba, Joey Gouly,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon,
	Mark Rutland, Paolo Bonzini, Sean Christopherson, Shuah Khan,
	linux-arm-kernel, linux-kernel, kvm, linux-kselftest

On Sat, Aug 29, 2026 at 07:48:55AM +0200, Karl Mehltretter wrote:
> kvm_smccc_set_filter() only rejects a range if its inclusive end,
> base + nr_functions - 1, is below base. That catches an empty range
> (nr_functions == 0) at every nonzero base, but at base 0 the end wraps
> to U32_MAX and KVM tries to insert [0, U32_MAX], which overlaps the
> reserved Arm Architecture Calls ranges. KVM_ARM_VM_SMCCC_FILTER then
> returns -EEXIST instead of the -EINVAL that the smccc_filter selftest
> expects for an empty range.
> 
> Reject a zero function count explicitly.
> 
> Tested with a userspace reproducer on an arm64 VHE host under QEMU TCG:
> EEXIST before, EINVAL after.
> 
> Fixes: 821d935c87bc ("KVM: arm64: Introduce support for userspace SMCCC filtering")
> Assisted-by: LLM
> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>

Good catch.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>

FWIW: Tested it on my downstream version of arm-on-s390 with hypercalls
already implemented. 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] KVM: arm64: selftests: Test empty SMCCC filter range at base 0
       [not found] ` <20260829054856.70549-3-kmehltretter@gmail.com>
  2026-08-29 15:04   ` [PATCH 2/2] KVM: arm64: selftests: Test " Fuad Tabba
@ 2026-09-01  7:39   ` Steffen Eiden
  1 sibling, 0 replies; 7+ messages in thread
From: Steffen Eiden @ 2026-09-01  7:39 UTC (permalink / raw)
  To: Karl Mehltretter
  Cc: Marc Zyngier, Oliver Upton, kvmarm, Fuad Tabba, Joey Gouly,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon,
	Mark Rutland, Paolo Bonzini, Sean Christopherson, Shuah Khan,
	linux-arm-kernel, linux-kernel, kvm, linux-kselftest

On Sat, Aug 29, 2026 at 07:48:56AM +0200, Karl Mehltretter wrote:
> test_invalid_nr_functions() only checks an empty range at
> PSCI_0_2_FN64_CPU_ON, which KVM's end < start check happens to catch.
> It never exercised base 0, where the inclusive end wraps to U32_MAX
> instead.
> 
> Add the base 0 case. Without the preceding fix it fails with EEXIST.
> 
> Assisted-by: LLM
> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-09-01  7:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260829054856.70549-1-kmehltretter@gmail.com>
     [not found] ` <20260829054856.70549-2-kmehltretter@gmail.com>
2026-08-29  5:58   ` [PATCH 1/2] KVM: arm64: Return -EINVAL for an empty SMCCC filter range at base 0 sashiko-bot
2026-08-29 15:04   ` Fuad Tabba
2026-08-29 15:53     ` Karl Mehltretter
2026-08-29 15:55       ` Fuad Tabba
2026-09-01  7:38   ` Steffen Eiden
     [not found] ` <20260829054856.70549-3-kmehltretter@gmail.com>
2026-08-29 15:04   ` [PATCH 2/2] KVM: arm64: selftests: Test " Fuad Tabba
2026-09-01  7:39   ` Steffen Eiden

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox