Skip to content
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

Add tests for issue 785 #786

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions test-data/loop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,61 @@ messages:
- "1:3: Code is unreachable after 1:3"
- "2 (counter): Loop counter is too large (pc[2] < 100000)"
- "2:3: Code is unreachable after 2:3"

---
# Issue: https://github.com/vbpf/ebpf-verifier/issues/785
# The verifier incorrectly assumes that the loop is infinite.
test-case: Count down loop - incorrectly passes
options: ["termination"]

pre: []

code:
<start>: |
r0 = 0
r1 = 10
<loop>: |
r1 -= 1
if r1 > 1 goto <loop>
exit

post:
- pc[2]=[1, +oo]
- r0.svalue=0
- r0.type=number
- r0.uvalue=0
- r1.svalue=[0, 1]
- r1.type=number
- r1.uvalue=[0, 1]

messages:
- "2: Loop counter is too large (pc[2] < 100000)"

Comment on lines +468 to +495
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Enhance test documentation with more details about the verifier's behavior.

The test case correctly demonstrates the issue where the verifier incorrectly assumes an infinite loop. Consider adding more context in the comments about:

  • Why the verifier incorrectly assumes this is an infinite loop
  • What aspect of the decrementing counter confuses the verifier
  • Expected vs actual behavior of the verifier
 # Issue: https://github.com/vbpf/ebpf-verifier/issues/785
-# The verifier incorrectly assumes that the loop is infinite.
+# The verifier incorrectly assumes that the loop is infinite despite:
+# - Loop having a clear termination condition (r1 > 1)
+# - r1 being decremented from 10 to 1, which should terminate after 9 iterations
+# - No possibility of integer overflow that could cause infinite looping
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Issue: https://github.com/vbpf/ebpf-verifier/issues/785
# The verifier incorrectly assumes that the loop is infinite.
test-case: Count down loop - incorrectly passes
options: ["termination"]
pre: []
code:
<start>: |
r0 = 0
r1 = 10
<loop>: |
r1 -= 1
if r1 > 1 goto <loop>
exit
post:
- pc[2]=[1, +oo]
- r0.svalue=0
- r0.type=number
- r0.uvalue=0
- r1.svalue=[0, 1]
- r1.type=number
- r1.uvalue=[0, 1]
messages:
- "2: Loop counter is too large (pc[2] < 100000)"
# Issue: https://github.com/vbpf/ebpf-verifier/issues/785
# The verifier incorrectly assumes that the loop is infinite despite:
# - Loop having a clear termination condition (r1 > 1)
# - r1 being decremented from 10 to 1, which should terminate after 9 iterations
# - No possibility of integer overflow that could cause infinite looping
test-case: Count down loop - incorrectly passes
options: ["termination"]
pre: []
code:
<start>: |
r0 = 0
r1 = 10
<loop>: |
r1 -= 1
if r1 > 1 goto <loop>
exit
post:
- pc[2]=[1, +oo]
- r0.svalue=0
- r0.type=number
- r0.uvalue=0
- r1.svalue=[0, 1]
- r1.type=number
- r1.uvalue=[0, 1]
messages:
- "2: Loop counter is too large (pc[2] < 100000)"

---
test-case: Count up loop
options: ["termination"]

pre: []

code:
<start>: |
r0 = 0
r1 = 0
<loop>: |
r1 += 1
if r1 < 10 goto <loop>
exit

post:
- r0.svalue=0
- r0.type=number
- r0.uvalue=0
- r1.svalue=10
- r1.type=number
- r1.uvalue=10
- r1.svalue=r1.uvalue
- pc[2]=10
- pc[2]=r1.svalue
- pc[2]=r1.uvalue

messages: []
Comment on lines +497 to +523
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Add context about test case's relationship to issue #785.

The test case correctly implements and verifies a counting up loop. Consider adding a comment explaining how this test case relates to issue #785, particularly how it demonstrates the verifier's different behavior with incrementing vs decrementing loops.

 test-case: Count up loop
 options: ["termination"]
+# Complementary test to the count down loop case in issue #785.
+# This demonstrates that the verifier correctly handles incrementing loops,
+# in contrast to its incorrect behavior with decrementing loops.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test-case: Count up loop
options: ["termination"]
pre: []
code:
<start>: |
r0 = 0
r1 = 0
<loop>: |
r1 += 1
if r1 < 10 goto <loop>
exit
post:
- r0.svalue=0
- r0.type=number
- r0.uvalue=0
- r1.svalue=10
- r1.type=number
- r1.uvalue=10
- r1.svalue=r1.uvalue
- pc[2]=10
- pc[2]=r1.svalue
- pc[2]=r1.uvalue
messages: []
test-case: Count up loop
options: ["termination"]
# Complementary test to the count down loop case in issue #785.
# This demonstrates that the verifier correctly handles incrementing loops,
# in contrast to its incorrect behavior with decrementing loops.
pre: []
code:
<start>: |
r0 = 0
r1 = 0
<loop>: |
r1 += 1
if r1 < 10 goto <loop>
exit
post:
- r0.svalue=0
- r0.type=number
- r0.uvalue=0
- r1.svalue=10
- r1.type=number
- r1.uvalue=10
- r1.svalue=r1.uvalue
- pc[2]=10
- pc[2]=r1.svalue
- pc[2]=r1.uvalue
messages: []

Loading