-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix overflow in conversion from uvalue to svalue #769
Conversation
Signed-off-by: Alan Jowett <[email protected]>
Warning Rate limit exceeded@Alan-Jowett has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 23 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe changes in this pull request primarily enhance the Changes
Assessment against linked issues
Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Signed-off-by: Alan Jowett <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (2)
src/crab/ebpf_domain.cpp
(1 hunks)test-data/shift.yaml
(1 hunks)
🧰 Additional context used
📓 Learnings (1)
src/crab/ebpf_domain.cpp (1)
Learnt from: elazarg
PR: vbpf/ebpf-verifier#709
File: src/crab/ebpf_domain.cpp:2498-2498
Timestamp: 2024-09-30T22:42:59.728Z
Learning: When casting from larger integer types to smaller signed integer types, prefer using `gsl::narrow` over `static_cast`.
🔇 Additional comments (2)
test-data/shift.yaml (1)
1109-1139
: Test case effectively validates unsigned right shift by 0.
The test case is well-structured and thoroughly validates that an unsigned right shift by 0 preserves the original value, which is crucial for the PR's objective of handling value conversions correctly. It uses a carefully chosen test value that has different signed and unsigned representations, making it effective for testing potential overflow scenarios.
src/crab/ebpf_domain.cpp (1)
2377-2378
: Properly handling conversion from uvalue
to svalue
to prevent overflow
The added condition ensures that both ub_n
and lb_n
fit into int64_t
and that ub_n.narrow<int64_t>()
is greater than or equal to lb_n.narrow<int64_t>()
before assigning dst.svalue
to dst.uvalue
. This validation prevents potential overflow issues when converting unsigned values to signed values and ensures the correctness of the interval assignment.
Signed-off-by: Alan Jowett <[email protected]>
…shift match Signed-off-by: Alan Jowett <[email protected]>
Signed-off-by: Alan Jowett <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (2)
src/crab/ebpf_domain.cpp
(1 hunks)test-data/shift.yaml
(1 hunks)
🧰 Additional context used
📓 Learnings (1)
src/crab/ebpf_domain.cpp (1)
Learnt from: elazarg
PR: vbpf/ebpf-verifier#709
File: src/crab/ebpf_domain.cpp:2498-2498
Timestamp: 2024-09-30T22:42:59.728Z
Learning: When casting from larger integer types to smaller signed integer types, prefer using `gsl::narrow` over `static_cast`.
🔇 Additional comments (4)
test-data/shift.yaml (3)
1109-1145
: LGTM! Well-structured test case for edge value.
The test case effectively verifies the idempotent property of right shift by 0 using the maximum negative signed 64-bit value (0x8000000000000000), which is a crucial edge case for testing overflow scenarios.
1146-1183
: LGTM! Complementary test case for valid boundary value.
The test case provides good coverage by testing the maximum positive signed 64-bit value (0x7fffffffffffffff), complementing the previous test case to ensure both boundaries of the signed range are verified.
1107-1270
: Excellent test coverage for unsigned right shift by 0!
The new test cases provide comprehensive coverage of the overflow scenarios:
- Tests both maximum positive and negative 64-bit values
- Verifies behavior with both immediate and register-based shifting
- Maintains consistent verification of both svalue and uvalue preservation
- Includes clear documentation of the test values and their significance
This thoroughly addresses the overflow issue described in the PR and the scenarios from issue #766.
src/crab/ebpf_domain.cpp (1)
2377-2379
: Verify the assignment of dst.svalue
after logical shift right operation
Assigning dst.svalue
to dst.uvalue
following the logical shift right may result in unexpected negative values if dst.uvalue
exceeds the signed integer range. Please ensure that this assignment is intentional and that the subsequent overflow handling with overflow_signed
and overflow_unsigned
functions correctly manage any potential overflows or sign issues.
Signed-off-by: Alan Jowett <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (2)
src/crab/ebpf_domain.cpp
(3 hunks)test-data/shift.yaml
(1 hunks)
🧰 Additional context used
📓 Learnings (1)
src/crab/ebpf_domain.cpp (1)
Learnt from: elazarg
PR: vbpf/ebpf-verifier#709
File: src/crab/ebpf_domain.cpp:2498-2498
Timestamp: 2024-09-30T22:42:59.728Z
Learning: When casting from larger integer types to smaller signed integer types, prefer using `gsl::narrow` over `static_cast`.
🔇 Additional comments (6)
test-data/shift.yaml (4)
1109-1264
: LGTM! Well-structured test cases for unsigned right shift.
The test cases thoroughly verify the idempotent behavior of unsigned right shift by 0 using both MIN_INT64 and MAX_INT64 values, with both immediate and register-based variants.
1269-1427
: LGTM! Comprehensive test cases for signed right shift.
The test cases effectively verify the idempotent behavior of signed right shift by 0 using both MIN_INT64 and MAX_INT64 values, with both immediate and register-based variants.
1429-1586
: LGTM! Well-structured test cases for left shift.
The test cases thoroughly verify the idempotent behavior of left shift by 0 using both MIN_INT64 and MAX_INT64 values, with both immediate and register-based variants.
1108-1586
: LGTM! Excellent test coverage for shift operations.
The added test cases provide comprehensive coverage for shift operations by:
- Testing both signed and unsigned shifts
- Verifying behavior with edge cases (MIN_INT64 and MAX_INT64)
- Including both immediate and register-based variants
- Ensuring proper handling of uvalue/svalue conversions
This aligns well with the PR objective of fixing overflow in conversion from uvalue to svalue.
src/crab/ebpf_domain.cpp (2)
2337-2339
: Shift left operation correctly assigns and handles overflow
The assignment of dst.svalue
from dst.uvalue
and the subsequent overflow checks in the shl
function are appropriate.
2375-2377
: Logical shift right operation correctly assigns and handles overflow
The assignment of dst.svalue
from dst.uvalue
and the overflow handling in the lshr
function are implemented correctly.
Signed-off-by: Alan Jowett <[email protected]>
Signed-off-by: Alan Jowett <[email protected]>
Signed-off-by: Alan Jowett <[email protected]>
Resolves: #732
Resolves: #766
Resolves: #767
Resolves: #768
Invoke the overflow_* APIs to handle cases where the value would have overflowed.
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Tests