[BUG] CBMC: ProcessReceivedTCPPacket_IPv6 allocator stub fixes xDataLength at 18 bytes, so every segment is rejected
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- c
- Ambito
- testing-qa
Direzione di ricerca
Read test/cbmc/proofs/parsing/ProcessReceivedTCPPacket_IPv6/ProcessReceivedTCPPacket_IPv6_harness.c and its Makefile.json, then compare them with the IPv4 proof files named in the issue. Run python3 prepare.py in test/cbmc/proofs before running make goto and make cbmc in the IPv6 proof directory. Done means the IPv6 proof reaches the intended packet processing paths and passes with the expected property and coverage results.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
In the CBMC proof parsing/ProcessReceivedTCPPacket_IPv6, the pxGetNetworkBufferWithDescriptor() stub sets xDataLength to ipSIZE_OF_ETH_HEADER + sizeof( int32_t ) = 18 bytes, although the harness requests at least ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + sizeof( TCPHeader_t ) = 74 bytes. xProcessReceivedTCPPacket() therefore rejects every buffer at its minimum-size check and returns pdFAIL. The proof never reaches the socket lookup, option checking, state handling or reply paths, yet make cbmc reports SUCCESS. Only the proof is affected, and it still passes after the fix below.
ProcessReceivedTCPPacket_IPv6_harness.c, lines 80-81:
pxNetworkBuffer->pucEthernetBuffer = safeMalloc( xRequestedSizeBytes );
__CPROVER_assume( pxNetworkBuffer->xDataLength == ipSIZE_OF_ETH_HEADER + sizeof( int32_t ) );
The IPv4 harness had the same line until #1258 (28dd66ce23c966625fc0e1c58340b8fef5ffa781) replaced it with pxNetworkBuffer->xDataLength = xRequestedSizeBytes; (IPv4 harness, line 157). That commit also edited the IPv6 harness but kept this assumption.
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 plus the flags of the coverage make target. The sed line temporarily replaces the call in the harness with __CPROVER_assert( xProcessReceivedTCPPacket( pxNetworkBuffer ) == pdFAIL, "every segment is rejected" ).
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 parsing/ProcessReceivedTCPPacket_IPv6
make goto
make -s cbmc; grep '<cprover-status>' cbmc.xml; grep -c '<result ' cbmc.xml
cbmc --32 --object-bits 8 --unwind 1 --unwindset prvTCPSendRepeated.0:13 --nondet-static --no-standard-checks --malloc-may-fail --malloc-fail-null \
--cover location ProcessReceivedTCPPacket_IPv6.goto \
| grep 'function xProcessReceivedTCPPacket ' | grep -c 'SATISFIED$'
sed -i.orig 's/^ xProcessReceivedTCPPacket( pxNetworkBuffer );/ __CPROVER_assert( xProcessReceivedTCPPacket( pxNetworkBuffer ) == pdFAIL, "every segment is rejected" );/' ProcessReceivedTCPPacket_IPv6_harness.c
make -s goto cbmc; grep '<cprover-status>' cbmc.xml
mv ProcessReceivedTCPPacket_IPv6_harness.c.orig ProcessReceivedTCPPacket_IPv6_harness.c
Last lines of the output:
<cprover-status>SUCCESS</cprover-status>
660
6
<cprover-status>SUCCESS</cprover-status>
The proof passes with 660 properties, only 6 of the 69 location goals in xProcessReceivedTCPPacket() are reachable, and CBMC proves that every segment is rejected.
Expected behavior
Segments of a valid length get past the size check. With the patch below, the same commands give:
| current | with the patch | |
|---|---|---|
make cbmc |
SUCCESS, 660 properties |
SUCCESS, 758 properties |
reachable location goals in xProcessReceivedTCPPacket() (of 69) |
6 | 68 |
| "every segment is rejected" | SUCCESS (proved) |
FAILURE |
The IPv4 proof parsing/ProcessReceivedTCPPacket gives SUCCESS, 751 properties and 68 of 69 with the same make and --cover location commands, run in its directory on ProcessReceivedTCPPacket.goto.
Additional context
Changing only the allocator line, as #1258 did for IPv4, makes 53 properties fail. With realistic lengths the proof reaches functions that this harness neither links nor stubs, which get assert(false) bodies (Makefile.template, line 109), and the real vTCPStateChange(), which the IPv4 harness stubs. The patch below therefore makes the IPv6 harness mirror the IPv4 one: the same stubs (with prvHandleListen_IPV6 instead of prvHandleListen_IPV4), the same allocator stub, and the same sources in Makefile.json, using the _IPv6 variants. Afterwards the two harness files differ only in IPv4/IPv6 names and in the IPv6 frame-type assumption.
Apply it with git apply from the repository root, then run python3 prepare.py again in test/cbmc/proofs, because it changes Makefile.json.
Patch: ProcessReceivedTCPPacket_IPv6 harness and Makefile.json
diff --git a/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket_IPv6/Makefile.json b/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket_IPv6/Makefile.json
index c37bc279..a733d1ec 100644
--- a/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket_IPv6/Makefile.json
+++ b/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket_IPv6/Makefile.json
@@ -12,7 +12,16 @@
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto",
- "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_IP.goto"
+ "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto",
+ "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto",
+ "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Timers.goto",
+ "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_IP.goto",
+ "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_IP_IPv6.goto",
+ "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission.goto",
+ "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission_IPv6.goto",
+ "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_State_Handling.goto",
+ "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Utils.goto",
+ "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Reception.goto"
],
"INSTFLAGS":
[
diff --git a/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket_IPv6/ProcessReceivedTCPPacket_IPv6_harness.c b/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket_IPv6/ProcessReceivedTCPPacket_IPv6_harness.c
index 204d404e..926c8b67 100644
--- a/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket_IPv6/ProcessReceivedTCPPacket_IPv6_harness.c
+++ b/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket_IPv6/ProcessReceivedTCPPacket_IPv6_harness.c
@@ -12,9 +12,8 @@
#include "cbmc.h"
#include "../../utility/memory_assignments.c"
-/* This proof assumes pxTCPSocketLookup, vTCPStateChange, prvTCPSocketIsActive, xIsCallingFromIPTask,
- * xSequenceGreaterThan, xSequenceLessThan, xTaskGetTickCount, vReleaseNetworkBufferAndDescriptor, xTCPWindowTxHasData and
- * pxGetNetworkBufferWithDescriptor are implemented correctly.
+/* This proof assumes pxTCPSocketLookup and pxGetNetworkBufferWithDescriptor
+ * are implemented correctly.
*
* It also assumes prvSingleStepTCPHeaderOptions, prvCheckOptions, prvTCPPrepareSend,
* prvTCPHandleState, prvHandleListen_IPV6 and prvTCPReturnPacket are correct. These functions are
@@ -36,9 +35,86 @@ TaskHandle_t xTaskGetCurrentTaskHandle( void )
return pxCurrentTCB;
}
-/* Abstraction of prvHandleListen */
-FreeRTOS_Socket_t * prvHandleListen( FreeRTOS_Socket_t * pxSocket,
- NetworkBufferDescriptor_t * pxNetworkBuffer )
+/* Abstraction of vTCPStateChange */
+void vTCPStateChange( FreeRTOS_Socket_t * pxSocket,
+ enum eTCP_STATE eTCPState )
+{
+}
+
+/* prvTCPReturnPacket is proven separately */
+void prvTCPReturnPacket( FreeRTOS_Socket_t * pxSocket,
+ NetworkBufferDescriptor_t * pxDescriptor,
+ uint32_t ulLen,
+ BaseType_t xReleaseAfterSend )
+{
+ __CPROVER_assert( pxSocket != NULL || pxDescriptor != NULL, "Either pxSocket or pxDescriptor must be non-NULL" );
+ __CPROVER_assert( pxDescriptor->pucEthernetBuffer != NULL, "pucEthernetBuffer should not be NULL" );
+}
+
+/* prvTCPPrepareSend is proven separately. */
+int32_t prvTCPPrepareSend( FreeRTOS_Socket_t * pxSocket,
+ NetworkBufferDescriptor_t ** ppxNetworkBuffer,
+ UBaseType_t uxOptionsLength )
+{
+ int32_t ret = nondet_int32();
+
+ __CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" );
+ __CPROVER_assert( *ppxNetworkBuffer != NULL, "*ppxNetworkBuffer cannot be NULL" );
+ __CPROVER_assert( __CPROVER_r_ok( ( *ppxNetworkBuffer )->pucEthernetBuffer, ( *ppxNetworkBuffer )->xDataLength ), "Data in *ppxNetworkBuffer must be readable" );
+
+ __CPROVER_assume( ret >= 0 && ret <= ipconfigNETWORK_MTU );
+ return ret;
+}
+
+/* prvTCPHandleState is proven separately. */
+BaseType_t prvTCPHandleState( FreeRTOS_Socket_t * pxSocket,
+ NetworkBufferDescriptor_t ** ppxNetworkBuffer )
+{
+ __CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" );
+ __CPROVER_assert( *ppxNetworkBuffer != NULL, "*ppxNetworkBuffer cannot be NULL" );
+ __CPROVER_assert( __CPROVER_r_ok( ( *ppxNetworkBuffer )->pucEthernetBuffer, ( *ppxNetworkBuffer )->xDataLength ), "Data in *ppxNetworkBuffer must be readable" );
+
+ return nondet_basetype();
+}
+
+/* prvCheckOptions is proven separately. */
+BaseType_t prvCheckOptions( FreeRTOS_Socket_t * pxSocket,
+ const NetworkBufferDescriptor_t * pxNetworkBuffer )
+{
+ __CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" );
+ __CPROVER_assert( pxNetworkBuffer != NULL, "*ppxNetworkBuffer cannot be NULL" );
+ __CPROVER_assert( __CPROVER_r_ok( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength ), "Data in *ppxNetworkBuffer must be readable" );
+
+ return nondet_basetype();
+}
+
+BaseType_t xTCPWindowTxHasData( TCPWindow_t const * pxWindow,
+ uint32_t ulWindowSize,
+ TickType_t * pulDelay )
+{
+ __CPROVER_assert( pxWindow != NULL, "pxWindow cannot be NULL" );
+ __CPROVER_assert( pulDelay != NULL, "pulDelay cannot be NULL" );
+
+ return nondet_basetype();
+}
+
+/* Abstraction of xSequenceLessThan */
+BaseType_t xSequenceLessThan( uint32_t a,
+ uint32_t b )
+{
+ return nondet_basetype();
+}
+
+/* Abstraction of xSequenceGreaterThan */
+BaseType_t xSequenceGreaterThan( uint32_t a,
+ uint32_t b )
+{
+ return nondet_basetype();
+}
+
+/* Abstraction of prvHandleListen_IPV6 */
+FreeRTOS_Socket_t * prvHandleListen_IPV6( FreeRTOS_Socket_t * pxSocket,
+ NetworkBufferDescriptor_t * pxNetworkBuffer )
{
FreeRTOS_Socket_t * xRetSocket = ensure_FreeRTOS_Socket_t_is_allocated();
@@ -78,7 +154,7 @@ NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedS
if( pxNetworkBuffer )
{
pxNetworkBuffer->pucEthernetBuffer = safeMalloc( xRequestedSizeBytes );
- __CPROVER_assume( pxNetworkBuffer->xDataLength == ipSIZE_OF_ETH_HEADER + sizeof( int32_t ) );
+ pxNetworkBuffer->xDataLength = xRequestedSizeBytes;
}
return pxNetworkBuffer;
- Lingua principale
- C
- Stelle
- 215
- Fork
- 222
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di FreeRTOS/FreeRTOS-Plus-TCP
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 63/100
FreeRTOS/FreeRTOS-Plus-TCP#1395 ·
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
FreeRTOS/FreeRTOS-Plus-TCP#1389 ·
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
FreeRTOS/FreeRTOS-Plus-TCP#1388 ·
-
[BUG] PhyHandling incorrectly lists LAN8742A as having 19 PHYCRForse già presa @StitchLilo626 l’ha presa 41 giorni fa. Apertabug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
FreeRTOS/FreeRTOS-Plus-TCP#1361 ·
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 66/100
FreeRTOS/FreeRTOS-Plus-TCP#1392 · 1 commento ·
Tutte le issue di FreeRTOS/FreeRTOS-Plus-TCP
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
qoretechnologies/qore#8222 ·
I maintainer di solito rispondono entro 1 giorno
-
c easy first-contributor first-contributors good first issue help wanted up-for-grabs
Difficoltà 1/5 1-3 ore Idoneità per principianti 96/100
fork-commit-merge/fork-commit-merge#8696 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
libsdl-org/SDL#16873 ·
I maintainer di solito rispondono entro 1 giorno