Skip to content

Commit c90748b

Browse files
GustavoARSilvaVudentz
authored andcommitted
Bluetooth: hci_conn: Use __counted_by() to avoid -Wfamnae warning
Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). Also, -Wflex-array-member-not-at-end is coming in GCC-14, and we are getting ready to enable it globally. So, use the `DEFINE_FLEX()` helper for an on-stack definition of a flexible structure where the size of the flexible-array member is known at compile-time, and refactor the rest of the code, accordingly. With these changes, fix the following warning: net/bluetooth/hci_conn.c:2116:50: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] Link: KSPP#202 Signed-off-by: Gustavo A. R. Silva <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent c4585ed commit c90748b

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

include/net/bluetooth/hci.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2216,7 +2216,7 @@ struct hci_cp_le_big_create_sync {
22162216
__u8 mse;
22172217
__le16 timeout;
22182218
__u8 num_bis;
2219-
__u8 bis[];
2219+
__u8 bis[] __counted_by(num_bis);
22202220
} __packed;
22212221

22222222
#define HCI_OP_LE_BIG_TERM_SYNC 0x206c

net/bluetooth/hci_conn.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,13 +2109,10 @@ int hci_le_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon,
21092109
struct bt_iso_qos *qos,
21102110
__u16 sync_handle, __u8 num_bis, __u8 bis[])
21112111
{
2112-
struct _packed {
2113-
struct hci_cp_le_big_create_sync cp;
2114-
__u8 bis[0x11];
2115-
} pdu;
2112+
DEFINE_FLEX(struct hci_cp_le_big_create_sync, pdu, bis, num_bis, 0x11);
21162113
int err;
21172114

2118-
if (num_bis < 0x01 || num_bis > sizeof(pdu.bis))
2115+
if (num_bis < 0x01 || num_bis > pdu->num_bis)
21192116
return -EINVAL;
21202117

21212118
err = qos_set_big(hdev, qos);
@@ -2125,18 +2122,17 @@ int hci_le_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon,
21252122
if (hcon)
21262123
hcon->iso_qos.bcast.big = qos->bcast.big;
21272124

2128-
memset(&pdu, 0, sizeof(pdu));
2129-
pdu.cp.handle = qos->bcast.big;
2130-
pdu.cp.sync_handle = cpu_to_le16(sync_handle);
2131-
pdu.cp.encryption = qos->bcast.encryption;
2132-
memcpy(pdu.cp.bcode, qos->bcast.bcode, sizeof(pdu.cp.bcode));
2133-
pdu.cp.mse = qos->bcast.mse;
2134-
pdu.cp.timeout = cpu_to_le16(qos->bcast.timeout);
2135-
pdu.cp.num_bis = num_bis;
2136-
memcpy(pdu.bis, bis, num_bis);
2125+
pdu->handle = qos->bcast.big;
2126+
pdu->sync_handle = cpu_to_le16(sync_handle);
2127+
pdu->encryption = qos->bcast.encryption;
2128+
memcpy(pdu->bcode, qos->bcast.bcode, sizeof(pdu->bcode));
2129+
pdu->mse = qos->bcast.mse;
2130+
pdu->timeout = cpu_to_le16(qos->bcast.timeout);
2131+
pdu->num_bis = num_bis;
2132+
memcpy(pdu->bis, bis, num_bis);
21372133

21382134
return hci_send_cmd(hdev, HCI_OP_LE_BIG_CREATE_SYNC,
2139-
sizeof(pdu.cp) + num_bis, &pdu);
2135+
sizeof(*pdu) + num_bis, pdu);
21402136
}
21412137

21422138
static void create_big_complete(struct hci_dev *hdev, void *data, int err)

0 commit comments

Comments
 (0)