Commit 857b1cde authored by aligungr's avatar aligungr

NAS replay protection bug fix

parent 8bf2f54b
...@@ -363,13 +363,18 @@ bool NasMm::checkForReplay(const nas::SecuredMmMessage &msg) ...@@ -363,13 +363,18 @@ bool NasMm::checkForReplay(const nas::SecuredMmMessage &msg)
{ {
int n = static_cast<int>(msg.sequenceNumber); int n = static_cast<int>(msg.sequenceNumber);
for (int seq : m_lastNasSequenceNums) if (m_usim->m_currentNsCtx)
{
auto &lastNasSequenceNums = m_usim->m_currentNsCtx->lastNasSequenceNums;
for (int seq : lastNasSequenceNums)
if (seq == n) if (seq == n)
return false; return false;
m_lastNasSequenceNums.push_back(n); lastNasSequenceNums.push_back(n);
while (m_lastNasSequenceNums.size() > 16) while (lastNasSequenceNums.size() > 16)
m_lastNasSequenceNums.pop_front(); lastNasSequenceNums.pop_front();
}
return true; return true;
} }
......
...@@ -65,8 +65,6 @@ class NasMm ...@@ -65,8 +65,6 @@ class NasMm
int64_t m_lastTimePlmnSearchFailureLogged{}; int64_t m_lastTimePlmnSearchFailureLogged{};
// Last time MM state changed // Last time MM state changed
int64_t m_lastTimeMmStateChange{}; int64_t m_lastTimeMmStateChange{};
// Received NAS sequence numbers for replay protection
std::deque<int> m_lastNasSequenceNums{};
friend class UeCmdHandler; friend class UeCmdHandler;
friend class NasSm; friend class NasSm;
......
...@@ -423,6 +423,8 @@ struct NasSecurityContext ...@@ -423,6 +423,8 @@ struct NasSecurityContext
nas::ETypeOfIntegrityProtectionAlgorithm integrity{}; nas::ETypeOfIntegrityProtectionAlgorithm integrity{};
nas::ETypeOfCipheringAlgorithm ciphering{}; nas::ETypeOfCipheringAlgorithm ciphering{};
std::deque<int> lastNasSequenceNums{};
void updateDownlinkCount(const NasCount &validatedCount) void updateDownlinkCount(const NasCount &validatedCount)
{ {
downlinkCount.overflow = validatedCount.overflow; downlinkCount.overflow = validatedCount.overflow;
...@@ -476,6 +478,7 @@ struct NasSecurityContext ...@@ -476,6 +478,7 @@ struct NasSecurityContext
ctx.keys = keys.deepCopy(); ctx.keys = keys.deepCopy();
ctx.integrity = integrity; ctx.integrity = integrity;
ctx.ciphering = ciphering; ctx.ciphering = ciphering;
ctx.lastNasSequenceNums = lastNasSequenceNums;
return ctx; return ctx;
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment