* [PATCH 6.6.y 0/2] wifi: ath12k: fix M3 buffer reuse in my CVE-2024-40979 backport
@ 2026-10-12 16:59 Artem Dinaburg
2026-10-12 16:59 ` [PATCH 6.6.y 1/2] wifi: ath12k: fix reusing m3 memory Artem Dinaburg
2026-10-12 16:59 ` [PATCH 6.6.y 2/2] wifi: ath12k: copy M3 firmware when reusing the buffer Artem Dinaburg
0 siblings, 2 replies; 3+ messages in thread
From: Artem Dinaburg @ 2026-10-12 16:59 UTC (permalink / raw)
To: stable
Cc: Greg Kroah-Hartman, Sasha Levin, Baochen Qiang, Kalle Valo,
Jeff Johnson, Jeff Johnson, Vasanthakumar Thiagarajan, ath12k,
linux-wireless, linux-kernel
Hi Greg, Sasha, and ath12k maintainers,
My backport of 05090ae82f44 ("wifi: ath12k: check M3 buffer size as well
whey trying to reuse it"), which landed in 6.6.158 as 9a38ba5561d9, does
not match upstream. When the existing M3 buffer is large enough, it
returns early without copying the new image or updating its length.
Upstream copies the current image into the reused buffer every time. In
6.6.y, recovery or resume therefore keeps the old M3 image unless the new
one is larger.
Restoring the copy needs one more upstream fix first. Once a smaller
image can be copied into the buffer, m3_mem->size can shrink below the
allocation size, and that shrunken size is later passed to
dma_free_coherent(). Upstream fixed this in 00575bb44b2c ("wifi: ath12k:
fix reusing m3 memory") by tracking the allocation size separately.
1/2 backports 00575bb44b2c.
2/2 fixes my backport by restoring the upstream copy on reuse. It has
no upstream equivalent; upstream never had the early return.
6.12.y already copies on reuse but lacked 00575bb44b2c; my backport of
it is now queued for 6.12.y. 6.18.y and 7.2.y already have the fix, and
6.1.y has no ath12k driver.
Testing: both patches apply to v6.6.158 and on top of the current 6.6
stable queue. An x86_64 allmodconfig build with CONFIG_WERROR=y is clean,
and ath12k also builds cleanly with W=1. I tested ath12k_qmi_m3_load()
and ath12k_qmi_m3_free() in userspace with firmware and DMA stubs under
ASan/UBSan, covering same-size, smaller, and larger replacement images,
plus allocation and firmware-request failures. I did not test on ath12k
hardware.
Previous series: https://lore.kernel.org/all/20260929025856.85683-1-artem@trailofbits.com/
An LLM helped compare the backport with upstream, prepare these patches,
and build and test them. I reviewed the results.
Thanks,
Artem Dinaburg
Artem Dinaburg (1):
wifi: ath12k: copy M3 firmware when reusing the buffer
Baochen Qiang (1):
wifi: ath12k: fix reusing m3 memory
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 6.6.y 1/2] wifi: ath12k: fix reusing m3 memory
2026-10-12 16:59 [PATCH 6.6.y 0/2] wifi: ath12k: fix M3 buffer reuse in my CVE-2024-40979 backport Artem Dinaburg
@ 2026-10-12 16:59 ` Artem Dinaburg
2026-10-12 16:59 ` [PATCH 6.6.y 2/2] wifi: ath12k: copy M3 firmware when reusing the buffer Artem Dinaburg
1 sibling, 0 replies; 3+ messages in thread
From: Artem Dinaburg @ 2026-10-12 16:59 UTC (permalink / raw)
To: stable
Cc: Greg Kroah-Hartman, Sasha Levin, Baochen Qiang, Kalle Valo,
Jeff Johnson, Jeff Johnson, Vasanthakumar Thiagarajan, ath12k,
linux-wireless, linux-kernel
From: Baochen Qiang <baochen.qiang@oss.qualcomm.com>
[ Upstream commit 00575bb44b2c2aa53d0a768de2b80c9c1af0174d ]
During firmware recovery or suspend/resume, m3 memory could be reused if
the size of the new m3 binary is equal to or less than that of the
existing memory. There will be issues for the latter case, since
m3_mem->size will be updated with a smaller value and this value is
eventually used in the free path, where the original total size should be
used instead.
To fix it, add a new member in m3_mem_region structure to track the original
memory size and use it in free path.
Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c5-00302-QCAHMTSWPL_V1.0_V2.0_SILICONZ-1.115823.3
[ Backport to 6.6.y: 6.6.y only loads the separate m3.bin, so use
fw->size where upstream uses m3_len. The upstream change to the
allocation-failure message only matters for the firmware-N.bin path,
which 6.6.y lacks, so it is dropped. The copyright lines are left as
they are.
On its own this changes nothing in 6.6.y, because the reuse path
currently returns before m3_mem->size is updated. It is needed by the
following fix to my 6.6.y backport of 05090ae82f44, which copies a
possibly smaller image into the reused buffer as upstream does. ]
Fixes: 05090ae82f44 ("wifi: ath12k: check M3 buffer size as well whey trying to reuse it")
Signed-off-by: Baochen Qiang <baochen.qiang@oss.qualcomm.com>
Reviewed-by: Vasanthakumar Thiagarajan <vasanthakumar.thiagarajan@oss.qualcomm.com>
Link: https://patch.msgid.link/20251029-ath12k-fix-m3-reuse-v1-1-69225bacfc5d@oss.qualcomm.com
Signed-off-by: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
Assisted-by: LLM
Signed-off-by: Artem Dinaburg <artem@trailofbits.com>
---
drivers/net/wireless/ath/ath12k/qmi.c | 7 +++++--
drivers/net/wireless/ath/ath12k/qmi.h | 3 +++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/net/wireless/ath/ath12k/qmi.c b/drivers/net/wireless/ath/ath12k/qmi.c
index 48d0043fcee9..86cc61dba094 100644
--- a/drivers/net/wireless/ath/ath12k/qmi.c
+++ b/drivers/net/wireless/ath/ath12k/qmi.c
@@ -2518,9 +2518,10 @@ static void ath12k_qmi_m3_free(struct ath12k_base *ab)
if (!m3_mem->vaddr)
return;
- dma_free_coherent(ab->dev, m3_mem->size,
+ dma_free_coherent(ab->dev, m3_mem->total_size,
m3_mem->vaddr, m3_mem->paddr);
m3_mem->vaddr = NULL;
+ m3_mem->total_size = 0;
m3_mem->size = 0;
}
@@ -2542,7 +2543,7 @@ static int ath12k_qmi_m3_load(struct ath12k_base *ab)
/* In recovery/resume cases, M3 buffer is not freed, try to reuse that */
if (m3_mem->vaddr) {
- if (m3_mem->size >= fw->size) {
+ if (m3_mem->total_size >= fw->size) {
release_firmware(fw);
return 0;
}
@@ -2561,6 +2562,8 @@ static int ath12k_qmi_m3_load(struct ath12k_base *ab)
return -ENOMEM;
}
+ m3_mem->total_size = fw->size;
+
memcpy(m3_mem->vaddr, fw->data, fw->size);
m3_mem->size = fw->size;
release_firmware(fw);
diff --git a/drivers/net/wireless/ath/ath12k/qmi.h b/drivers/net/wireless/ath/ath12k/qmi.h
index a996c6d57aa7..62c7a526f111 100644
--- a/drivers/net/wireless/ath/ath12k/qmi.h
+++ b/drivers/net/wireless/ath/ath12k/qmi.h
@@ -119,6 +119,9 @@ struct target_info {
};
struct m3_mem_region {
+ /* total memory allocated */
+ u32 total_size;
+ /* actual memory being used */
u32 size;
dma_addr_t paddr;
void *vaddr;
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 6.6.y 2/2] wifi: ath12k: copy M3 firmware when reusing the buffer
2026-10-12 16:59 [PATCH 6.6.y 0/2] wifi: ath12k: fix M3 buffer reuse in my CVE-2024-40979 backport Artem Dinaburg
2026-10-12 16:59 ` [PATCH 6.6.y 1/2] wifi: ath12k: fix reusing m3 memory Artem Dinaburg
@ 2026-10-12 16:59 ` Artem Dinaburg
1 sibling, 0 replies; 3+ messages in thread
From: Artem Dinaburg @ 2026-10-12 16:59 UTC (permalink / raw)
To: stable
Cc: Greg Kroah-Hartman, Sasha Levin, Baochen Qiang, Kalle Valo,
Jeff Johnson, Jeff Johnson, Vasanthakumar Thiagarajan, ath12k,
linux-wireless, linux-kernel
This fixes my 6.6.y backport of upstream commit 05090ae82f44 ("wifi:
ath12k: check M3 buffer size as well whey trying to reuse it"). There is
no corresponding upstream commit, because upstream never had this bug.
When the existing M3 buffer is large enough for the new m3.bin, my
backport releases the firmware and returns early. The new image is never
copied, and m3_mem->size keeps the old length. Upstream instead jumps to
skip_m3_alloc, which copies the current image into the existing buffer
and records its length. As a result, after recovery or resume, 6.6.y
gives the firmware the previous M3 image whenever the new one is the
same size or smaller. A larger image is reallocated and loaded.
Replace the early return with the upstream goto skip_m3_alloc. The
previous patch, a backport of upstream commit 00575bb44b2c ("wifi:
ath12k: fix reusing m3 memory"), keeps the allocation size in
total_size. So copying a smaller image no longer changes the size passed
to dma_free_coherent().
Fixes: 9a38ba5561d9 ("wifi: ath12k: check M3 buffer size as well whey trying to reuse it")
Assisted-by: LLM
Signed-off-by: Artem Dinaburg <artem@trailofbits.com>
---
drivers/net/wireless/ath/ath12k/qmi.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/net/wireless/ath/ath12k/qmi.c b/drivers/net/wireless/ath/ath12k/qmi.c
index 86cc61dba094..8dc1c8e0c7b1 100644
--- a/drivers/net/wireless/ath/ath12k/qmi.c
+++ b/drivers/net/wireless/ath/ath12k/qmi.c
@@ -2543,10 +2543,8 @@ static int ath12k_qmi_m3_load(struct ath12k_base *ab)
/* In recovery/resume cases, M3 buffer is not freed, try to reuse that */
if (m3_mem->vaddr) {
- if (m3_mem->total_size >= fw->size) {
- release_firmware(fw);
- return 0;
- }
+ if (m3_mem->total_size >= fw->size)
+ goto skip_m3_alloc;
/* Old buffer is too small, free and reallocate */
ath12k_qmi_m3_free(ab);
@@ -2564,6 +2562,7 @@ static int ath12k_qmi_m3_load(struct ath12k_base *ab)
m3_mem->total_size = fw->size;
+skip_m3_alloc:
memcpy(m3_mem->vaddr, fw->data, fw->size);
m3_mem->size = fw->size;
release_firmware(fw);
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-12 16:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-12 16:59 [PATCH 6.6.y 0/2] wifi: ath12k: fix M3 buffer reuse in my CVE-2024-40979 backport Artem Dinaburg
2026-10-12 16:59 ` [PATCH 6.6.y 1/2] wifi: ath12k: fix reusing m3 memory Artem Dinaburg
2026-10-12 16:59 ` [PATCH 6.6.y 2/2] wifi: ath12k: copy M3 firmware when reusing the buffer Artem Dinaburg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox