fix(core): guard WatchConfigChanges endpoint iteration with EndPointsLock#2760
Open
rootp1 wants to merge 1 commit into
Open
fix(core): guard WatchConfigChanges endpoint iteration with EndPointsLock#2760rootp1 wants to merge 1 commit into
rootp1 wants to merge 1 commit into
Conversation
…Lock Take a read lock while snapshotting dm.EndPoints before iterating in the config-reload callback, matching the locking convention used everywhere else dm.EndPoints is accessed (e.g. kubeUpdate.go). Fixes a data race between config reload and concurrent endpoint mutations from container handlers. Fixes kubearmor#2759 Signed-off-by: rootp1 <arnav.iitr@gmail.com>
rootp1
requested review from
Aryan-sharma11,
AryanBakliwal and
achrefbensaad
as code owners
July 10, 2026 16:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WatchConfigChanges()inKubeArmor/core/unorchestratedUpdates.goiterateddm.EndPointsdirectly on config reload without holdingdm.EndPointsLock, unlike every other access to that slice in the daemon (e.g.kubeUpdate.go).Linked Issue
Fixes #2759
What Changed
dm.EndPointsLock.RLock()to copydm.EndPointsinto a local snapshot, release the lock, then iterate the snapshot to perform per-endpoint posture/visibility updates.KubeArmor/core/unorchestratedUpdates_race_test.go, a targeted-racetest that runs the fixed snapshot-and-iterate pattern concurrently against goroutines mutatingdm.EndPointsunder the same lock.Verification
gofmt -lon changed files — passed (no output)GOOS=linux GOARCH=amd64 go build ./core/...— passedGOOS=linux GOARCH=amd64 go vet ./core/...— passedgo test ./core/... -run TestConfigReloadEndpointIterationRaceCondition -race— not run: this repo'scorepackage (viaKubeArmor/commonandKubeArmor/utils/bpflsmprobe) only compiles on Linux (uses Linux-onlygolang.org/x/sys/unixAPIs), and no Linux toolchain/Docker was available in this environment; verified via Linux cross-compilation (build+vet above) insteadmake gofmt/go-lint(Revive) /go-sec/go-vuln/go test ./...(repo CI,ci-test-go.yml) — not run locally: these require a Linux runner and/or tools (Revive, Gosec, govulncheck) not installed in this environment; will run in upstream CI on this PRScope
KubeArmor/core/unorchestratedUpdates.goand the new test file were changed; no unrelated files were touched.