mirror of
https://github.com/slackhq/nebula.git
synced 2026-11-17 21:26:52 +01:00
multiport: derive lane sessions on demand, install once authenticated
How many lanes a tunnel has is partly the peer's call: it advertises how many it sends on and we have to be able to receive all of them, up to the header's 256. Deriving them all when the handshake completes meant a peer advertising a large count cost us a replay window and two cipher states per lane, per tunnel, for lanes it may never send on. Derive each session on the first packet that needs it instead. The TX side asks through laneSet.session, which installs on the spot — we only ask for lanes we chose to send on. The RX side can't do that: anyone who can spoof a tunnel's local index can name any lane, and installing on sight would hand them the same allocation for free. So laneSession hands back a session without publishing it and reports that it did; outside.go installs it only once the packet has decrypted, which is the first moment the lane is known to be real. A spoofer gets an HKDF per packet and nothing retained. Only the session table is sized by the peer's advert now. txAddr, demand and probe are sized by the lanes we will actually send on, so the peer can no longer size our per-lane tx state either. Also refuse relayed lane packets before the session lookup rather than after, so a junk relay packet can't reach the derivation path at all.
This commit is contained in:
1 parent
fb20de39b2
commit
8c5c740571
6 files changed
+288
-103
No files matched your search
+5
-12
@@ -721,12 +721,10 @@ func (hm *HandshakeManager) laneAdvert() *handshake.LaneDetails {
|
||||
}
|
||||
}
|
||||
|
||||
// maybeAllocLanes derives the multiport lane sessions for a just-completed
|
||||
// tunnel. Must run before the hostinfo becomes visible in the hostmap: the data
|
||||
// plane reads hostinfo.lanes with no synchronization at all.
|
||||
//
|
||||
// A failure here costs the tunnel its lanes, not the tunnel: the base session is
|
||||
// already usable and every lane the data plane wants falls back to it.
|
||||
// maybeAllocLanes sets up the multiport lanes for a just-completed tunnel. Must
|
||||
// run before the hostinfo becomes visible in the hostmap: the data plane reads
|
||||
// hostinfo.lanes without synchronizing on it. The sessions themselves are derived
|
||||
// later, on the first packet that needs each one.
|
||||
func (hm *HandshakeManager) maybeAllocLanes(hostinfo *HostInfo, result *handshake.Result) {
|
||||
if hm.config.laneCount == 0 || result.PeerPortCount == 0 {
|
||||
return
|
||||
@@ -735,12 +733,7 @@ func (hm *HandshakeManager) maybeAllocLanes(hostinfo *HostInfo, result *handshak
|
||||
return
|
||||
}
|
||||
|
||||
ls, err := newLaneSet(result, hm.config.laneCount, hm.f.myVpnAddrs[0], hostinfo.vpnAddrs[0])
|
||||
if err != nil {
|
||||
hostinfo.logger(hm.l).Error("Failed to derive multiport lanes", "error", err)
|
||||
return
|
||||
}
|
||||
hostinfo.lanes = ls
|
||||
hostinfo.lanes = newLaneSet(result, hm.config.laneCount, hm.f.myVpnAddrs[0], hostinfo.vpnAddrs[0])
|
||||
}
|
||||
|
||||
// beginHandshake handles an incoming handshake packet that doesn't match any
|
||||
|
||||
Reference in new issue
Block a user