macsec: prevent AES-GCM nonce reuse after packet number wrap
Subsystems (4)
PATCH v2 1/1 macsec: prevent AES-GCM nonce reuse after packet number wrap
After allocating the last valid packet number, MACsec wraps next_pn to zero and deactivates the transmit SA. This happens for both 32- and 64-bit types of packet numbers (at values 0xffffffff and 0xffffffffffffffff, respectively).
TX packets that were still getting processed during deactivation keep being processed and then receive packet numbers. The first gets 0 and is correctly dropped, but next_pn is incremented to 1, which makes the next packet take number 1. It then does not get dropped and may induce a reuse of the AES-GCM nonce corresponding to value 1.
This race affects TX packets that have already passed the SA activity
check: packets that observe the inactive SA are correctly dropped. Reactivating the SA after PN wrap without a packet number can also cause nonce reuse. Keep next_pn at 0 after wrap, even if the SA is reactivated, so further packet number allocations return 0 and the corresponding packets are dropped.
--- drivers/net/macsec.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/macsec.c +5 -0
@@ -486,6 +486,9 @@ static pn_t tx_sa_update_pn(struct macsec_tx_sa *tx_sa,spin_lock_bh (&tx_sa->lock); pn = tx_sa->next_pn_halves; +if (unlikely (pn.full64 ==0 )) + goto out; +if (secy->xpn) tx_sa->next_pn++;else
@@ -493,6 +496,8 @@ static pn_t tx_sa_update_pn(struct macsec_tx_sa *tx_sa,if (tx_sa->next_pn ==0 )__macsec_pn_wrapped (secy, tx_sa); + +out:spin_unlock_bh (&tx_sa->lock);return pn;
Signature · 1 line
2.47.3
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 5 lines · On Thu, 8 Oct 2026 08:06:26 +0000 you wrote:
After allocating the last valid packet number, MACsec wraps
next_pnto zero and deactivates the transmit SA. This happens for both 32- and 64-bit types of packet numbers (at values0xffffffffand0xffffffffffffffff, respectively).
Quoted 7 lines
TX packets that were still getting processed during deactivation keep being processed and then receive packet numbers. The first gets 0 and is correctly dropped, but
next_pnis incremented to 1, which makes the next packet take number 1. It then does not get dropped and may induce a reuse of the AES-GCM nonce corresponding to value 1.[...]
Here is the summary with links:
- [net,v2] macsec: prevent AES-GCM nonce reuse after packet number wrap
https://git.kernel.org/netdev/net-next/c/94d51c59f0a8
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html