[BUG] CBMC: operator precedence turns the pxUDPPayloadBuffer_to_NetworkBuffer harness assumption into assume(false)

Aperta Adatta ai principianti
#1,389 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
95/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c
Ambito
testing

Direzione di ricerca

Apri test/cbmc/proofs/IPUtils/pxUDPPayloadBuffer_to_NetworkBuffer/pxUDPPayloadBuffer_to_NetworkBuffer_harness.c alla riga 88 e controlla la precedenza degli operatori nell’assunzione sul tipo IP. Aggiungi parentesi affinché la maschera venga valutata prima di ogni confronto di uguaglianza. Poi esegui i comandi di riproduzione nell’issue e conferma che CBMC segnali SUCCESS, 94 properties e coverage after the assumption come SATISFIED.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

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 );
 }
Lingua principale
C
Stelle
215
Fork
222
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di FreeRTOS/FreeRTOS-Plus-TCP

Tutte le issue di FreeRTOS/FreeRTOS-Plus-TCP

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.