]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Bluetooth: MGMT: reject malformed HCI_CMD_SYNC commands
authorDmitry Antipov <dmantipov@yandex.ru>
Thu, 22 May 2025 18:16:02 +0000 (21:16 +0300)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 30 May 2025 17:29:30 +0000 (13:29 -0400)
In 'mgmt_hci_cmd_sync()', check whether the size of parameters passed
in 'struct mgmt_cp_hci_cmd_sync' matches the total size of the data
(i.e. 'sizeof(struct mgmt_cp_hci_cmd_sync)' plus trailing bytes).
Otherwise, large invalid 'params_len' will cause 'hci_cmd_sync_alloc()'
to do 'skb_put_data()' from an area beyond the one actually passed to
'mgmt_hci_cmd_sync()'.

Reported-by: syzbot+5fe2d5bfbfbec0b675a0@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=5fe2d5bfbfbec0b675a0
Fixes: 827af4787e74 ("Bluetooth: MGMT: Add initial implementation of MGMT_OP_HCI_CMD_SYNC")
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
net/bluetooth/mgmt.c

index 261926dccc7e8efc6b0f096ba8c8202d96290106..14a9462fced5e9a8f831f86a8e890c17b8c5671c 100644 (file)
@@ -2566,7 +2566,8 @@ static int mgmt_hci_cmd_sync(struct sock *sk, struct hci_dev *hdev,
        struct mgmt_pending_cmd *cmd;
        int err;
 
-       if (len < sizeof(*cp))
+       if (len != (offsetof(struct mgmt_cp_hci_cmd_sync, params) +
+                   le16_to_cpu(cp->params_len)))
                return mgmt_cmd_status(sk, hdev->id, MGMT_OP_HCI_CMD_SYNC,
                                       MGMT_STATUS_INVALID_PARAMS);