kvm: fix security group conntrack NOTRACK optimization triggered by single-direction allow-all rule - #14100
Conversation
…ingle-direction allow-all rule The raw-table NOTRACK rules for a VM IP in the cs_notrack/cs_notrack6 ipsets apply to that IP as both source and destination, disabling connection tracking for it in both directions at once. The check that populates these ipsets did not look at rule['ruletype'], so an allow-all rule in only one direction (e.g. egress all to 0.0.0.0/0) was enough to disable conntrack for the VM, breaking return traffic when the other direction (e.g. ingress) is restricted. Only skip conntrack for a family now when both an ingress allow-all and an egress allow-all rule exist for that family, matching the actual bidirectional effect of the NOTRACK rules.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14100 +/- ##
=========================================
Coverage 19.79% 19.80%
- Complexity 20020 20022 +2
=========================================
Files 6371 6371
Lines 575954 575954
Branches 70521 70521
=========================================
+ Hits 114034 114043 +9
+ Misses 449486 449472 -14
- Partials 12434 12439 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
verified the following cases
|
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Fixes a security group conntrack optimization bug where a single-direction allow-all rule could incorrectly disable conntrack for both traffic directions on a VM IP.
Changes:
- Track ingress/egress “allow-all” rules separately per IP family (IPv4/IPv6).
- Only disable conntrack (NOTRACK ipset membership) when both ingress and egress are allow-all for a given family.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| ingress4_allow_all = False | ||
| egress4_allow_all = False | ||
| ingress6_allow_all = False | ||
| egress6_allow_all = False |
| if '0.0.0.0/0' in rule['ipv4']: | ||
| if rule['ruletype'] == 'E': | ||
| egress4_allow_all = True | ||
| else: | ||
| ingress4_allow_all = True | ||
| if '::/0' in rule['ipv6']: | ||
| if rule['ruletype'] == 'E': | ||
| egress6_allow_all = True | ||
| else: |
Description
This PR fixes #14099
The raw-table NOTRACK rules for a VM IP in the cs_notrack/cs_notrack6 ipsets apply to that IP as both source and destination, disabling connection tracking for it in both directions at once. The check that populates these ipsets did not look at rule['ruletype'], so an allow-all rule in only one direction (e.g. egress all to 0.0.0.0/0) was enough to disable conntrack for the VM, breaking return traffic when the other direction (e.g. ingress) is restricted.
Only skip conntrack for a family now when both an ingress allow-all and an egress allow-all rule exist for that family, matching the actual bidirectional effect of the NOTRACK rules.
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
How did you try to break this feature and the system with this change?