recover from stale-SAK after dirty macsec docker restart - #4583
Conversation
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@rawal01 Can you please test this issue on 202405 release ? @senthil-nexthop Please have test-gap in sonic-mgmt to cover this. |
|
@senthil-nexthop, can you please add UT for this change |
1c8779b to
d869bd1
Compare
Done, added macsecorch_ut to cover all 3 scenarios. |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Automated Review (SONiC Review Agent)Files reviewed: 2 ( The fix is well-reasoned, addresses a real and well-documented bug, and the three re-key paths are mirror-symmetric. Recursion termination in 🔵 INFO: Inherited partial-failure semantics in
|
|
Added sonic-mgmt tests to verify the fix: sonic-net/sonic-mgmt#24903 |
The partial-failure case is present in existing code, we can review all of them and fix if necessary in a subsequent PR.
Can be followed up separately.
Not a blocker.
|
d869bd1 to
b912828
Compare
|
/azp run |
|
@prsunny : can you help merge this |
|
@prsunny : can you help merge this. |
|
/azp run |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
This PR has backport request label(s) for branch(es): 202511,202605, but is missing required test information. Please make sure you tick the tested branch(es) in the Tested branch section and provide test evidence (e.g., 202511: <test result>) in the Test result section as well in your PR description. ---Powered by SONiC BuildBot
|
|
Hi — this PR has a cherry-pick conflict for the 202605 branch ( If you need help identifying the conflicting changes, let us know. Thanks! Comment by @vaibhavhd via automated tooling |
|
|
@prabhataravind , @prsunny , please help on this PR . Thanks. |
|
Cherry-pick PR to 202511: |
|
The cherry pick conflict has been handled manually. Removing cherry pick conflict label... ---Powered by SONiC BuildBot
|
|
The change is not in msft-202405 yet. @senthil-nexthop, please manually create the cherry pick PR for branch msft-202405. ---Powered by SONiC BuildBot
|
|
The change is not in 202605 yet. @senthil-nexthop, please manually create the cherry pick PR for branch 202605. ---Powered by SONiC BuildBot
|
Why I did it
After a macsec docker restart that doesn't give
macsecmgrdenough time to calldisableMACsecon every port (e.g. systemdTimeoutStopSecelapsed mid-loop, SIGKILL, or simply 16 ports exceeding the stop window), orchagent'sMACsecOrchin-memory state survives with OIDs pointing at SAs whose SAK was distributed in the prior MKA cycle. The post-restartwpa_supplicantnegotiates a fresh SAK and writes it to APPL_DB, but three code paths fail to propagate it to SAI. The result is asymmetric encryption: the ASIC keeps using the stale SAK while userspace believes the re-key happened, so ICV fails on every received frame and LACPDUs / LLDPDUs get silently dropped.How I did it
Three matching re-key paths in
orchagent/macsecorch.cpp, all detected by the presence of asakfield in the incoming SET:taskUpdateIngressSA:wpa_supplicant'smacsec_sonicdriver installs a new ingress SA in two stages: stage-1 writesactive=false+ full key material; stage-2 writesactive=trueonly. After a dirty restart the SA pre-exists, so the legacy path deletes onactive=falseand the subsequentactive=truecreateMACsecSAfails with no SAK to consume. New behaviour: whenactive=falsearrives on an existing SA AND the SET carries a SAK, dodeleteMACsecSA+createMACsecSAinline using THIS sa_attr's key material — atomically. When no SAK is in the SET, original delete-only path is kept (true deactivate).createMACsecSA: the function's "SA already exists -> return task_success" early-exit silently discarded any SAK in the SET.SAI_MACSEC_SA_ATTR_SAKis create-only in SAI, so a re-key requires delete+create. New behaviour: when the SA exists and the SET carries a SAK, treat as re-key:deleteMACsecSA+ recurse. When no SAK is present, keep the existing fast-path. Defends both directions and both code paths that callcreateMACsecSA.taskUpdateEgressSA: the egress "SA already exists" branch only updatednext_pn; the new SAK inthe SET was silently dropped. Mirror the ingress re-key pattern: detect SAK presence,
deleteMACsecSA+createMACsecSAwith the new key material.How to verify it
Pre-requisite: at least one DUT with multiple MACsec-protected ports in a LACP portchannel, peer also macsec-enabled.
show interfaces portchannelshows members Selected andIN_PKTS_OKadvancing.sudo docker kill -s 9 macsec.IN_PKTS_OKcontinues to climb on both ends;IN_PKTS_NOT_VALIDandIN_PKTS_NOT_USING_SAstay at zero;show lldp tableshows the peer entry.