0c1637fb04c2b96745a4c3d4dc7088572fd43810
[openwrt/staging/blogic.git] /
1 From 447b0398a9cd41ca343dfd43e555af92d6214487 Mon Sep 17 00:00:00 2001
2 From: Bhagavathi Perumal S <quic_bperumal@quicinc.com>
3 Date: Fri, 24 Mar 2023 16:57:00 +0200
4 Subject: [PATCH] wifi: ath11k: Fix invalid management rx frame length issue
5
6 The WMI management rx event has multiple arrays of TLVs, however the common
7 WMI TLV parser won't handle multiple TLV tags of same type.
8 So the multiple array tags of WMI management rx TLV is parsed incorrectly
9 and the length calculated becomes wrong when the target sends multiple
10 array tags.
11
12 Add separate TLV parser to handle multiple arrays for WMI management rx
13 TLV. This fixes invalid length issue when the target sends multiple array
14 tags.
15
16 Tested-on: QCN9074 hw1.0 PCI WLAN.HK.2.7.0.1-01744-QCAHKSWPL_SILICONZ-1
17
18 Signed-off-by: Bhagavathi Perumal S <quic_bperumal@quicinc.com>
19 Co-developed-by: Nagarajan Maran <quic_nmaran@quicinc.com>
20 Signed-off-by: Nagarajan Maran <quic_nmaran@quicinc.com>
21 Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>
22 Link: https://lore.kernel.org/r/20230320133840.30162-1-quic_nmaran@quicinc.com
23 ---
24 drivers/net/wireless/ath/ath11k/wmi.c | 45 +++++++++++++++++++++------
25 1 file changed, 35 insertions(+), 10 deletions(-)
26
27 --- a/drivers/net/wireless/ath/ath11k/wmi.c
28 +++ b/drivers/net/wireless/ath/ath11k/wmi.c
29 @@ -82,6 +82,12 @@ struct wmi_tlv_fw_stats_parse {
30 bool chain_rssi_done;
31 };
32
33 +struct wmi_tlv_mgmt_rx_parse {
34 + const struct wmi_mgmt_rx_hdr *fixed;
35 + const u8 *frame_buf;
36 + bool frame_buf_done;
37 +};
38 +
39 static const struct wmi_tlv_policy wmi_tlv_policies[] = {
40 [WMI_TAG_ARRAY_BYTE]
41 = { .min_len = 0 },
42 @@ -5633,28 +5639,49 @@ static int ath11k_pull_vdev_stopped_para
43 return 0;
44 }
45
46 +static int ath11k_wmi_tlv_mgmt_rx_parse(struct ath11k_base *ab,
47 + u16 tag, u16 len,
48 + const void *ptr, void *data)
49 +{
50 + struct wmi_tlv_mgmt_rx_parse *parse = data;
51 +
52 + switch (tag) {
53 + case WMI_TAG_MGMT_RX_HDR:
54 + parse->fixed = ptr;
55 + break;
56 + case WMI_TAG_ARRAY_BYTE:
57 + if (!parse->frame_buf_done) {
58 + parse->frame_buf = ptr;
59 + parse->frame_buf_done = true;
60 + }
61 + break;
62 + }
63 + return 0;
64 +}
65 +
66 static int ath11k_pull_mgmt_rx_params_tlv(struct ath11k_base *ab,
67 struct sk_buff *skb,
68 struct mgmt_rx_event_params *hdr)
69 {
70 - const void **tb;
71 + struct wmi_tlv_mgmt_rx_parse parse = { };
72 const struct wmi_mgmt_rx_hdr *ev;
73 const u8 *frame;
74 int ret;
75
76 - tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
77 - if (IS_ERR(tb)) {
78 - ret = PTR_ERR(tb);
79 - ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
80 + ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
81 + ath11k_wmi_tlv_mgmt_rx_parse,
82 + &parse);
83 + if (ret) {
84 + ath11k_warn(ab, "failed to parse mgmt rx tlv %d\n",
85 + ret);
86 return ret;
87 }
88
89 - ev = tb[WMI_TAG_MGMT_RX_HDR];
90 - frame = tb[WMI_TAG_ARRAY_BYTE];
91 + ev = parse.fixed;
92 + frame = parse.frame_buf;
93
94 if (!ev || !frame) {
95 ath11k_warn(ab, "failed to fetch mgmt rx hdr");
96 - kfree(tb);
97 return -EPROTO;
98 }
99
100 @@ -5673,7 +5700,6 @@ static int ath11k_pull_mgmt_rx_params_tl
101
102 if (skb->len < (frame - skb->data) + hdr->buf_len) {
103 ath11k_warn(ab, "invalid length in mgmt rx hdr ev");
104 - kfree(tb);
105 return -EPROTO;
106 }
107
108 @@ -5685,7 +5711,6 @@ static int ath11k_pull_mgmt_rx_params_tl
109
110 ath11k_ce_byte_swap(skb->data, hdr->buf_len);
111
112 - kfree(tb);
113 return 0;
114 }
115