From: David Woodhouse <dwmw2@infradead.org>
To: keescook@chromium.org
Cc: daniel@iogearbox.net, gustavoars@kernel.org, jgg@ziepe.ca,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] treewide: uapi: Replace zero-length arrays with flexible-array members
Date: Mon, 23 Feb 2026 14:28:11 +0000 [thread overview]
Message-ID: <aaa7ac93db25459fa5a629d0da5abf13e93d8301.camel@infradead.org> (raw)
In-Reply-To: <202206281009.4332AA33@keescook>
[-- Attachment #1: Type: text/plain, Size: 2168 bytes --]
On 2022-07-28 at 10:54:58 -0700, Kees Cook <keescook@chromium.org> wrote:
> The issue here seems to be a collision between "unknown array size"
> and known sizes:
>
> struct bpf_lpm_trie_key {
> __u32 prefixlen; /* up to 32 for AF_INET, 128 for AF_INET6 */
> __u8 data[0]; /* Arbitrary size */
> };
>
> struct lpm_key {
> struct bpf_lpm_trie_key trie_key;
> __u32 data;
> };
>
> This is treating trie_key as a header, which it's not: it's a complete
> structure. :)
>
> Perhaps:
>
> struct lpm_key {
> __u32 prefixlen;
> __u32 data;
> };
>
> I don't see anything else trying to include bpf_lpm_trie_key.
What was the eventual conclusion here?
These changes broke userspace compilation, because a *lot* of these
structures ending with VLAs are very much used as headers.
QEMU does it, for example...
uint64_t kvm_arch_get_supported_msr_feature(KVMState *s, uint32_t index)
{
struct {
struct kvm_msrs info;
struct kvm_msr_entry entries[1];
} msr_data = {};
... which works in C but not in C++, which gives an error I can't work
out how to avoid.
Am I missing something, or did we break our userspace headers for C++
and make them C-only?
$ cat test_kvm.cpp
#include <cstdlib>
#include <asm/kvm.h>
struct msr_data {
struct kvm_msrs info;
struct kvm_msr_entry entries[1];
};
struct msr_data *alloc_msr_data(void)
{
return static_cast<struct msr_data *>(malloc(sizeof(struct msr_data)));
}
$ g++ -c -o test_kvm.o test_kvm.cpp
In file included from test_kvm.cpp:2:
/usr/include/x86_64-linux-gnu/asm/kvm.h:194:30: error: flexible array member ‘kvm_msrs::entries’ not at end of ‘struct msr_data’
194 | struct kvm_msr_entry entries[];
| ^~~~~~~
test_kvm.cpp:6:30: note: next member ‘kvm_msr_entry msr_data::entries [1]’ declared here
6 | struct kvm_msr_entry entries[1];
| ^~~~~~~
test_kvm.cpp:4:8: note: in the definition of ‘struct msr_data’
4 | struct msr_data {
| ^~~~~~~~
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5069 bytes --]
next prev parent reply other threads:[~2026-02-23 14:28 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-27 18:04 Gustavo A. R. Silva
2022-06-27 18:27 ` Daniel Borkmann
2022-06-27 18:35 ` Gustavo A. R. Silva
2022-06-28 0:40 ` Jason Gunthorpe
2022-06-28 0:58 ` Gustavo A. R. Silva
2022-06-28 2:21 ` Gustavo A. R. Silva
2022-06-28 13:36 ` Jason Gunthorpe
2022-06-28 13:56 ` Gustavo A. R. Silva
2022-06-28 17:54 ` Kees Cook
2022-06-28 18:44 ` Jason Gunthorpe
2026-02-23 14:28 ` David Woodhouse [this message]
2026-02-23 3:38 ` Gustavo A. R. Silva
2026-02-23 19:57 ` David Woodhouse
2026-02-26 11:44 ` [PATCH] KVM: x86: Fix C++ user API for structures with variable length arrays David Woodhouse
2026-02-26 19:02 ` Kees Cook
2026-02-27 8:29 ` David Woodhouse
2026-02-28 0:43 ` Kees Cook
2026-02-28 8:54 ` David Woodhouse
2026-03-05 18:36 ` Sean Christopherson
2026-03-05 19:18 ` David Woodhouse
2026-03-05 19:31 ` Sean Christopherson
2026-03-05 19:49 ` [PATCH v2] KVM: x86: Use __DECLARE_FLEX_ARRAY() for UAPI structures with VLAs David Woodhouse
2026-04-03 15:13 ` Sean Christopherson
2022-06-27 19:53 ` [PATCH][next] treewide: uapi: Replace zero-length arrays with flexible-array members Stephen Hemminger
2022-06-28 14:18 ` Gustavo A. R. Silva
2022-06-27 22:31 ` Dan Williams
2022-06-28 7:27 ` Geert Uytterhoeven
2022-06-28 18:05 ` Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aaa7ac93db25459fa5a629d0da5abf13e93d8301.camel@infradead.org \
--to=dwmw2@infradead.org \
--cc=daniel@iogearbox.net \
--cc=gustavoars@kernel.org \
--cc=jgg@ziepe.ca \
--cc=keescook@chromium.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®