Commit c90748b8 authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva Committed by Luiz Augusto von Dentz

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: https://github.com/KSPP/linux/issues/202Signed-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
parent c4585edf
...@@ -2216,7 +2216,7 @@ struct hci_cp_le_big_create_sync { ...@@ -2216,7 +2216,7 @@ struct hci_cp_le_big_create_sync {
__u8 mse; __u8 mse;
__le16 timeout; __le16 timeout;
__u8 num_bis; __u8 num_bis;
__u8 bis[]; __u8 bis[] __counted_by(num_bis);
} __packed; } __packed;
#define HCI_OP_LE_BIG_TERM_SYNC 0x206c #define HCI_OP_LE_BIG_TERM_SYNC 0x206c
......
...@@ -2109,13 +2109,10 @@ int hci_le_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon, ...@@ -2109,13 +2109,10 @@ int hci_le_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon,
struct bt_iso_qos *qos, struct bt_iso_qos *qos,
__u16 sync_handle, __u8 num_bis, __u8 bis[]) __u16 sync_handle, __u8 num_bis, __u8 bis[])
{ {
struct _packed { DEFINE_FLEX(struct hci_cp_le_big_create_sync, pdu, bis, num_bis, 0x11);
struct hci_cp_le_big_create_sync cp;
__u8 bis[0x11];
} pdu;
int err; int err;
if (num_bis < 0x01 || num_bis > sizeof(pdu.bis)) if (num_bis < 0x01 || num_bis > pdu->num_bis)
return -EINVAL; return -EINVAL;
err = qos_set_big(hdev, qos); err = qos_set_big(hdev, qos);
...@@ -2125,18 +2122,17 @@ int hci_le_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon, ...@@ -2125,18 +2122,17 @@ int hci_le_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon,
if (hcon) if (hcon)
hcon->iso_qos.bcast.big = qos->bcast.big; hcon->iso_qos.bcast.big = qos->bcast.big;
memset(&pdu, 0, sizeof(pdu)); pdu->handle = qos->bcast.big;
pdu.cp.handle = qos->bcast.big; pdu->sync_handle = cpu_to_le16(sync_handle);
pdu.cp.sync_handle = cpu_to_le16(sync_handle); pdu->encryption = qos->bcast.encryption;
pdu.cp.encryption = qos->bcast.encryption; memcpy(pdu->bcode, qos->bcast.bcode, sizeof(pdu->bcode));
memcpy(pdu.cp.bcode, qos->bcast.bcode, sizeof(pdu.cp.bcode)); pdu->mse = qos->bcast.mse;
pdu.cp.mse = qos->bcast.mse; pdu->timeout = cpu_to_le16(qos->bcast.timeout);
pdu.cp.timeout = cpu_to_le16(qos->bcast.timeout); pdu->num_bis = num_bis;
pdu.cp.num_bis = num_bis; memcpy(pdu->bis, bis, num_bis);
memcpy(pdu.bis, bis, num_bis);
return hci_send_cmd(hdev, HCI_OP_LE_BIG_CREATE_SYNC, return hci_send_cmd(hdev, HCI_OP_LE_BIG_CREATE_SYNC,
sizeof(pdu.cp) + num_bis, &pdu); sizeof(*pdu) + num_bis, pdu);
} }
static void create_big_complete(struct hci_dev *hdev, void *data, int err) static void create_big_complete(struct hci_dev *hdev, void *data, int err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment