[mac] clear mode2 key only on mac destruction (#12243)

This commit adjusts how the `MAC Mode2 key` is cleared to avoid
invalidating it in certain runtime flows.

In the previous behavior, when the OpenThread instance is initialized,
Mac is constructed and sets the Mode2 key. If
otInstanceErasePersistentInfo is called afterwards, the call chain
reaches KeyManager::DestroyTemporaryKeys(), where the Mode2 key is
cleared. However, there is no subsequent point where the Mode2 key is
re-set. If Thread is then enabled and a frame using Key ID Mode 2 is
received, the Mode2 key remains invalid, which can lead to incorrect
behavior.

To fix this, this commit removes the Mode2 key clearing from
`KeyManager::DestroyTemporaryKeys()` and clears the Mode2 key in the
Mac destructor. This ensures that the Mode2 key stays valid for the
lifetime of the Mac (and thus the OpenThread instance) after
initialization, and is only cleared when Mac is destroyed.
This commit is contained in:
xusiyu
2026-01-05 13:14:00 -08:00
committed by GitHub
parent 2bb49ea22e
commit 946af205a1
2 changed files with 5 additions and 1 deletions
+5
View File
@@ -134,6 +134,11 @@ public:
*/
explicit Mac(Instance &aInstance);
/**
* Clears the Mode2Key on destruction.
*/
~Mac(void) { ClearMode2Key(); }
/**
* Starts an IEEE 802.15.4 Active Scan.
*
-1
View File
@@ -693,7 +693,6 @@ void KeyManager::DestroyTemporaryKeys(void)
mMleKey.Clear();
mKek.Clear();
Get<Mac::SubMac>().ClearMacKeys();
Get<Mac::Mac>().ClearMode2Key();
}
void KeyManager::DestroyPersistentKeys(void) { Get<Crypto::Storage::KeyRefManager>().DestroyPersistentKeys(); }