Skip to content

ptp4u: don't apply a denied grant renewal to a running subscription - #595

Open
Support-itecz wants to merge 1 commit into
meta:mainfrom
Support-itecz:ptp4u-denied-renewal
Open

Support-itecz wants to merge 1 commit into
meta:mainfrom
Support-itecz:ptp4u-denied-renewal

Conversation

@Support-itecz

Copy link
Copy Markdown

Summary

handleGeneralMessages handles a REQUEST_UNICAST_TRANSMISSION renewal for a running Announce, Sync or DelayResp subscription by calling SetExpire, SetInterval and SetGclisa first, and only then checking MinSubInterval and MaxSubDuration. An out-of-limit renewal gets a denial grant (duration 0), but the running subscription already carries the requested interval, expiry and reply address.

Signaling is unauthenticated, so any host that can reach port 320 can do this with two packets: a normal grant request, then a renewal with a smaller log interval and a larger duration. With the default limits of 1s and 1h:

  • Log interval -10 with duration 0xFFFFFFFF leaves the subscription at ~977µs for ~136 years. In a loopback reproducer that is about 200 Announce messages per second queued for the client instead of 1. The address comes from the renewal's UDP source, which is spoofable.
  • Log interval -128 converts to a zero time.Duration. On the next tick Start calls intervalTicker.Reset(0), which panics with non-positive interval for Ticker.Reset and takes ptp4u down for every client.

The fix evaluates the limit check once, before the subscription is touched, and only updates a running subscription when the request is within limits. Out-of-limit requests still get the same zero-duration grant, and new subscriptions behave as before. One behavior change worth knowing: the denial for a running subscription now goes to the address the subscription was granted with, not to the source of the rejected renewal.

Test Plan

Added TestSignalingDeniedRenewalKeepsSubscription to ptp/ptp4u/server/server_test.go. It drives handleGeneralMessages over loopback like the existing DelayReq tests. It subscribes to Announce at log interval 0 for 60s, sends a renewal at log interval -7 for 0xFFFFFFFF seconds from a second port, then checks that a denial is sent and the subscription keeps its interval, expiry and address.

Without the change to server.go:

$ go test -count=1 -run TestSignalingDeniedRenewalKeepsSubscription ./ptp/ptp4u/server/
--- FAIL: TestSignalingDeniedRenewalKeepsSubscription (0.01s)
        	Error:      	Not equal:
        	            	expected: 1s
        	            	actual  : 7.8125ms
        	Messages:   	a denied renewal must not change the interval
FAIL

With it:

$ go test -count=5 -race -run TestSignalingDeniedRenewalKeepsSubscription ./ptp/ptp4u/server/
ok  	github.com/facebook/time/ptp/ptp4u/server	1.073s

The zero-interval crash, from a scratch test that sends the renewal at log interval -128 against the unpatched tree:

panic: non-positive interval for Ticker.Reset

goroutine 37 [running]:
time.(*Ticker).Reset(...)
	/usr/local/go/src/time/tick.go:67 +0x7c
github.com/facebook/time/ptp/ptp4u/server.(*SubscriptionClient).Start(...)
	/src/ptp/ptp4u/server/subscription.go:121 +0x2e4

With the fix the same renewal is denied and the subscription stays at 1s.

Also ran on Linux in a golang:1.26 container with libpcap-dev: go build ./..., go test -race ./... (all packages pass) and golangci-lint run ./ptp/ptp4u/... (0 issues).

@meta-cla

meta-cla Bot commented Nov 7, 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

@leoleovich
leoleovich self-requested a review November 18, 2026 16:53
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