Skip to content

Commit d3d358e

Browse files
Venkateswara Naralasettykvalo
authored andcommitted
ath11k: add spectral/CFR buffer validation support
Currently there is no validation on the spectral/CFR report over the db ring buffers from the hardware. Improper/incomplete DMA by the target can result in invalid data received by host. Due to this we may populate incorrect data to user space. This buffer validation support fix this issues by filling some magic value in the buffer during buffer replenish and check for the magic value in the buffer received by the target. If host detect magic value in the received buffer it will drop the buffer. Tested-on: IPQ8074 WLAN.HK.2.4.0.1-01467-QCAHKSWPL_SILICONZ-1 Signed-off-by: Venkateswara Naralasetty <[email protected]> Signed-off-by: Kalle Valo <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7e2ea2e commit d3d358e

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

drivers/net/wireless/ath/ath11k/dbring.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,35 @@
66
#include "core.h"
77
#include "debug.h"
88

9+
#define ATH11K_DB_MAGIC_VALUE 0xdeadbeaf
10+
11+
int ath11k_dbring_validate_buffer(struct ath11k *ar, void *buffer, u32 size)
12+
{
13+
u32 *temp;
14+
int idx;
15+
16+
size = size >> 2;
17+
18+
for (idx = 0, temp = buffer; idx < size; idx++, temp++) {
19+
if (*temp == ATH11K_DB_MAGIC_VALUE)
20+
return -EINVAL;
21+
}
22+
23+
return 0;
24+
}
25+
26+
static void ath11k_dbring_fill_magic_value(struct ath11k *ar,
27+
void *buffer, u32 size)
28+
{
29+
u32 *temp;
30+
int idx;
31+
32+
size = size >> 2;
33+
34+
for (idx = 0, temp = buffer; idx < size; idx++, temp++)
35+
*temp++ = ATH11K_DB_MAGIC_VALUE;
36+
}
37+
938
static int ath11k_dbring_bufs_replenish(struct ath11k *ar,
1039
struct ath11k_dbring *ring,
1140
struct ath11k_dbring_element *buff)
@@ -26,6 +55,7 @@ static int ath11k_dbring_bufs_replenish(struct ath11k *ar,
2655

2756
ptr_unaligned = buff->payload;
2857
ptr_aligned = PTR_ALIGN(ptr_unaligned, ring->buf_align);
58+
ath11k_dbring_fill_magic_value(ar, ptr_aligned, ring->buf_sz);
2959
paddr = dma_map_single(ab->dev, ptr_aligned, ring->buf_sz,
3060
DMA_FROM_DEVICE);
3161

drivers/net/wireless/ath/ath11k/dbring.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,6 @@ int ath11k_dbring_get_cap(struct ath11k_base *ab,
7676
struct ath11k_dbring_cap *db_cap);
7777
void ath11k_dbring_srng_cleanup(struct ath11k *ar, struct ath11k_dbring *ring);
7878
void ath11k_dbring_buf_cleanup(struct ath11k *ar, struct ath11k_dbring *ring);
79+
int ath11k_dbring_validate_buffer(struct ath11k *ar, void *data, u32 size);
80+
7981
#endif /* ATH11K_DBRING_H */

drivers/net/wireless/ath/ath11k/spectral.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ int ath11k_spectral_process_fft(struct ath11k *ar,
581581
u16 length, freq;
582582
u8 chan_width_mhz, bin_sz;
583583
int ret;
584+
u32 check_length;
584585

585586
lockdep_assert_held(&ar->spectral.lock);
586587

@@ -614,6 +615,13 @@ int ath11k_spectral_process_fft(struct ath11k *ar,
614615
return -EINVAL;
615616
}
616617

618+
check_length = sizeof(*fft_report) + (num_bins * ab->hw_params.spectral.fft_sz);
619+
ret = ath11k_dbring_validate_buffer(ar, data, check_length);
620+
if (ret) {
621+
ath11k_warn(ar->ab, "found magic value in fft data, dropping\n");
622+
return ret;
623+
}
624+
617625
ret = ath11k_spectral_pull_search(ar, data, &search);
618626
if (ret) {
619627
ath11k_warn(ab, "failed to pull search report %d\n", ret);
@@ -747,6 +755,12 @@ static int ath11k_spectral_process_data(struct ath11k *ar,
747755
goto err;
748756
}
749757

758+
ret = ath11k_dbring_validate_buffer(ar, data, tlv_len);
759+
if (ret) {
760+
ath11k_warn(ar->ab, "found magic value in spectral summary, dropping\n");
761+
goto err;
762+
}
763+
750764
summary = (struct spectral_summary_fft_report *)tlv;
751765
ath11k_spectral_pull_summary(ar, &param->meta,
752766
summary, &summ_rpt);

0 commit comments

Comments
 (0)