Skip to content

sptp-exporter: don't serve pprof on the exporter port - #601

Open
Support-itecz wants to merge 1 commit into
meta:mainfrom
Support-itecz:sptp-exporter-pprof
Open

Support-itecz wants to merge 1 commit into
meta:mainfrom
Support-itecz:sptp-exporter-pprof

Conversation

@Support-itecz

Copy link
Copy Markdown

Summary

sptp-exporter blank-imports net/http/pprof, whose init registers /debug/pprof/* on http.DefaultServeMux. PrometheusExporter.Start registered /metrics on that same default mux and served it with http.ListenAndServe(":<exporterport>", nil), so the exporter port (6942 by default, all interfaces) answered every pprof endpoint even with -pprof left empty, which the flag help describes as disabled. Anyone who can reach that port can read /debug/pprof/cmdline, full goroutine dumps and heap profiles, and start CPU profiles or execution traces against the process without authentication. It is the same exposure as CVE-2019-11248 (kubelet serving pprof on its healthz port).

Start now builds its own ServeMux holding only /metrics, the same fix ntp/responder/stats already carries for ntpresponder. Profiling stays available through the explicit -pprof listener, which keeps using the default mux. ptpcheck's metrics server also uses the default mux, but that binary does not link net/http/pprof, so it is not affected and is left alone.

Test Plan

Added TestPrometheusExporterDoesNotServePprof, modeled on TestMonitoringPortDoesNotServePprof in ntp/responder/stats. It links net/http/pprof the way the binary does, runs Start against a stub sptp counters endpoint on [::1], waits for the scraped gauge on /metrics, then expects 404 from /debug/pprof/, /debug/pprof/cmdline and /debug/pprof/symbol.

Without the prom_exporter.go change:

$ go test -race -count=1 -run TestPrometheusExporterDoesNotServePprof ./ptp/sptp/stats/
    prom_exporter_test.go:74:
        	Error:      	Not equal:
        	            	expected: 404
        	            	actual  : 200
        	Messages:   	/debug/pprof/
--- FAIL: TestPrometheusExporterDoesNotServePprof (0.01s)
FAIL

With it (Linux, Go 1.26.10):

$ go test -race -count=1 ./ptp/sptp/... ./ntp/responder/stats/...
ok  	github.com/facebook/time/ptp/sptp/asymmetry	1.023s
ok  	github.com/facebook/time/ptp/sptp/bmc	1.011s
ok  	github.com/facebook/time/ptp/sptp/client	15.384s
ok  	github.com/facebook/time/ptp/sptp/client/measurement	1.011s
ok  	github.com/facebook/time/ptp/sptp/stats	1.034s
ok  	github.com/facebook/time/ntp/responder/stats	1.029s

Against the built binary with default flags (-pprof unset), -exporterport 48942 and a stub sptp on [::1]:48269:

before
/metrics                       -> HTTP 200
/debug/pprof/                  -> HTTP 200
/debug/pprof/cmdline           -> HTTP 200
/debug/pprof/goroutine?debug=1 -> HTTP 200
listening: *:48942

after
/metrics                       -> HTTP 200
/debug/pprof/                  -> HTTP 404
/debug/pprof/cmdline           -> HTTP 404
/debug/pprof/goroutine?debug=1 -> HTTP 404

With -pprof 127.0.0.1:48060 the profiler still answers on that address (200) and the exporter port still returns 404. go build ./..., golangci-lint run (v2.15.0) and gofmt -l are clean.

sptp-exporter links net/http/pprof, which registers /debug/pprof/* on
http.DefaultServeMux, and PrometheusExporter.Start served that mux on
:<exporterport>. The profiler was reachable on every interface even with
-pprof left empty. Serve /metrics from a dedicated mux, as
ntp/responder/stats already does for ntpresponder.
@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