From: "Jérémy Jean" <jeremy.jean@oss.cyber.gouv.fr>
To: Sabrina Dubroca <sd@queasysnail.net>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH net] macsec: prevent AES-GCM nonce reuse after packet number wrap
Date: Thu, 01 Oct 2026 17:08:29 +0200 [thread overview]
Message-ID: <864ee7d8f719deea74ff3e5aba1bc949@oss.cyber.gouv.fr> (raw)
In-Reply-To: <ar4rKxYd7Csm6l2t@krikkit>
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
next prev parent reply other threads:[~2026-10-01 15:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 20:33 Jérémy Jean
2026-09-30 20:38 ` netdev-bot+sinfo
2026-10-01 9:43 ` Sabrina Dubroca
2026-10-01 15:08 ` Jérémy Jean [this message]
2026-10-02 11:35 ` netdev-bot+sashiko
2026-10-02 15:22 ` Jérémy Jean
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=864ee7d8f719deea74ff3e5aba1bc949@oss.cyber.gouv.fr \
--to=jeremy.jean@oss.cyber.gouv.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sd@queasysnail.net \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®