Skip to content

Commit 0ab905c

Browse files
zijun-huVudentz
authored andcommitted
Bluetooth: Devcoredump: Fix storing u32 without specifying byte order issue
API hci_devcd_init() stores its u32 type parameter @dump_size into skb, but it does not specify which byte order is used to store the integer, let us take little endian to store and parse the integer. Fixes: f5cc609d09d4 ("Bluetooth: Add support for hci devcoredump") Signed-off-by: Zijun Hu <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 25c150a commit 0ab905c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

net/bluetooth/coredump.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <linux/devcoredump.h>
77

8+
#include <asm/unaligned.h>
89
#include <net/bluetooth/bluetooth.h>
910
#include <net/bluetooth/hci_core.h>
1011

@@ -180,25 +181,25 @@ static int hci_devcd_prepare(struct hci_dev *hdev, u32 dump_size)
180181

181182
static void hci_devcd_handle_pkt_init(struct hci_dev *hdev, struct sk_buff *skb)
182183
{
183-
u32 *dump_size;
184+
u32 dump_size;
184185

185186
if (hdev->dump.state != HCI_DEVCOREDUMP_IDLE) {
186187
DBG_UNEXPECTED_STATE();
187188
return;
188189
}
189190

190-
if (skb->len != sizeof(*dump_size)) {
191+
if (skb->len != sizeof(dump_size)) {
191192
bt_dev_dbg(hdev, "Invalid dump init pkt");
192193
return;
193194
}
194195

195-
dump_size = skb_pull_data(skb, sizeof(*dump_size));
196-
if (!*dump_size) {
196+
dump_size = get_unaligned_le32(skb_pull_data(skb, 4));
197+
if (!dump_size) {
197198
bt_dev_err(hdev, "Zero size dump init pkt");
198199
return;
199200
}
200201

201-
if (hci_devcd_prepare(hdev, *dump_size)) {
202+
if (hci_devcd_prepare(hdev, dump_size)) {
202203
bt_dev_err(hdev, "Failed to prepare for dump");
203204
return;
204205
}
@@ -441,7 +442,7 @@ int hci_devcd_init(struct hci_dev *hdev, u32 dump_size)
441442
return -ENOMEM;
442443

443444
hci_dmp_cb(skb)->pkt_type = HCI_DEVCOREDUMP_PKT_INIT;
444-
skb_put_data(skb, &dump_size, sizeof(dump_size));
445+
put_unaligned_le32(dump_size, skb_put(skb, 4));
445446

446447
skb_queue_tail(&hdev->dump.dump_q, skb);
447448
queue_work(hdev->workqueue, &hdev->dump.dump_rx);

0 commit comments

Comments
 (0)