Re: [PATCH net] macsec: prevent AES-GCM nonce reuse after packet number wrap
From: Jérémy Jean
Date: Thu Oct 01 2026 - 11:22:06 EST
On 2026-10-01 11:43, Sabrina Dubroca wrote:
2026-09-30, 20:33:33 +0000, Jérémy Jean wrote:
When MACsec uses 32-bit packet numbers, 0xffffffff is the last valid
packet number
This makes it sound like it's only a problem for 32b packet numbers,
but I think it affects both? Sure it's unlikely with 64b unless we
start from a large offset, but a well-behaved userspace should also
rekey and switch SAs before we ever wrap to avoid losing packets while
the rekey completes (but yes, "losing packets" is not as bad as
"breaking crypto").
and after allocating it, MACsec deactivates the
transmit SA and wraps the next packet number to zero. Packets already
in flight can still be processed after that.
So this is more of a race condition than a full "forever" bug. I think
commit messages should be clear about that (and that doesn't mean it's
not bad or not worth patching, but it's worth mentioning).
Once TX operations hit macsec_encrypt -> macsec_txsa_get and see
!sa->active, packets will be dropped and nonce reuse stops.
The first late packet gets packet number zero and is dropped, but
tx_sa_update_pn() has already advanced the stored counter to one before
macsec_encrypt() drops it. A second late packet can then be sent with
packet number one again, reusing the AES-GCM nonce from the start of the
SA.
Keep next_pn at zero after wrap so all late packets are dropped.
"late packet" is defined on the RX side, but it doesn't make sense on
the TX path.
The diff looks good to me.
Below is suggestion of a hopefully better description.
---
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 only affects TX packets that have already passed the SA
activity check: new packets after deactivation are correctly dropped.
Keep next_pn at 0 after wrap and return early so that the packets that
finishes getting processed are dropped.
---
I can send a v2 if needed.
Jérémy