mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] KVM: x86/pmu: annotate struct kvm_x86_pmu_event_filter with __counted_by()
@ 2026-02-12 14:05 Carlos López
  2026-03-05 17:07 ` Sean Christopherson
  0 siblings, 1 reply; 2+ messages in thread
From: Carlos López @ 2026-02-12 14:05 UTC (permalink / raw)
  To: kvm, seanjc, pbonzini
  Cc: Carlos López, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	H. Peter Anvin, Kees Cook, Gustavo A. R. Silva,
	open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:KERNEL HARDENING (not covered by other
	areas):Keyword:b__counted_by(_le|_be)?b

struct kvm_x86_pmu_event_filter has a flexible array member, so annotate
it with the field that describes the amount of entries in such array.
Opportunistically replace the open-coded array size calculation with
flex_array_size() when copying the array portion of the struct from
userspace.

Signed-off-by: Carlos López <clopez@suse.de>
---
 arch/x86/include/asm/kvm_host.h | 2 +-
 arch/x86/kvm/pmu.c              | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index ff07c45e3c73..d9159b969bd9 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1261,7 +1261,7 @@ struct kvm_x86_pmu_event_filter {
 	__u32 nr_excludes;
 	__u64 *includes;
 	__u64 *excludes;
-	__u64 events[];
+	__u64 events[] __counted_by(nevents);
 };
 
 enum kvm_apicv_inhibit {
diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index bd6b785cf261..e218352e3423 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -1256,7 +1256,7 @@ int kvm_vm_ioctl_set_pmu_event_filter(struct kvm *kvm, void __user *argp)
 
 	r = -EFAULT;
 	if (copy_from_user(filter->events, user_filter->events,
-			   sizeof(filter->events[0]) * filter->nevents))
+			   flex_array_size(filter, events, filter->nevents)))
 		goto cleanup;
 
 	r = prepare_filter_lists(filter);

base-commit: e944fe2c09f405a2e2d147145c9b470084bc4c9a
-- 
2.51.0


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

* Re: [PATCH] KVM: x86/pmu: annotate struct kvm_x86_pmu_event_filter with __counted_by()
  2026-02-12 14:05 [PATCH] KVM: x86/pmu: annotate struct kvm_x86_pmu_event_filter with __counted_by() Carlos López
@ 2026-03-05 17:07 ` Sean Christopherson
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2026-03-05 17:07 UTC (permalink / raw)
  To: Sean Christopherson, kvm, pbonzini, Carlos López
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Kees Cook, Gustavo A. R. Silva, linux-kernel,
	linux-hardening

On Thu, 12 Feb 2026 15:05:56 +0100, Carlos López wrote:
> struct kvm_x86_pmu_event_filter has a flexible array member, so annotate
> it with the field that describes the amount of entries in such array.
> Opportunistically replace the open-coded array size calculation with
> flex_array_size() when copying the array portion of the struct from
> userspace.
> 
> 
> [...]

Applied to kvm-x86 misc, thanks!

[1/1] KVM: x86/pmu: annotate struct kvm_x86_pmu_event_filter with __counted_by()
      https://github.com/kvm-x86/linux/commit/c522ac04ba9d

--
https://github.com/kvm-x86/linux/tree/next

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

end of thread, other threads:[~2026-03-05 17:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-12 14:05 [PATCH] KVM: x86/pmu: annotate struct kvm_x86_pmu_event_filter with __counted_by() Carlos López
2026-03-05 17:07 ` Sean Christopherson

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

all inboxes | Powered by JetHome®