Skip to content

Commit cda0d6a

Browse files
jhovoldVudentz
authored andcommitted
Bluetooth: qca: fix info leak when fetching fw build id
Add the missing sanity checks and move the 255-byte build-id buffer off the stack to avoid leaking stack data through debugfs in case the build-info reply is malformed. Fixes: c0187b0 ("Bluetooth: btqca: Add support to read FW build version for WCN3991 BTSoC") Cc: [email protected] # 5.12 Signed-off-by: Johan Hovold <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent dd33664 commit cda0d6a

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

drivers/bluetooth/btqca.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ static int qca_read_fw_build_info(struct hci_dev *hdev)
9999
{
100100
struct sk_buff *skb;
101101
struct edl_event_hdr *edl;
102-
char cmd, build_label[QCA_FW_BUILD_VER_LEN];
102+
char *build_label;
103+
char cmd;
103104
int build_lbl_len, err = 0;
104105

105106
bt_dev_dbg(hdev, "QCA read fw build info");
@@ -114,6 +115,11 @@ static int qca_read_fw_build_info(struct hci_dev *hdev)
114115
return err;
115116
}
116117

118+
if (skb->len < sizeof(*edl)) {
119+
err = -EILSEQ;
120+
goto out;
121+
}
122+
117123
edl = (struct edl_event_hdr *)(skb->data);
118124
if (!edl) {
119125
bt_dev_err(hdev, "QCA read fw build info with no header");
@@ -129,14 +135,25 @@ static int qca_read_fw_build_info(struct hci_dev *hdev)
129135
goto out;
130136
}
131137

138+
if (skb->len < sizeof(*edl) + 1) {
139+
err = -EILSEQ;
140+
goto out;
141+
}
142+
132143
build_lbl_len = edl->data[0];
133-
if (build_lbl_len <= QCA_FW_BUILD_VER_LEN - 1) {
134-
memcpy(build_label, edl->data + 1, build_lbl_len);
135-
*(build_label + build_lbl_len) = '\0';
144+
145+
if (skb->len < sizeof(*edl) + 1 + build_lbl_len) {
146+
err = -EILSEQ;
147+
goto out;
136148
}
137149

150+
build_label = kstrndup(&edl->data[1], build_lbl_len, GFP_KERNEL);
151+
if (!build_label)
152+
goto out;
153+
138154
hci_set_fw_info(hdev, "%s", build_label);
139155

156+
kfree(build_label);
140157
out:
141158
kfree_skb(skb);
142159
return err;

drivers/bluetooth/btqca.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
#define get_soc_ver(soc_id, rom_ver) \
4949
((le32_to_cpu(soc_id) << 16) | (le16_to_cpu(rom_ver)))
5050

51-
#define QCA_FW_BUILD_VER_LEN 255
5251
#define QCA_HSP_GF_SOC_ID 0x1200
5352
#define QCA_HSP_GF_SOC_MASK 0x0000ff00
5453

0 commit comments

Comments
 (0)