From: Kees Cook <keescook@chromium.org>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
linux-api@vger.kernel.org, linux-hardening@vger.kernel.org,
David.Laight@aculab.com
Subject: Re: [PATCH v3 1/2] uapi: fix __DECLARE_FLEX_ARRAY for C++
Date: Fri, 15 Sep 2023 12:14:06 -0700 [thread overview]
Message-ID: <202309151208.C99747375@keescook> (raw)
In-Reply-To: <97242381-f1ec-4a4a-9472-1a464f575657@p183>
On Tue, Sep 12, 2023 at 07:22:24PM +0300, Alexey Dobriyan wrote:
> __DECLARE_FLEX_ARRAY(T, member) macro expands to
>
> struct {
> struct {} __empty_member;
> T member[];
> };
>
> which is subtly wrong in C++ because sizeof(struct{}) is 1 not 0,
> changing UAPI structures layouts.
Looking at this again just now, what about using a 0-length array
instead of an anonymous struct?
https://godbolt.org/z/rGaxPWjef
Then we don't need an #ifdef at all...
struct {
int __empty_member[0];
T member[];
};
-Kees
--
Kees Cook
prev parent reply other threads:[~2023-09-15 19:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-08 11:32 [PATCH] uapi: partially fix __DECLARE_FLEX_ARRAY for C++ Alexey Dobriyan
2023-09-08 15:14 ` [PATCH v2] uapi: " Alexey Dobriyan
2023-09-08 15:53 ` Kees Cook
2023-09-08 16:03 ` Alexey Dobriyan
2023-09-08 16:11 ` Kees Cook
2023-09-11 8:19 ` David Laight
2023-09-12 15:06 ` Alexey Dobriyan
2023-09-12 16:22 ` [PATCH v3 1/2] " Alexey Dobriyan
2023-09-12 16:23 ` [PATCH v3 2/2] uapi: fix header guard in include/uapi/linux/stddef.h Alexey Dobriyan
2023-09-15 19:14 ` Kees Cook [this message]
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=202309151208.C99747375@keescook \
--to=keescook@chromium.org \
--cc=David.Laight@aculab.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-hardening@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.