-
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
Havoc register if truncating non-number #742
Conversation
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 19 minutes and 30 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 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 (
|
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: 14
🧹 Outside diff range comments (2)
src/test/test_yaml.cpp (1)
Line range hint
1-44
: Consider addressing the TODO and improving test organization.While the addition of the new test case is good, there are a few suggestions for improving the overall structure:
The TODO comment at the beginning of the file suggests moving this framework. Consider creating an issue to track this refactoring task if it hasn't been done already.
The test cases are currently listed individually. To improve maintainability, consider using a data-driven approach:
- Create a list or array of test case file names.
- Use a loop to generate the
YAML_CASE
for each test file.This approach would make it easier to add, remove, or reorder test cases in the future.
Example:
std::vector<std::string> test_files = { "test-data/add.yaml", "test-data/assign.yaml", // ... other test files ... "test-data/pointer.yaml", // ... remaining test files ... }; for (const auto& file : test_files) { YAML_CASE(file.c_str()) }
- Consider adding a brief comment explaining the purpose of each test file or grouping related tests together with comments. This would improve the readability and maintainability of the test suite.
src/crab/ebpf_domain.cpp (1)
Line range hint
2408-2418
: Refactor duplicated code for handling non-number types in 32-bit operationsThe code segments in lines 2408-2418 and 2500-2505 perform identical logic to reset the destination register when it's not of type
T_NUM
during a 32-bit operation. Refactoring this repeated logic into a helper function would reduce code duplication and enhance maintainability.Apply this diff to create a helper function and replace duplicated code:
+void ebpf_domain_t::reset_non_number_register(const Reg& reg) { + havoc_register(m_inv, reg); + havoc_offsets(reg); + havoc(reg_pack(reg).type); +} // In both instances, replace the duplicated code with: if (!type_inv.has_type(m_inv, bin.dst, T_NUM)) { - havoc_register(m_inv, bin.dst); - havoc_offsets(bin.dst); - havoc(dst.type); + reset_non_number_register(bin.dst); }Also applies to: 2500-2505
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (3)
- src/crab/ebpf_domain.cpp (1 hunks)
- src/test/test_yaml.cpp (1 hunks)
- test-data/pointer.yaml (1 hunks)
🧰 Additional context used
🔇 Additional comments (5)
src/test/test_yaml.cpp (1)
38-38
: LGTM: New test case added for pointer operations.The addition of
YAML_CASE("test-data/pointer.yaml")
is consistent with the existing code structure and follows the established pattern for defining YAML test cases. This new test case aligns well with the PR objectives, specifically addressing the need for testing 32-bit pointer truncation operations as mentioned in the linked issue #741.src/crab/ebpf_domain.cpp (4)
Line range hint
762-811
: Implementation of atomic operations handles edge cases correctlyThe
void ebpf_domain_t::operator()(const Atomic& a)
function correctly implements the handling of atomic operations, including special cases likeCMPXCHG
andfetch
operations. It ensures that the abstract domain accurately reflects the effects of atomic instructions on shared and stack memory.
Line range hint
2315-2332
: Efficient recomputation ofstack_numeric_size
when unknownThe
recompute_stack_numeric_size
method effectively recalculates thestack_numeric_size
when it's unknown (TOP
). This ensures that the analysis maintains accurate information about the numeric size of stack variables, which is crucial for preventing false positives in verification.
Line range hint
2334-2353
: Properly updates stack offsets and numeric sizes during additionThe
void ebpf_domain_t::add(const Reg& reg, const int imm, const int finite_width)
function correctly updates the stack offset andstack_numeric_size
when an immediate value is added to a register. It handles both positive and negative immediate values, ensuring that the abstract state remains sound.
Line range hint
762-811
: Verify that shared memory values are correctly handledThe comment in lines 804-805 mentions that
do_mem_store()
doesn't track shared memory values. Verify whether this could lead to any inconsistencies in the abstract domain, especially since atomic operations can modify shared memory. Ensuring that shared memory is accurately modeled is important for soundness.Run the following script to check for usages of
do_mem_store
with shared memory:
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: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (1)
- test-data/pointer.yaml (1 hunks)
🧰 Additional context used
🔇 Additional comments (11)
test-data/pointer.yaml (11)
4-24
: LGTM: Well-structured test case for additionThis test case effectively checks the behavior of 32-bit addition on a pointer. The use of a no-op addition (w1 += 0) is a clever way to trigger the 32-bit ALU operation without changing the value.
26-44
: LGTM: Consistent test case for subtractionThis test case maintains consistency with the addition test, using a no-op subtraction (w1 -= 0) to trigger the 32-bit ALU operation. The structure and expected messages are appropriate for the operation.
47-71
: LGTM: Comprehensive test case for multiplicationThis test case effectively checks the behavior of 32-bit multiplication on a pointer. The use of multiplication by 1 (w1 *= 1) is consistent with previous tests. The additional error message for r1.type == number is appropriate for the multiplication operation.
73-97
: LGTM: Consistent test case for divisionThis test case maintains consistency with previous tests, using division by 1 (w1 /= 1) to trigger the 32-bit ALU operation. The structure and expected messages are appropriate for the operation.
125-149
: LGTM: Comprehensive test case for signed divisionThis test case effectively checks the behavior of 32-bit signed division on a pointer. The use of signed division by 1 (w1 s/= 1) is consistent with previous tests and appropriate for testing signed operations.
177-201
: LGTM: Well-designed test case for bitwise ANDThis test case effectively checks the behavior of 32-bit bitwise AND on a pointer. The use of AND with -1 (w1 &= -1) is a clever way to trigger the 32-bit ALU operation without changing the value, as -1 has all bits set (0xFFFFFFFF).
203-227
: LGTM: Consistent test case for bitwise ORThis test case maintains consistency with previous tests, using bitwise OR with 0 (w1 |= 0) to trigger the 32-bit ALU operation without changing the value. The structure and expected messages are appropriate for the operation.
229-253
: LGTM: Well-structured test case for bitwise XORThis test case effectively checks the behavior of 32-bit bitwise XOR on a pointer. The use of XOR with 0 (w1 ^= 0) is consistent with previous tests and triggers the 32-bit ALU operation without changing the value.
255-279
: LGTM: Consistent test case for left shiftThis test case maintains consistency with previous tests, using left shift by 0 (w1 <<= 0) to trigger the 32-bit ALU operation without changing the value. The structure and expected messages are appropriate for the operation.
281-305
: LGTM: Well-structured test case for right shiftThis test case effectively checks the behavior of 32-bit right shift on a pointer. The use of right shift by 0 (w1 >>= 0) is consistent with previous tests and triggers the 32-bit ALU operation without changing the value.
307-331
: LGTM: Comprehensive test case for arithmetic right shiftThis test case effectively checks the behavior of 32-bit arithmetic right shift on a pointer. The use of arithmetic right shift by 0 (w1 s>>= 0) is consistent with previous tests and appropriate for testing signed operations.
e997117
to
9d0beda
Compare
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 (3)
- src/crab/ebpf_domain.cpp (1 hunks)
- src/test/test_yaml.cpp (1 hunks)
- test-data/pointer.yaml (1 hunks)
🧰 Additional context used
📓 Learnings (1)
test-data/pointer.yaml (2)
Learnt from: Alan-Jowett PR: vbpf/ebpf-verifier#742 File: test-data/pointer.yaml:99-123 Timestamp: 2024-10-21T16:48:10.036Z Learning: In BPF ISA, modulo by zero results in the original value.
Learnt from: Alan-Jowett PR: vbpf/ebpf-verifier#742 File: test-data/pointer.yaml:151-175 Timestamp: 2024-10-21T16:48:02.548Z Learning: In BPF ISA, modulo by zero results in the original value.
🪛 yamllint
test-data/pointer.yaml
[error] 356-356: no new line character at the end of file
(new-line-at-end-of-file)
🪛 GitHub Check: validate-yaml
test-data/pointer.yaml
[failure] 356-356:
356:84 [new-line-at-end-of-file] no new line character at the end of file
[failure] 356-356:
356:84 [new-line-at-end-of-file] no new line character at the end of file
🔇 Additional comments (8)
src/test/test_yaml.cpp (1)
38-38
: Excellent addition of the pointer.yaml test case!The inclusion of this test case aligns perfectly with the PR objectives to address issues related to 32-bit ALU operations on pointers. It will help ensure that the changes made to handle pointer truncation are properly tested, enhancing the overall robustness of the ebpf verifier.
test-data/pointer.yaml (6)
3-23
: LGTM: Well-structured test case for additionThe test case for 32-bit pointer truncation with addition is well-structured and correctly implements the intended operation. The pre-conditions, code, and expected messages are appropriate and consistent with the test objectives.
25-44
: LGTM: Consistent test case for subtractionThe test case for 32-bit pointer truncation with subtraction maintains consistency with the previous test case. It correctly implements the intended operation and includes appropriate pre-conditions and expected messages.
46-278
: LGTM: Comprehensive set of test cases for various operationsThe test cases for multiplication, division, modulo, signed division, signed modulo, AND, OR, XOR, and LSH operations are well-structured and consistent. Each case appropriately tests 32-bit pointer truncation for its respective operation. The use of modulo by zero is correct as per the BPF ISA definition.
280-305
: LGTM: Consistent test case for right shift operationThe test case for 32-bit pointer truncation with right shift (RSH) maintains consistency with the previous test cases. It correctly implements the intended operation and includes appropriate pre-conditions and expected messages.
332-356
: LGTM: Well-implemented test case for NOT operation with appropriate variationsThe test case for 32-bit pointer truncation with the NOT operation is well-implemented. It correctly applies the operation twice to maintain the original value. The slight differences in post-conditions and expected messages are appropriate for this specific operation, showing attention to detail in the test design.
🧰 Tools
🪛 yamllint
[error] 356-356: no new line character at the end of file
(new-line-at-end-of-file)
🪛 GitHub Check: validate-yaml
[failure] 356-356:
356:84 [new-line-at-end-of-file] no new line character at the end of file
[failure] 356-356:
356:84 [new-line-at-end-of-file] no new line character at the end of file
1-356
: Excellent comprehensive test suite for 32-bit pointer truncation operationsThis YAML file provides a well-structured and consistent set of test cases that effectively address the PR objectives. The test suite covers a wide range of arithmetic and bitwise operations, ensuring thorough testing of 32-bit pointer truncation scenarios. The consistency in test case structure enhances readability and maintainability.
Key strengths:
- Comprehensive coverage of various 32-bit operations
- Consistent structure across all test cases
- Appropriate use of pre-conditions, code, and expected messages
- Clever use of operations that trigger 32-bit ALU without changing values
The only minor improvement needed is adding a newline at the end of the file to satisfy coding standards.
Overall, this test suite significantly enhances the project's ability to validate pointer handling in 32-bit operations.
🧰 Tools
🪛 yamllint
[error] 356-356: no new line character at the end of file
(new-line-at-end-of-file)
🪛 GitHub Check: validate-yaml
[failure] 356-356:
356:84 [new-line-at-end-of-file] no new line character at the end of file
[failure] 356-356:
356:84 [new-line-at-end-of-file] no new line character at the end of filesrc/crab/ebpf_domain.cpp (1)
2500-2505
: Proper handling of non-number destination registers in 32-bit operationsThe added code correctly checks if the destination register is not of type
T_NUM
during a 32-bit operation. If so, it properly invalidates the destination register by callinghavoc_register
,havoc_offsets
, andhavoc
ondst.type
. This ensures that any incorrect assumptions about the register's state are removed, maintaining the integrity of the analysis.
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
🧹 Outside diff range comments (1)
src/test/test_yaml.cpp (1)
Line range hint
1-42
: Consider improving file organization for better maintainability.While the current structure is functional and the new test case is correctly placed, consider the following suggestions to enhance maintainability:
- Group related test cases together (e.g., arithmetic operations, bitwise operations, etc.).
- Add comments to describe the purpose of each group of tests.
- Consider using a data-driven approach to generate test cases, which could make it easier to add new tests in the future.
These changes could make the file more readable and easier to maintain as the test suite grows.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (3)
- src/crab/ebpf_domain.cpp (1 hunks)
- src/test/test_yaml.cpp (1 hunks)
- test-data/pointer.yaml (1 hunks)
🧰 Additional context used
📓 Learnings (1)
test-data/pointer.yaml (2)
Learnt from: Alan-Jowett PR: vbpf/ebpf-verifier#742 File: test-data/pointer.yaml:99-123 Timestamp: 2024-10-21T16:48:10.036Z Learning: In BPF ISA, modulo by zero results in the original value.
Learnt from: Alan-Jowett PR: vbpf/ebpf-verifier#742 File: test-data/pointer.yaml:151-175 Timestamp: 2024-10-21T16:48:02.548Z Learning: In BPF ISA, modulo by zero results in the original value.
🔇 Additional comments (23)
src/test/test_yaml.cpp (1)
38-38
: LGTM: New test case added for pointer operations.The addition of
YAML_CASE("test-data/pointer.yaml")
expands the test suite to include scenarios for 32-bit pointer truncation operations. This aligns well with the PR objectives to address issue #741.To ensure the new test case adequately covers the issue, let's examine its contents:
✅ Verification successful
Verified: The new test cases in
test-data/pointer.yaml
comprehensively cover the 32-bit pointer truncation scenarios as intended for issue #741.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the contents of the new pointer.yaml test file # Test: Check if the file exists and contains relevant test cases cat test-data/pointer.yamlLength of output: 8030
test-data/pointer.yaml (12)
3-23
: LGTM: Well-structured test case for additionThe test case for 32-bit pointer truncation with addition is well-structured and aligns with the PR objectives. The use of a no-op addition (w1 += 0) effectively triggers the 32-bit ALU operation without changing the value, which is ideal for testing pointer truncation behavior.
46-70
: LGTM: Comprehensive test case for multiplicationThe test case for 32-bit pointer truncation with multiplication is well-structured and comprehensive. It includes complete pre-conditions, appropriate post-conditions, and correct expected messages. The use of multiplication by 1 (w1 *= 1) effectively triggers the 32-bit ALU operation without changing the value.
72-96
: LGTM: Consistent test case for divisionThe test case for 32-bit pointer truncation with division is well-structured and consistent with the multiplication test case. It includes appropriate pre-conditions, post-conditions, and expected messages. The use of division by 1 (w1 /= 1) effectively triggers the 32-bit ALU operation without changing the value.
98-122
: LGTM: Correct test case for modulo operationThe test case for 32-bit pointer truncation with modulo is well-structured and consistent with previous test cases. It includes appropriate pre-conditions, post-conditions, and expected messages.
Note: The use of modulo by 0 (w1 %= 0) is correct in this context. In BPF ISA, modulo by zero results in the original value, which effectively triggers the 32-bit ALU operation without changing the value.
124-148
: LGTM: Consistent test case for signed divisionThe test case for 32-bit pointer truncation with signed division is well-structured and consistent with previous test cases. It includes appropriate pre-conditions, post-conditions, and expected messages. The use of signed division by 1 (w1 s/= 1) effectively triggers the 32-bit ALU operation without changing the value.
150-174
: LGTM: Correct test case for signed modulo operationThe test case for 32-bit pointer truncation with signed modulo is well-structured and consistent with previous test cases. It includes appropriate pre-conditions, post-conditions, and expected messages.
Note: The use of signed modulo by 0 (w1 s%= 0) is correct in this context. In BPF ISA, modulo by zero results in the original value, which effectively triggers the 32-bit ALU operation without changing the value.
176-200
: LGTM: Well-crafted test case for bitwise ANDThe test case for 32-bit pointer truncation with bitwise AND is well-structured and consistent with previous test cases. It includes appropriate pre-conditions, post-conditions, and expected messages. The use of AND with -1 (w1 &= -1) effectively triggers the 32-bit ALU operation without changing the value, as -1 in two's complement is all 1's.
202-226
: LGTM: Well-designed test case for bitwise ORThe test case for 32-bit pointer truncation with bitwise OR is well-structured and consistent with previous test cases. It includes appropriate pre-conditions, post-conditions, and expected messages. The use of OR with 0 (w1 |= 0) effectively triggers the 32-bit ALU operation without changing the value.
228-252
: LGTM: Solid test case for bitwise XORThe test case for 32-bit pointer truncation with bitwise XOR is well-structured and consistent with previous test cases. It includes appropriate pre-conditions, post-conditions, and expected messages. The use of XOR with 0 (w1 ^= 0) effectively triggers the 32-bit ALU operation without changing the value.
254-278
: LGTM: Effective test case for left shift operationThe test case for 32-bit pointer truncation with left shift (LSH) is well-structured and consistent with previous test cases. It includes appropriate pre-conditions, post-conditions, and expected messages. The use of left shift by 0 (w1 <<= 0) effectively triggers the 32-bit ALU operation without changing the value.
280-304
: LGTM: Proper test case for right shift operationThe test case for 32-bit pointer truncation with right shift (RSH) is well-structured and consistent with previous test cases. It includes appropriate pre-conditions, post-conditions, and expected messages. The use of right shift by 0 (w1 >>= 0) effectively triggers the 32-bit ALU operation without changing the value.
306-330
: LGTM: Appropriate test case for arithmetic right shift operationThe test case for 32-bit pointer truncation with arithmetic right shift (ARSH) is well-structured and consistent with previous test cases. It includes appropriate pre-conditions, post-conditions, and expected messages. The use of arithmetic right shift by 0 (w1 s>>= 0) effectively triggers the 32-bit ALU operation without changing the value.
src/crab/ebpf_domain.cpp (10)
Line range hint
967-971
: Addition with overflow handling is correctly implementedThe
add_overflow
method appropriately handles addition with potential overflow for both signed and unsigned values by utilizing theapply_signed
function.
Line range hint
972-976
: Subtraction with overflow handling is correctly implementedThe
sub_overflow
method correctly manages subtraction with potential overflow, ensuring robustness for both signed and unsigned values using theapply_signed
function.
2500-2505
: Correctly invalidating registers for 32-bit operations on non-number typesThe code properly invalidates the destination register when performing 32-bit operations on non-number types. This is crucial to prevent incorrect assumptions about the register state and ensures type safety.
Line range hint
1949-1974
: Shift left operation handles edge cases accuratelyThe
shl
function correctly masks the shift amount as per the BPF ISA requirements and handles potential overflows. It accounts for different cases where the bits shifted out may or may not be identical, ensuring accurate interval computations.
Line range hint
2046-2077
: Arithmetic shift right operation is correctly implementedThe
ashr
function accurately implements arithmetic right shift, properly handling both 64-bit and 32-bit cases. It ensures that the sign is correctly extended and that intervals are appropriately updated.
Line range hint
2271-2282
: Valid pointer assignment method ensures pointers are within valid rangeThe
assign_valid_ptr
function correctly sets up the pointer registers, ensuring that they are within valid bounds and properly handling the possibility of null pointers when applicable.
Line range hint
1608-1617
: Verification of map file descriptor range is robustThe
get_map_fd_range
function effectively retrieves the range of map file descriptors and caps the maximum range to prevent excessive iterations, which enhances performance and avoids potential issues with large ranges.
Line range hint
1940-1947
: Shift left immediate operation masks shift amount correctlyThe
shl
function properly masks the immediate value withfinite_width - 1
as required by the BPF ISA, ensuring that the shift amount is within valid bounds and preventing undefined behavior.
Line range hint
2009-2044
: Sign extension operations handle different bit widths appropriatelyThe
sign_extend
function supports different bit widths (8, 16, 32) and accurately performs sign extension, updating the interval for the destination register and handling potential overflows when a finite width is specified.
Line range hint
1831-1866
: Overflow handling in arithmetic operations maintains interval accuracyThe
overflow_signed
andoverflow_unsigned
functions effectively manage intervals when potential overflows occur in arithmetic operations, ensuring that variable bounds are adjusted correctly to maintain soundness in analysis.
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: 5
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (3)
- src/crab/ebpf_domain.cpp (1 hunks)
- src/test/test_yaml.cpp (1 hunks)
- test-data/pointer.yaml (1 hunks)
🧰 Additional context used
📓 Learnings (1)
test-data/pointer.yaml (2)
Learnt from: Alan-Jowett PR: vbpf/ebpf-verifier#742 File: test-data/pointer.yaml:99-123 Timestamp: 2024-10-21T16:48:10.036Z Learning: In BPF ISA, modulo by zero results in the original value.
Learnt from: Alan-Jowett PR: vbpf/ebpf-verifier#742 File: test-data/pointer.yaml:151-175 Timestamp: 2024-10-21T16:48:02.548Z Learning: In BPF ISA, modulo by zero results in the original value.
🔇 Additional comments (13)
src/test/test_yaml.cpp (1)
38-38
: New test case added for pointer operations.The addition of the "test-data/pointer.yaml" test case is a positive change that aligns with the PR objectives. It will help ensure the correct handling of 32-bit operations on pointers, as mentioned in the linked issue #741.
Consider the following points:
- The placement of the new test case seems arbitrary. Consider organizing the test cases alphabetically or by functionality for better maintainability.
- Ensure that this additional test case doesn't significantly impact the overall test suite execution time.
- Verify that the test cases in "pointer.yaml" cover all the scenarios mentioned in the PR objectives, particularly the various 32-bit ALU operations on pointers.
To verify the contents of the new test file, run the following script:
✅ Verification successful
Verification of new test cases in
test-data/pointer.yaml
completed.The added test cases comprehensively cover various 32-bit ALU operations on pointers, aligning well with the PR objectives and enhancing test coverage without adversely affecting test suite performance.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the contents of the new test file # Test: Check if the file exists and display its contents if [ -f "test-data/pointer.yaml" ]; then echo "Contents of test-data/pointer.yaml:" cat "test-data/pointer.yaml" else echo "Error: test-data/pointer.yaml not found" fiLength of output: 8169
test-data/pointer.yaml (11)
47-71
: LGTM: Well-structured test case for multiplicationThis test case for multiplication is well-structured and consistent with the expected format. It effectively tests the 32-bit pointer truncation scenario using a no-op multiplication (w1 *= 1). The pre-conditions, post-conditions, and expected messages are all appropriate and comprehensive.
73-97
: LGTM: Well-structured test case for divisionThis test case for division is well-structured and consistent with the expected format. It effectively tests the 32-bit pointer truncation scenario using a no-op division (w1 /= 1). The pre-conditions, post-conditions, and expected messages are all appropriate and comprehensive.
99-123
: LGTM: Well-structured test case for modulo operationThis test case for the modulo operation is well-structured and consistent with the expected format. It effectively tests the 32-bit pointer truncation scenario using modulo by 0 (w1 %= 0). The use of modulo by 0 is intentional, as in BPF ISA, this operation results in the original value. The pre-conditions, post-conditions, and expected messages are all appropriate and comprehensive.
125-149
: LGTM: Well-structured test case for signed divisionThis test case for signed division is well-structured and consistent with the expected format. It effectively tests the 32-bit pointer truncation scenario using a no-op signed division (w1 s/= 1). The pre-conditions, post-conditions, and expected messages are all appropriate and comprehensive.
151-175
: LGTM: Well-structured test case for signed modulo operationThis test case for the signed modulo operation is well-structured and consistent with the expected format. It effectively tests the 32-bit pointer truncation scenario using signed modulo by 0 (w1 s%= 0). The use of modulo by 0 is intentional, as in BPF ISA, this operation results in the original value. The pre-conditions, post-conditions, and expected messages are all appropriate and comprehensive.
177-201
: LGTM: Well-structured test case for AND operationThis test case for the AND operation is well-structured and consistent with the expected format. It effectively tests the 32-bit pointer truncation scenario using AND with -1 (w1 &= -1), which is equivalent to all bits set. The pre-conditions, post-conditions, and expected messages are all appropriate and comprehensive.
203-227
: LGTM: Well-structured test case for OR operationThis test case for the OR operation is well-structured and consistent with the expected format. It effectively tests the 32-bit pointer truncation scenario using OR with 0 (w1 |= 0), which is a no-op operation. The pre-conditions, post-conditions, and expected messages are all appropriate and comprehensive.
229-253
: LGTM: Well-structured test case for XOR operationThis test case for the XOR operation is well-structured and consistent with the expected format. It effectively tests the 32-bit pointer truncation scenario using XOR with 0 (w1 ^= 0), which is a no-op operation. The pre-conditions, post-conditions, and expected messages are all appropriate and comprehensive.
255-279
: LGTM: Well-structured test case for LSH (Left Shift) operationThis test case for the LSH operation is well-structured and consistent with the expected format. It effectively tests the 32-bit pointer truncation scenario using left shift by 0 (w1 <<= 0), which is a no-op operation. The pre-conditions, post-conditions, and expected messages are all appropriate and comprehensive.
281-305
: LGTM: Well-structured test case for RSH (Right Shift) operationThis test case for the RSH operation is well-structured and consistent with the expected format. It effectively tests the 32-bit pointer truncation scenario using right shift by 0 (w1 >>= 0), which is a no-op operation. The pre-conditions, post-conditions, and expected messages are all appropriate and comprehensive.
307-331
: LGTM: Well-structured test case for ARSH (Arithmetic Right Shift) operationThis test case for the ARSH operation is well-structured and consistent with the expected format. It effectively tests the 32-bit pointer truncation scenario using arithmetic right shift by 0 (w1 s>>= 0), which is a no-op operation. The pre-conditions, post-conditions, and expected messages are all appropriate and comprehensive.
src/crab/ebpf_domain.cpp (1)
2500-2505
: Correct handling of non-number destinations in 32-bit operationsThe added code correctly resets the state of the destination register when performing a 32-bit operation on a non-number type. This ensures that pointers are not incorrectly manipulated in 32-bit contexts.
Signed-off-by: Alan Jowett <[email protected]>
Resolves: #741
This pull request includes changes to the
ebpf_domain.cpp
file to handle 32-bit operations more robustly and adds new test cases for 32-bit pointer truncation operations in thetest-data/pointer.yaml
file. The most important changes include updating theoperator()
function to handle non-numeric destination registers and adding multiple test cases for various 32-bit pointer truncation operations.Code Updates:
src/crab/ebpf_domain.cpp
:operator()
function to handle cases where the destination register is not a number by invokinghavoc_register
,havoc_offsets
, andhavoc
on the destination type. ([src/crab/ebpf_domain.cppR2500-R2505](https://github.com/vbpf/ebpf-verifier/pull/742/files#diff-4260cca82870d77e078c224955ebce890cb127bdd92fd63a2d57e1374dedd9f2R2500-R2505)
)Test Additions:
src/test/test_yaml.cpp
:test-data/pointer.yaml
. ([src/test/test_yaml.cppR38](https://github.com/vbpf/ebpf-verifier/pull/742/files#diff-d6599eb5fe454ccafc39fb6c17342381a11a931e4cb63345edcdfc7518e87412R38)
)test-data/pointer.yaml
:[test-data/pointer.yamlR1-R290](https://github.com/vbpf/ebpf-verifier/pull/742/files#diff-17ff005c150bc4fab316506419b7ef68084ae2c8462795ec40c12786fae4152cR1-R290)
)Summary by CodeRabbit
New Features
Bug Fixes