[PATCH 1/2] WPA: Explicitly clear PTK derivation buffers
Xiaoyi Suo
18102059357 at 163.com
Sun Nov 22 16:10:00 PST 2026
wpa_pmk_to_ptk() builds the PTK in a local tmp[] buffer, and builds a
local data[] buffer with the addresses, the nonces, and the optional Z
value (DHss for 802.1X auth in Authentication frames, or the DPP shared
secret). Both are cleared with os_memset() before the function returns.
Nothing reads them after the clear. So the compiler can drop the clear,
and GCC 13.3 and Clang 18 do drop it at -O2. The keys and the shared
secret are still in the stack frame when the function returns.
The same file already uses forced_memzero() for the same kind of buffer
in pasn_pmk_to_ptk() and wpa_pmk_r1_to_ptk(). Use it here too.
This is a hardening change. It removes the extra copy that stays in
memory. It does not fix a known read-back path.
Signed-off-by: Xiaoyi Suo <18102059357 at 163.com>
---
src/common/wpa_common.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/common/wpa_common.c b/src/common/wpa_common.c
index 106f6ef..1743097 100644
--- a/src/common/wpa_common.c
+++ b/src/common/wpa_common.c
@@ -819,8 +819,8 @@ int wpa_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const char *label,
ptk->kck2_len = 0;
ptk->ptk_len = ptk_len;
- os_memset(tmp, 0, sizeof(tmp));
- os_memset(data, 0, data_len);
+ forced_memzero(tmp, sizeof(tmp));
+ forced_memzero(data, data_len);
return 0;
}
--
2.55.0.windows.5
More information about the Hostap
mailing list