Repository navigation
fix(agent): prevent shift overflow in clone_by_masklen for IPv6 - #11948
Open
YanLongDai wants to merge 1 commit into
Open
YanLongDai wants to merge 1 commit into
YanLongDai wants to merge 1 commit into
Conversation
- Add boundary check in clone_by_masklen() to prevent shift overflow - When masklen=0 and is_ipv4=false, shift amount equals 128, causing panic - Fix: check if shift >= max_prefix, return 0 mask instead of shifting Fixes: Agent crash with signal 6 (SIGABRT) at policy/labeler.rs:73 Signed-off-by: Dai Yanlong <daiyanlong@kylinos.cn>
This branch has not been deployed
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.
This PR is for:
Fixes shift overflow panic in clone_by_masklen for IPv6 addresses
Steps to reproduce the bug
systemctl start deepflow-agentThe issue occurs when the agent processes IPv6 addresses with
masklen=0in the policy labeler. The code attempts to shiftu128::MAXby 128 bits, which causes a shift overflow panic in Rust debug builds.Stack trace (native agent v7.2.2):
Agent log error:
Test environment:
Verification:
Conclusion: This is a bug in the native DeepFlow code, verified on community version v7.2.2.
Root Cause
In
agent/src/policy/labeler.rs:73, theclone_by_masklenfunction performs a left shift operation:When processing IPv6 addresses (
is_ipv4=false),max_prefixis set toIPV6_BITS(128). Ifmasklen=0, the shift amount becomes128 - 0 = 128. In Rust debug builds, shifting au128value by 128 bits causes a panic because the shift amount must be less than the bit width.Changes to fix the bug
Location: EpcNetIpKey::clone_by_masklen() - Line 70-77
Before:
After:
Explanation:
shift >= max_prefix(which would cause overflow)0as the mask (all bits zeroed)Affected branches
Checklist
Note: The eBPF verification items are not applicable for this fix as it only modifies policy labeler logic, not eBPF programs.
Signed-off-by: Dai Yanlong daiyanlong@kylinos.cn
cc @lzf575 @rvql Please review this fix. Thanks!