Skip to contentSkip to conversation

KVM: x86/pmu: annotate struct kvm_x86_pmu_event_filter with __counted_by()

PATCH Applied Carlos López 2 participants 2 messages Feb 12 – Mar 5

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: x86/pmu: annotate struct kvm_x86_pmu_event_filter with __counted_by()

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.

---
 arch/x86/include/asm/kvm_host.h | 2 +-
 arch/x86/kvm/pmu.c              | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -1
index ff07c45e3c73..d9159b969bd9 100644
@@ -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 {
arch/x86/kvm/pmu.c +1 -1
index bd6b785cf261..e218352e3423 100644
@@ -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

Signature · 1 line
2.51.0
maintainer Applied
#1 lore raw
Quoted 8 lines · Carlos López

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