Repository navigation
lib: allocate matchers and set elements with calloc() - #612
Merged
Merged
Conversation
qdeslandes
force-pushed
the
ipv6-net-zero-padding
branch
from
October 23, 2026 18:24
f15f55e to
6c17977
Compare
Contributor
Author
|
@claude review |
Claude review of PR #612 (6c17977)The fix looks correct for newly parsed elements. Reviewers checked every Suggestions
Nits
|
prashantpcm94
force-pushed
the
ipv6-net-zero-padding
branch
from
October 26, 2026 16:26
6c17977 to
8dd298f
Compare
qdeslandes
requested changes
Oct 28, 2026
qdeslandes
left a comment
Contributor
There was a problem hiding this comment.
I would calloc the matchers instead, so we apply this across the board.
prashantpcm94
force-pushed
the
ipv6-net-zero-padding
branch
from
October 28, 2026 17:15
8dd298f to
ab2cd93
Compare
Contributor
Author
|
Fixed in latest rev |
Matcher payloads and set elements are parsed into buffers allocated with malloc(), and nothing guarantees a parser writes every byte. _bf_parse_ipv6_net() leaves the 4 bytes of padding at the end of struct bf_ip6_lpm_key unset, so an ip6.snet or ip6.dnet element parsed from text keeps whatever was in that memory. Set elements are compared byte for byte, so "chain update-set --remove" of such a prefix doesn't find it and still returns success, the prefix keeps matching, and the same prefix can be stored several times in one set. Allocate matchers and set elements with calloc(), so the bytes a parser doesn't write are zero.
qdeslandes
force-pushed
the
ipv6-net-zero-padding
branch
from
October 29, 2026 15:14
ab2cd93 to
fb97a0f
Compare
qdeslandes
enabled auto-merge (rebase)
October 29, 2026 15:14
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
bfcli chain update-set --removeof an IPv6 prefix returns success but doesn't remove it:The prefix keeps matching, and
{ 2001:db8::/64; 2001:db8::/64 }is stored as 2 elements. Matcher payloads and set elements are parsed into buffers allocated withmalloc(), and_bf_parse_ipv6_net()leaves the 4 bytes of padding at the end ofstruct bf_ip6_lpm_keyunset. Sets compare elements byte for byte, so each parsedip6.snet/ip6.dnetelement carries whatever was in that memory, and the element to remove usually doesn't equal the stored one. This allocates matchers and set elements withcalloc(), so the bytes a parser doesn't write are zero.Related issue
None.
Testing
CMake release build (
-DNO_DOCS=1) on CentOS Stream 9, kernel 6.16.1, gcc 11.5, clang 22.1.3, libbpf 1.6.3, thenmake -C $BUILD test_binandctest(withoutfuzzing.parser.infinite, which runs until stopped):check.iwyudidn't run becauseiwyu_tool.pyisn't installed here (it only checkscgen/program.c). Thecheck.astgreptests aren't registered becauseast-grepisn't installed either.No test is added: whether the bug shows depends on what
malloc()returns, so a test could pass without the fix.Checked by hand with release builds, the chain above on
BF_HOOK_TC_INGRESS, packets run withbpftool prog run, 3 runs each:--remove 2001:db8::/64returns 0,chain getstill lists both prefixes, and a packet from 2001:db8::1 is still dropped. The duplicate literal keeps 3 copies.2001:db9::/64is left, the 2001:db8::1 packet passes, the 2001:db9::1 packet is still dropped, and the duplicate literal keeps 1 copy.Notes for the reviewer
bf_set_pack()writes element bytes as they are), so removing their IPv6 networks keeps missing until the chain is set again. No release is affected: main can't restore chains with sets pinned by any build before 5239340 (v0.7.0 included), so only chains pinned by main builds between 5239340 and this fix are concerned.prefixlenbits and the generated program never reads the padding, so this doesn't change how an element matches. It changes which elements userspace sees as equal: what--removefinds, and duplicates.AI disclosure
Claude Code found the issue, drafted the change, the commit message and this description under my direction, and ran the tests listed under Testing. I reviewed the change and the results.
Checklist
make -C $BUILD test_bin testpasses (check.iwyuandcheck.astgrepnot run, see Testing) and the code follows the style guidecomponent: subcomponent: short description