Skip to content

sptp: only answer bare DELAY_REQ probes in ptping - #600

Open
Support-itecz wants to merge 1 commit into
meta:mainfrom
Support-itecz:sptp-ptping-loop
Open

Support-itecz wants to merge 1 commit into
meta:mainfrom
Support-itecz:sptp-ptping-loop

Conversation

@Support-itecz

Copy link
Copy Markdown

Summary

When sptp gets a datagram on port 319 from a host it doesn't sync to, it falls through to ptping and answers with a stamped DELAY_REQ plus an ANNOUNCE. ptping answered more than ptping probes:

  • It never checked the message type or the OriginTimestamp, so it answered SYNCs, and it answered the stamped DELAY_REQ that handleDelayReq itself sends. Two sptp clients that are not each other's servers keep answering each other once one spoofed DELAY_REQ (source set to the other client) starts the exchange. The same happens between an sptp client and a ptp4u it is not configured for, because ptp4u answers an sptp DELAY_REQ with a SYNC.
  • RunListener passed the whole receive buffer instead of buf[:bbuf], so the length checks in FromBytes never saw the datagram size. A single 0x01 octet was parsed against the stale or zeroed rest of the buffer and answered with two packets.

This is a UDP application-layer loop (the CVE-2024-2169 "Loop DoS" class). One unauthenticated, spoofed packet starts traffic that never stops, and every loop runs inline in the event-port listener goroutine that also handles SYNCs from the configured GMs. A host that can send spoofed UDP to port 319 of two sptp clients can start as many loops as it likes.

ptping now answers only a bare DELAY_REQ (type DELAY_REQ, empty OriginTimestamp). That is the same test collectReply already uses to tell a reply from a probe ("a DELAY_REQ carrying a stamped OriginTimestamp, which a genuine inbound request never has"). The requester in the tree, pingUnicast behind ptpcheck ptping, sends ReqDelay with an empty OriginTimestamp, so real probes are still answered. The listener now passes buf[:bbuf].

TestPTPing used a zero header (a SYNC) as its valid probe. It now sends ReqDelay, which is what a ptping probe looks like on the wire.

Test Plan

Two new regression tests in ptp/sptp/client/sptp_test.go:

  • TestPtpingIgnoresReplies answers a real probe, then feeds the captured reply and a stamped SYNC back into ptping. Neither may be answered.
  • TestRunListenerPtpingShortDatagram sends a 1-octet datagram from an unknown host through RunListener. Nothing may be written.

Without the change to sptp.go:

$ go test -count=1 -run 'TestPTPing|TestPtpingIgnoresReplies|TestRunListenerPtpingShortDatagram' -v ./ptp/sptp/client/
--- PASS: TestPTPing (0.00s)
--- FAIL: TestPtpingIgnoresReplies (0.00s)
        expected call at /src/ptp/sptp/client/sptp_test.go:1022 has already been called the max number of times
--- FAIL: TestRunListenerPtpingShortDatagram (1.00s)
        Error:      	Should be zero, but was 2
        Messages:   	a 1-octet datagram must not be answered
FAIL

With it, on Linux with Go 1.26 (the package doesn't build on macOS, see #593):

$ go build ./...                      # ok
$ go test -race -count=1 ./...        # all packages ok
$ GOOS=linux golangci-lint run ./ptp/sptp/client/
0 issues.

Loop reproducer (not committed): two SPTP instances joined by an in-memory UDP network, neither configured as the other's server, with one DELAY_REQ injected into A as if it came from B. The in-memory network has no latency, so the rate is an upper bound. On real hosts it is limited by RTT and TX timestamping, but it still never stops.
before after
packets in 200ms after one spoofed DELAY_REQ 5681 2
packets sent in reply to a 1-byte datagram 2 0
packets sent in reply to a SYNC from an unconfigured GM 2 0

A datagram on port 319 from a host the client does not sync to falls
through to ptping, which answered it without checking the message type
or the OriginTimestamp. It answered SYNCs and the stamped DELAY_REQ
that handleDelayReq sends, so two sptp clients that are not each
other's servers, or an sptp client and a ptp4u it does not use, keep
answering each other once a single spoofed DELAY_REQ starts them.

The listener also handed ptping the whole receive buffer instead of
buf[:bbuf], so a 1-octet datagram was parsed against stale bytes and
answered.

Answer only a DELAY_REQ with an empty OriginTimestamp, the same test
collectReply uses to tell a reply from a probe, and parse only the
datagram.
@meta-cla

meta-cla Bot commented Nov 18, 2026

Copy link
Copy Markdown

Hi @Support-itecz!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@leoleovich

Copy link
Copy Markdown
Contributor

Unless you sign CLA we can't review this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants