Commit 94dfc73e7cf4 ("treewide: uapi: Replace zero-length arrays with flexible-array members") broke the userspace API for C++. These structures ending in VLAs are typically a *header*, which can be followed by an arbitrary number of entries. Userspace typically creates a larger structure with some non-zero number of entries, for example in QEMU's kvm_arch_get_supported_msr_feature(): struct { struct kvm_msrs info; struct kvm_msr_entry entries[1]; } msr_data = {}; While that works in C, it fails in C++ with an error like: flexible array member 'kvm_msrs::entries' not at end of 'struct msr_data' Fix this by using __DECLARE_FLEX_ARRAY() for the VLA, which uses [0] for C++ compilation.
Showing the changes to include/uapi (1 of 2 files). Show all
Unified · Split
| @@ -11,6 +11,7 @@ · 10 unmodified lines | ||
| 11 | 11 | #include <linux/const.h> |
| 12 | 12 | #include <linux/types.h> |
| 13 | 13 | #include <linux/compiler.h> |
| 14 | +#include <linux/stddef.h> | |
| 14 | 15 | #include <linux/ioctl.h> |
| 15 | 16 | #include <asm/kvm.h> |
| 16 | 17 | |
| @@ -542,7 +543,7 @@ struct kvm_coalesced_mmio { · 525 unmodified lines | ||
| 542 | 543 | |
| 543 | 544 | struct kvm_coalesced_mmio_ring { |
| 544 | 545 | __u32 first, last; |
| 545 | − struct kvm_coalesced_mmio coalesced_mmio[]; | |
| 546 | + __DECLARE_FLEX_ARRAY(struct kvm_coalesced_mmio, coalesced_mmio); | |
| 546 | 547 | }; |
| 547 | 548 | |
| 548 | 549 | #define KVM_COALESCED_MMIO_MAX \ |
| @@ -592,7 +593,7 @@ struct kvm_clear_dirty_log { · 43 unmodified lines | ||
| 592 | 593 | /* for KVM_SET_SIGNAL_MASK */ |
| 593 | 594 | struct kvm_signal_mask { |
| 594 | 595 | __u32 len; |
| 595 | − __u8 sigset[]; | |
| 596 | + __DECLARE_FLEX_ARRAY(__u8, sigset); | |
| 596 | 597 | }; |
| 597 | 598 | |
| 598 | 599 | /* for KVM_TPR_ACCESS_REPORTING */ |
| @@ -1051,7 +1052,7 @@ struct kvm_irq_routing_entry { · 452 unmodified lines | ||
| 1051 | 1052 | struct kvm_irq_routing { |
| 1052 | 1053 | __u32 nr; |
| 1053 | 1054 | __u32 flags; |
| 1054 | − struct kvm_irq_routing_entry entries[]; | |
| 1055 | + __DECLARE_FLEX_ARRAY(struct kvm_irq_routing_entry, entries); | |
| 1055 | 1056 | }; |
| 1056 | 1057 | |
| 1057 | 1058 | #define KVM_IRQFD_FLAG_DEASSIGN (1 << 0) |
| @@ -1142,7 +1143,7 @@ struct kvm_dirty_tlb { · 84 unmodified lines | ||
| 1142 | 1143 | |
| 1143 | 1144 | struct kvm_reg_list { |
| 1144 | 1145 | __u64 n; /* number of regs */ |
| 1145 | − __u64 reg[]; | |
| 1146 | + __DECLARE_FLEX_ARRAY(__u64, reg); | |
| 1146 | 1147 | }; |
| 1147 | 1148 | |
| 1148 | 1149 | struct kvm_one_reg { |
| @@ -1608,7 +1609,7 @@ struct kvm_stats_desc { · 459 unmodified lines | ||
| 1608 | 1609 | #ifdef __KERNEL__ |
| 1609 | 1610 | char name[KVM_STATS_NAME_SIZE]; |
| 1610 | 1611 | #else |
| 1611 | − char name[]; | |
| 1612 | + __DECLARE_FLEX_ARRAY(char, name); | |
| 1612 | 1613 | #endif |
| 1613 | 1614 | }; |
| 1614 | 1615 | |