Repository navigation
Conversation
monitorFlags&1<<msgType parses as (monitorFlags&1)<<msgType, since & and << have the same precedence in Go. Masks with bit 0 (NEWTABLE) therefore let every message through, and masks without it, such as MonitorObjectRules or MonitorActionDel, drop every message, including NFT_MSG_NEWGEN, which is what delivers the batch. Rules-only monitors never get an event, and a new-tables monitor also gets chains and rules. Test the bit for msgType, and never filter out NFT_MSG_NEWGEN, which is not in any mask but MonitorObjectAny with MonitorActionAny. Without that, Ruleset and MonitorActionNew monitors, which work today because their masks contain bit 0, would stop receiving events. Fixes google#374
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.
I started from #374 and checked it against the code. The precedence bug is as described there:
monitor.monitorFlags&1<<msgTypeis(monitorFlags&1)<<msgType. Fixing only the parentheses is not enough, though, because the same check also filtersNFT_MSG_NEWGEN, and that message is what hands the collected changes to the caller.NFT_MSG_NEWGENis only in theMonitorActionAny/MonitorObjectAnymask, so with the parentheses fixed alone, every filtered monitor would stop receiving events, including the Ruleset andMonitorActionNewones that work today.This PR tests the bit for
msgTypeand always letsNFT_MSG_NEWGENthrough.How I found it
After reading #374 I went through
monitor()to see what the filter feeds into. Since the change to deliver events per batch, nothing is sent untilNFT_MSG_NEWGENarrives, so whether a monitor sees anything depends on whether its mask lets that message through. Today that comes down to bit 0 (NFT_MSG_NEWTABLE):NewMonitor.NFT_MSG_NEWGENincluded, so nothing is delivered: Any/Chains, Any/Rules, Any/Sets, Any/Elements, New/Chains, New/Rules, New/Sets, and Del/Any.I then wrote a system test with three filters and ran it against
main, against the parentheses-only change, and against this change (results below).Where this can show up in practice
WithMonitorObject(MonitorObjectRules)orWithMonitorAction(MonitorActionDel): the monitor starts without error and never sends anything, so the program silently never reacts.MonitorActionNewandMonitorObjectTablesalso gets every chain, rule and set change, and has to filter by type itself. Code that assumesDatais a*Tablefails on the other events.This is my estimate; I have not seen a field report.
What changes
monitor.go: the filter testsmonitorFlags&(1<<msgType)and skips the check forNFT_MSG_NEWGEN.monitor_test.go:TestMonitorFilteradds a table, a chain and a rule in one batch and checks which changes arrive for a Rules monitor, a New/Tables monitor and a Ruleset monitor. The Ruleset case already passes onmain; it is there to catch the parentheses-only version.Two behaviour changes to be aware of:
Del*and object events, which they got only because of the bug. Unfiltered (Any/Any) and Any/Ruleset monitors behave as before.AddGenerationalMonitorcaller with a filter now gets aMonitorEventswith emptyChangesfor a batch that only touched other objects, the same way the generation event is reported for every batch.AddMonitorcallers don't see this, since it only forwardsChanges.Testing
Cross-compiled on macOS (
GOOS=linux GOARCH=arm64 go test -c) and ran in a privileged Ubuntu 24.04 container on a local Linux VM (arm64, kernel 6.8, nf_tables), with-run_system_tests:mainTestMonitorpasses on all three. With the patch, all package tests (.,alignedbuff,binaryutil,expr,userdata,xt) pass exceptTestTableOwnershipandTestSocketDrainingOnErrors, which fail the same way on unpatchedmainin that container ("operation not supported" from the kernel). Without-run_system_teststhe new test skips like the other system tests.GOOS=linux go vet ./...andgofmtare clean.I did not run the
integrationtests, because the container has nonftbinary; they don't use the monitor. I have not run this on x86_64.Fixes #374