[BUG] CBMC: operator precedence turns the pxUDPPayloadBuffer_to_NetworkBuffer harness assumption into assume(false)
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 95/100
Research direction
Open test/cbmc/proofs/IPUtils/pxUDPPayloadBuffer_to_NetworkBuffer/pxUDPPayloadBuffer_to_NetworkBuffer_harness.c at line 88 and check the operator precedence in the IP type assumption. Add parentheses so the mask is evaluated before each equality, then run the reproduction commands in the issue and confirm CBMC reports SUCCESS, 94 properties, and coverage after the assumption as SATISFIED.
Written by the indexing model from the issue text.
Description
Describe the bug
In the CBMC proof IPUtils/pxUDPPayloadBuffer_to_NetworkBuffer, the IP-type assumption on harness line 88 is always false, because == binds tighter than &. CBMC therefore never reaches the call to pxUDPPayloadBuffer_to_NetworkBuffer() on line 90, so none of the proof's 94 properties is checked on an actual execution of the function, yet make cbmc reports SUCCESS. Only the proof is affected, and it still passes after the fix below.
pxUDPPayloadBuffer_to_NetworkBuffer_harness.c, line 88:
__CPROVER_assume( ( ( *pucIPType ) & 0xf0 == ipTYPE_IPv4 ) || ( ( *pucIPType ) & 0xf0 == ipTYPE_IPv6 ) );
This is ( *pucIPType & ( 0xf0 == 0x40 ) ) || ( *pucIPType & ( 0xf0 == 0x60 ) ), that is *pucIPType & 0 || *pucIPType & 0, which is always 0. gcc -Wparentheses warns about both & operands on this line. The library code masks first (FreeRTOS_IP_Utils.c, line 748).
Target
Not target-specific: CBMC proof only.
Host
Ubuntu 22.04 (x86-64), CBMC 6.3.1 (the version pinned in .github/workflows/ci.yml), 32-bit glibc headers from libc6-dev-i386. main at b86ad086e9870099bb0ac18a75dcb7f6dd508cc7 (V4.4.2).
To Reproduce
The cbmc line uses the proof's own CBMCFLAGS.
git clone https://github.com/FreeRTOS/FreeRTOS-Plus-TCP.git
cd FreeRTOS-Plus-TCP
git checkout b86ad086e9870099bb0ac18a75dcb7f6dd508cc7
git submodule update --init --checkout test/FreeRTOS-Kernel
cd test/cbmc/proofs
python3 prepare.py
cd IPUtils/pxUDPPayloadBuffer_to_NetworkBuffer
make goto
make -s cbmc; grep '<cprover-status>' cbmc.xml; grep -c '<result ' cbmc.xml
cbmc --32 --object-bits 8 --unwind 1 --nondet-static --cover assume pxUDPPayloadBuffer_to_NetworkBuffer.goto | grep 'line 88'
Last lines of the output:
<cprover-status>SUCCESS</cprover-status>
94
[harness.coverage.11] file pxUDPPayloadBuffer_to_NetworkBuffer_harness.c line 88 function harness assert(false) before assume(((signed int)*pucIPType & (signed int)((unsigned int)0xF0 == 0x40u)) != 0 || ((signed int)*pucIPType & (signed int)((unsigned int)0xF0 == 0x60u)) != 0): SATISFIED
[harness.coverage.12] file pxUDPPayloadBuffer_to_NetworkBuffer_harness.c line 88 function harness assert(false) after assume(((signed int)*pucIPType & (signed int)((unsigned int)0xF0 == 0x40u)) != 0 || ((signed int)*pucIPType & (signed int)((unsigned int)0xF0 == 0x60u)) != 0): FAILED
before ...: SATISFIED together with after ...: FAILED means that CBMC reaches the assumption but the assumption never holds.
Expected behavior
The point after the assumption is reachable (after ...: SATISFIED), so pxUDPPayloadBuffer_to_NetworkBuffer() is actually checked. With the patch below, the same commands print SUCCESS, 94 and after ...: SATISFIED.
Additional context
Suggested fix (apply with git apply from the repository root):
diff --git a/test/cbmc/proofs/IPUtils/pxUDPPayloadBuffer_to_NetworkBuffer/pxUDPPayloadBuffer_to_NetworkBuffer_harness.c b/test/cbmc/proofs/IPUtils/pxUDPPayloadBuffer_to_NetworkBuffer/pxUDPPayloadBuffer_to_NetworkBuffer_harness.c
index 6d53978b..df6c879a 100644
--- a/test/cbmc/proofs/IPUtils/pxUDPPayloadBuffer_to_NetworkBuffer/pxUDPPayloadBuffer_to_NetworkBuffer_harness.c
+++ b/test/cbmc/proofs/IPUtils/pxUDPPayloadBuffer_to_NetworkBuffer/pxUDPPayloadBuffer_to_NetworkBuffer_harness.c
@@ -85,7 +85,7 @@ void harness()
pvBuffer = &pxNetworkBuffer->pucEthernetBuffer[ ipconfigBUFFER_PADDING + sizeof( UDPPacket_t ) ];
}
- __CPROVER_assume( ( ( *pucIPType ) & 0xf0 == ipTYPE_IPv4 ) || ( ( *pucIPType ) & 0xf0 == ipTYPE_IPv6 ) );
+ __CPROVER_assume( ( ( ( *pucIPType ) & 0xf0 ) == ipTYPE_IPv4 ) || ( ( ( *pucIPType ) & 0xf0 ) == ipTYPE_IPv6 ) );
( void ) pxUDPPayloadBuffer_to_NetworkBuffer( pvBuffer );
}
- Dominant language
- C
- Stars
- 215
- Forks
- 222
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from FreeRTOS/FreeRTOS-Plus-TCP
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 63/100
FreeRTOS/FreeRTOS-Plus-TCP#1395 ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
FreeRTOS/FreeRTOS-Plus-TCP#1388 ·
-
[BUG] PhyHandling incorrectly lists LAN8742A as having 19 PHYCRPossibly taken @StitchLilo626 claimed this 41 days ago. Openbug
Difficulty 1/5 Under an hour Newbie friendliness 78/100
FreeRTOS/FreeRTOS-Plus-TCP#1361 ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 66/100
FreeRTOS/FreeRTOS-Plus-TCP#1392 · 1 comment ·
-
[BUG] DHCPv6 socket-allocation failure crashes with assertions disabled; CBMC stubs hide the pathOpenbug
Difficulty 3/5 1-2 days Newbie friendliness 65/100
FreeRTOS/FreeRTOS-Plus-TCP#1391 ·
All issues in FreeRTOS/FreeRTOS-Plus-TCP
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
shinyquagsire23/OpenJKDF2#540 ·
Maintainers usually reply within 12 days
-
Prison work hall: laundry and kitchen stations stand at bare walls, the hatch has no counter or signOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Life-Framework/Life-Framework#5939 ·
Maintainers usually reply within 1 day
-
autoconf failes to find libsodium even when present due to implicit function declarationPossibly taken @coderjoe claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 13 days
-
Bug Status: Needs Triage
Difficulty 1/5 Under an hour Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
bug python
Difficulty 2/5 1-3 hours Newbie friendliness 87/100
Jstar269/nakagawa-recomp#3521 ·
Maintainers usually reply within 1 day