include/net/bluetooth/mgmt.h | 9 +++++++-- net/bluetooth/mgmt_config.c | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-)
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are
getting ready to enable it, globally.
Use the __struct_group() helper to fix 31 instances of the following
type of warnings:
30 net/bluetooth/mgmt_config.c:16:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
1 net/bluetooth/mgmt_config.c:22:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
Changes in v2:
- Use __struct_group() instead of TRAILING_OVERLAP().
v1:
- Link: https://lore.kernel.org/linux-hardening/aLSCu8U62Hve7Dau@kspp/
include/net/bluetooth/mgmt.h | 9 +++++++--
net/bluetooth/mgmt_config.c | 4 ++--
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 3575cd16049a..74edea06985b 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -53,10 +53,15 @@ struct mgmt_hdr {
} __packed;
struct mgmt_tlv {
- __le16 type;
- __u8 length;
+ /* New members MUST be added within the __struct_group() macro below. */
+ __struct_group(mgmt_tlv_hdr, __hdr, __packed,
+ __le16 type;
+ __u8 length;
+ );
__u8 value[];
} __packed;
+static_assert(offsetof(struct mgmt_tlv, value) == sizeof(struct mgmt_tlv_hdr),
+ "struct member likely outside of __struct_group()");
struct mgmt_addr_info {
bdaddr_t bdaddr;
diff --git a/net/bluetooth/mgmt_config.c b/net/bluetooth/mgmt_config.c
index 6ef701c27da4..c4063d200c0a 100644
--- a/net/bluetooth/mgmt_config.c
+++ b/net/bluetooth/mgmt_config.c
@@ -13,13 +13,13 @@
#define HDEV_PARAM_U16(_param_name_) \
struct {\
- struct mgmt_tlv entry; \
+ struct mgmt_tlv_hdr entry; \
__le16 value; \
} __packed _param_name_
#define HDEV_PARAM_U8(_param_name_) \
struct {\
- struct mgmt_tlv entry; \
+ struct mgmt_tlv_hdr entry; \
__u8 value; \
} __packed _param_name_
--
2.43.0
Hi all,
Friendly ping: who can take this, please? :)
Thanks!
-Gustavo
On 9/9/25 14:13, Gustavo A. R. Silva wrote:
> -Wflex-array-member-not-at-end was introduced in GCC-14, and we are
> getting ready to enable it, globally.
>
> Use the __struct_group() helper to fix 31 instances of the following
> type of warnings:
>
> 30 net/bluetooth/mgmt_config.c:16:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> 1 net/bluetooth/mgmt_config.c:22:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> Changes in v2:
> - Use __struct_group() instead of TRAILING_OVERLAP().
>
> v1:
> - Link: https://lore.kernel.org/linux-hardening/aLSCu8U62Hve7Dau@kspp/
>
> include/net/bluetooth/mgmt.h | 9 +++++++--
> net/bluetooth/mgmt_config.c | 4 ++--
> 2 files changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
> index 3575cd16049a..74edea06985b 100644
> --- a/include/net/bluetooth/mgmt.h
> +++ b/include/net/bluetooth/mgmt.h
> @@ -53,10 +53,15 @@ struct mgmt_hdr {
> } __packed;
>
> struct mgmt_tlv {
> - __le16 type;
> - __u8 length;
> + /* New members MUST be added within the __struct_group() macro below. */
> + __struct_group(mgmt_tlv_hdr, __hdr, __packed,
> + __le16 type;
> + __u8 length;
> + );
> __u8 value[];
> } __packed;
> +static_assert(offsetof(struct mgmt_tlv, value) == sizeof(struct mgmt_tlv_hdr),
> + "struct member likely outside of __struct_group()");
>
> struct mgmt_addr_info {
> bdaddr_t bdaddr;
> diff --git a/net/bluetooth/mgmt_config.c b/net/bluetooth/mgmt_config.c
> index 6ef701c27da4..c4063d200c0a 100644
> --- a/net/bluetooth/mgmt_config.c
> +++ b/net/bluetooth/mgmt_config.c
> @@ -13,13 +13,13 @@
>
> #define HDEV_PARAM_U16(_param_name_) \
> struct {\
> - struct mgmt_tlv entry; \
> + struct mgmt_tlv_hdr entry; \
> __le16 value; \
> } __packed _param_name_
>
> #define HDEV_PARAM_U8(_param_name_) \
> struct {\
> - struct mgmt_tlv entry; \
> + struct mgmt_tlv_hdr entry; \
> __u8 value; \
> } __packed _param_name_
>
Dear Gustavo,
Thank you for your patch.
Am 09.09.25 um 14:13 schrieb Gustavo A. R. Silva:
> -Wflex-array-member-not-at-end was introduced in GCC-14, and we are
> getting ready to enable it, globally.
>
> Use the __struct_group() helper to fix 31 instances of the following
> type of warnings:
>
> 30 net/bluetooth/mgmt_config.c:16:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> 1 net/bluetooth/mgmt_config.c:22:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
You could add an explanation, why the macro `__struct_group()` defined
in `include/uapi/linux/stddef.h` fixes this, and why it is preferred
over `TRAILING_OVERLAP()`. Also, the two underscores would suggest to
me, it’s some kind of internal implementation.
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> Changes in v2:
> - Use __struct_group() instead of TRAILING_OVERLAP().
>
> v1:
> - Link: https://lore.kernel.org/linux-hardening/aLSCu8U62Hve7Dau@kspp/
>
> include/net/bluetooth/mgmt.h | 9 +++++++--
> net/bluetooth/mgmt_config.c | 4 ++--
> 2 files changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
> index 3575cd16049a..74edea06985b 100644
> --- a/include/net/bluetooth/mgmt.h
> +++ b/include/net/bluetooth/mgmt.h
> @@ -53,10 +53,15 @@ struct mgmt_hdr {
> } __packed;
>
> struct mgmt_tlv {
> - __le16 type;
> - __u8 length;
> + /* New members MUST be added within the __struct_group() macro below. */
> + __struct_group(mgmt_tlv_hdr, __hdr, __packed,
> + __le16 type;
> + __u8 length;
> + );
> __u8 value[];
> } __packed;
> +static_assert(offsetof(struct mgmt_tlv, value) == sizeof(struct mgmt_tlv_hdr),
> + "struct member likely outside of __struct_group()");
>
> struct mgmt_addr_info {
> bdaddr_t bdaddr;
> diff --git a/net/bluetooth/mgmt_config.c b/net/bluetooth/mgmt_config.c
> index 6ef701c27da4..c4063d200c0a 100644
> --- a/net/bluetooth/mgmt_config.c
> +++ b/net/bluetooth/mgmt_config.c
> @@ -13,13 +13,13 @@
>
> #define HDEV_PARAM_U16(_param_name_) \
> struct {\
> - struct mgmt_tlv entry; \
> + struct mgmt_tlv_hdr entry; \
> __le16 value; \
> } __packed _param_name_
>
> #define HDEV_PARAM_U8(_param_name_) \
> struct {\
> - struct mgmt_tlv entry; \
> + struct mgmt_tlv_hdr entry; \
> __u8 value; \
> } __packed _param_name_
>
Kind regards,
Paul
On Tue, Sep 09, 2025 at 02:13:35PM +0200, Gustavo A. R. Silva wrote: > -Wflex-array-member-not-at-end was introduced in GCC-14, and we are > getting ready to enable it, globally. > > Use the __struct_group() helper to fix 31 instances of the following > type of warnings: > > 30 net/bluetooth/mgmt_config.c:16:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] > 1 net/bluetooth/mgmt_config.c:22:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] > > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > --- > Changes in v2: > - Use __struct_group() instead of TRAILING_OVERLAP(). > > v1: > - Link: https://lore.kernel.org/linux-hardening/aLSCu8U62Hve7Dau@kspp/ Reviewed-by: Simon Horman <horms@kernel.org>
© 2016 - 2025 Red Hat, Inc.