]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: x86/pmu: annotate struct kvm_x86_pmu_event_filter with __counted_by()
authorCarlos López <clopez@suse.de>
Thu, 12 Feb 2026 14:05:56 +0000 (15:05 +0100)
committerSean Christopherson <seanjc@google.com>
Mon, 2 Mar 2026 22:31:28 +0000 (14:31 -0800)
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>
Link: https://patch.msgid.link/20260212140556.3883030-2-clopez@suse.de
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/pmu.c

index ff07c45e3c731a2833b472faca4262ac4af19a5b..d9159b969bd905be4cd94aec660808624e2c08e3 100644 (file)
@@ -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 {
index bd6b785cf2612e6069bb9ee8c6c826a1658baba1..e218352e342311e32b4570fa8fcf8666fb3d5eae 100644 (file)
@@ -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);