lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a0c3a352-89c6-4764-b377-f55a68a1b2cb@p183>
Date:   Fri, 8 Sep 2023 18:14:38 +0300
From:   Alexey Dobriyan <adobriyan@...il.com>
To:     akpm@...ux-foundation.org
Cc:     linux-kernel@...r.kernel.org, linux-api@...r.kernel.org,
        keescook@...omium.org
Subject: [PATCH v2] uapi: fix __DECLARE_FLEX_ARRAY for C++

__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.

This can be fixed by expanding to

	T member[];

Now g++ doesn't like "T member[]" either throwing errors on code like
this:

	struct S {
		union {
			T1 member1[];
			T2 member2[];
		};
	};

or

	struct S {
		T member[];
	};

So use

	T member[0];

which seems to work and does the right thing wrt structure layout.

Fix header guard while I'm at it.

Signed-off-by: Alexey Dobriyan <adobriyan@...il.com>
---

 include/uapi/linux/stddef.h |    6 ++++++
 1 file changed, 6 insertions(+)

--- a/include/uapi/linux/stddef.h
+++ b/include/uapi/linux/stddef.h
@@ -39,6 +39,10 @@
  * struct, it needs to be wrapped in an anonymous struct with at least 1
  * named member, but that member can be empty.
  */
+#ifdef __cplusplus
+#define __DECLARE_FLEX_ARRAY(T, member)		\
+	T member[0]
+#else
 #define __DECLARE_FLEX_ARRAY(TYPE, NAME)	\
 	struct { \
 		struct { } __empty_ ## NAME; \
@@ -49,3 +53,5 @@
 #ifndef __counted_by
 #define __counted_by(m)
 #endif
+
+#endif

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ