Skip to content

Commit f0bc704

Browse files
committed
Merge tag 'hardening-v6.13-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull hardening fix from Kees Cook: - stddef: make __struct_group() UAPI C++-friendly (Alexander Lobakin) * tag 'hardening-v6.13-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: stddef: make __struct_group() UAPI C++-friendly
2 parents 2c2b3d9 + 724c6ce commit f0bc704

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

include/uapi/linux/stddef.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
#define __always_inline inline
99
#endif
1010

11+
/* Not all C++ standards support type declarations inside an anonymous union */
12+
#ifndef __cplusplus
13+
#define __struct_group_tag(TAG) TAG
14+
#else
15+
#define __struct_group_tag(TAG)
16+
#endif
17+
1118
/**
1219
* __struct_group() - Create a mirrored named and anonyomous struct
1320
*
@@ -20,13 +27,13 @@
2027
* and size: one anonymous and one named. The former's members can be used
2128
* normally without sub-struct naming, and the latter can be used to
2229
* reason about the start, end, and size of the group of struct members.
23-
* The named struct can also be explicitly tagged for layer reuse, as well
24-
* as both having struct attributes appended.
30+
* The named struct can also be explicitly tagged for layer reuse (C only),
31+
* as well as both having struct attributes appended.
2532
*/
2633
#define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \
2734
union { \
2835
struct { MEMBERS } ATTRS; \
29-
struct TAG { MEMBERS } ATTRS NAME; \
36+
struct __struct_group_tag(TAG) { MEMBERS } ATTRS NAME; \
3037
} ATTRS
3138

3239
#ifdef __cplusplus

tools/include/uapi/linux/stddef.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
#define __always_inline __inline__
99
#endif
1010

11+
/* Not all C++ standards support type declarations inside an anonymous union */
12+
#ifndef __cplusplus
13+
#define __struct_group_tag(TAG) TAG
14+
#else
15+
#define __struct_group_tag(TAG)
16+
#endif
17+
1118
/**
1219
* __struct_group() - Create a mirrored named and anonyomous struct
1320
*
@@ -20,14 +27,14 @@
2027
* and size: one anonymous and one named. The former's members can be used
2128
* normally without sub-struct naming, and the latter can be used to
2229
* reason about the start, end, and size of the group of struct members.
23-
* The named struct can also be explicitly tagged for layer reuse, as well
24-
* as both having struct attributes appended.
30+
* The named struct can also be explicitly tagged for layer reuse (C only),
31+
* as well as both having struct attributes appended.
2532
*/
2633
#define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \
2734
union { \
2835
struct { MEMBERS } ATTRS; \
29-
struct TAG { MEMBERS } ATTRS NAME; \
30-
}
36+
struct __struct_group_tag(TAG) { MEMBERS } ATTRS NAME; \
37+
} ATTRS
3138

3239
/**
3340
* __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union

0 commit comments

Comments
 (0)