Skip to content

Commit 889750d

Browse files
tautschnigActoryOu
authored andcommitted
[Draft] CBMC: replace any missing functions by assert-false (#1147)
* CBMC: replace any missing functions by assert-false --------- Co-authored-by: ActoryOu <[email protected]>
1 parent abcb94c commit 889750d

File tree

79 files changed

+1850
-410
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1850
-410
lines changed

source/FreeRTOS_DNS_Cache.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,9 @@
448448
/* Add or update the item. */
449449
if( strlen( pcName ) < ( size_t ) ipconfigDNS_CACHE_NAME_LENGTH )
450450
{
451-
( void ) strncpy( xDNSCache[ uxFreeEntry ].pcName, pcName, ipconfigDNS_CACHE_NAME_LENGTH );
451+
( void ) strncpy( xDNSCache[ uxFreeEntry ].pcName, pcName, strlen( pcName ) );
452452
( void ) memcpy( &( xDNSCache[ uxFreeEntry ].xAddresses[ 0 ] ), pxIP, sizeof( *pxIP ) );
453453

454-
455454
xDNSCache[ uxFreeEntry ].ulTTL = ulTTL;
456455
xDNSCache[ uxFreeEntry ].ulTimeWhenAddedInSeconds = ulCurrentTimeSeconds;
457456
#if ( ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY > 1 )

test/cbmc/proofs/ARP/ARPAgeCache/ARPAgeCache_harness.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDes
3333
return 0;
3434
}
3535

36+
37+
void FreeRTOS_OutputAdvertiseIPv6( NetworkEndPoint_t * pxEndPoint )
38+
{
39+
__CPROVER_assert( pxEndPoint != NULL, "The Endpoint cannot be NULL." );
40+
}
41+
3642
void harness()
3743
{
3844
/*

test/cbmc/proofs/ARP/ARPAgeCache/Makefile.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto",
1616
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto",
1717
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto",
18+
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto",
19+
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto",
20+
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto",
1821
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/tasks.goto"
1922
],
2023
"DEF":

test/cbmc/proofs/ARP/ARPGetCacheEntry/Configurations.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
[
1515
"$(ENTRY)_harness.goto",
1616
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto",
17+
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IPv4.goto",
18+
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IPv4_Utils.goto",
1719
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto"
1820
],
1921
"DEF":
Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include "cbmc.h"
2-
31
/* FreeRTOS includes. */
42
#include "FreeRTOS.h"
53
#include "queue.h"
@@ -10,8 +8,37 @@
108
#include "FreeRTOS_ARP.h"
119
#include "FreeRTOS_Routing.h"
1210

11+
/* CBMC includes. */
12+
#include "cbmc.h"
13+
1314
/* This pointer is maintained by the IP-task. Defined in FreeRTOS_IP.c */
1415
extern NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer;
16+
NetworkEndPoint_t * pxNetworkEndPoint_Temp;
17+
18+
/* Stub FreeRTOS_FindEndPointOnNetMask_IPv6 as its not relevant to the
19+
* correctness of the proof */
20+
NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask_IPv6( const IPv6_Address_t * pxIPv6Address )
21+
{
22+
__CPROVER_assert( pxIPv6Address != NULL, "Precondition: pxIPv6Address != NULL" );
23+
24+
/* Assume at least one end-point is available */
25+
return pxNetworkEndPoint_Temp;
26+
}
27+
28+
/* Stub FreeRTOS_FindEndPointOnNetMask_IPv6 as its not relevant to the
29+
* correctness of the proof */
30+
NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress,
31+
uint32_t ulWhere )
32+
{
33+
/* Assume at least one end-point is available */
34+
return pxNetworkEndPoint_Temp;
35+
}
36+
37+
/* Get rid of configASSERT in FreeRTOS_TCP_IP.c */
38+
BaseType_t xIsCallingFromIPTask( void )
39+
{
40+
return pdTRUE;
41+
}
1542

1643
/* This is an output function and need not be tested with this proof. */
1744
void FreeRTOS_OutputARPRequest_Multi( NetworkEndPoint_t * pxEndPoint,
@@ -36,9 +63,19 @@ eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress,
3663

3764
void harness()
3865
{
39-
NetworkBufferDescriptor_t xLocalBuffer;
66+
NetworkBufferDescriptor_t * pxLocalBuffer;
67+
NetworkBufferDescriptor_t * pxNetworkBuffer2;
68+
TickType_t xBlockTimeTicks;
4069
uint16_t usEthernetBufferSize;
4170

71+
/*
72+
* The assumption made here is that the buffer pointed by pucEthernetBuffer
73+
* is at least allocated to sizeof(ARPPacket_t) size but eventually an even larger buffer.
74+
* This is not checked inside eARPProcessPacket.
75+
*/
76+
uint8_t ucBUFFER_SIZE;
77+
78+
4279
/* Non deterministically determine whether the pxARPWaitingNetworkBuffer will
4380
* point to some valid data or will it be NULL. */
4481
if( nondet_bool() )
@@ -47,48 +84,34 @@ void harness()
4784
* checked in the function as the pointer is stored by the IP-task itself
4885
* and therefore it will always be of the required size. */
4986
__CPROVER_assume( usEthernetBufferSize >= sizeof( IPPacket_t ) );
50-
51-
/* Add matching data length to the network buffer descriptor. */
52-
__CPROVER_assume( xLocalBuffer.xDataLength == usEthernetBufferSize );
53-
54-
xLocalBuffer.pucEthernetBuffer = malloc( usEthernetBufferSize );
87+
pxLocalBuffer = pxGetNetworkBufferWithDescriptor( usEthernetBufferSize, xBlockTimeTicks );
5588

5689
/* Since this pointer is maintained by the IP-task, either the pointer
57-
* pxARPWaitingNetworkBuffer will be NULL or xLocalBuffer.pucEthernetBuffer
90+
* pxARPWaitingNetworkBuffer will be NULL or pxLocalBuffer->pucEthernetBuffer
5891
* will be non-NULL. */
59-
__CPROVER_assume( xLocalBuffer.pucEthernetBuffer != NULL );
92+
__CPROVER_assume( pxLocalBuffer != NULL );
93+
__CPROVER_assume( pxLocalBuffer->pucEthernetBuffer != NULL );
94+
__CPROVER_assume( pxLocalBuffer->xDataLength == usEthernetBufferSize );
6095

61-
pxARPWaitingNetworkBuffer = &xLocalBuffer;
96+
pxARPWaitingNetworkBuffer = pxLocalBuffer;
6297
}
6398
else
6499
{
65100
pxARPWaitingNetworkBuffer = NULL;
66101
}
67102

68-
/*
69-
* The assumption made here is that the buffer pointed by pucEthernetBuffer
70-
* is at least allocated to sizeof(ARPPacket_t) size but eventually an even larger buffer.
71-
* This is not checked inside eARPProcessPacket.
72-
*/
73-
uint8_t ucBUFFER_SIZE;
74-
75-
void * xBuffer = malloc( ucBUFFER_SIZE + sizeof( ARPPacket_t ) );
76-
77-
__CPROVER_assume( xBuffer != NULL );
78-
79-
NetworkBufferDescriptor_t xNetworkBuffer2;
80-
81-
xNetworkBuffer2.pucEthernetBuffer = xBuffer;
82-
xNetworkBuffer2.xDataLength = ucBUFFER_SIZE + sizeof( ARPPacket_t );
103+
pxNetworkBuffer2 = pxGetNetworkBufferWithDescriptor( ucBUFFER_SIZE + sizeof( ARPPacket_t ), xBlockTimeTicks );
104+
__CPROVER_assume( pxNetworkBuffer2 != NULL );
105+
__CPROVER_assume( pxNetworkBuffer2->pucEthernetBuffer != NULL );
83106

84107
/*
85108
* This proof assumes one end point is present.
86109
*/
87-
xNetworkBuffer2.pxEndPoint = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
88-
__CPROVER_assume( xNetworkBuffer2.pxEndPoint != NULL );
89-
xNetworkBuffer2.pxEndPoint->pxNext = NULL;
110+
pxNetworkBuffer2->pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
111+
__CPROVER_assume( pxNetworkBuffer2->pxEndPoint != NULL );
112+
pxNetworkBuffer2->pxEndPoint->pxNext = NULL;
90113

91114
/* eARPProcessPacket will be called in the source code only after checking if
92-
* xNetworkBuffer2.pucEthernetBuffer is not NULL, hence, __CPROVER_assume( xBuffer != NULL ); */
93-
eARPProcessPacket( &xNetworkBuffer2 );
115+
* pxNetworkBuffer2->pucEthernetBuffer is not NULL, hence, __CPROVER_assume( xBuffer != NULL ); */
116+
eARPProcessPacket( pxNetworkBuffer2 );
94117
}

test/cbmc/proofs/ARP/ARPProcessPacket/Makefile.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
[
1212
"$(ENTRY)_harness.goto",
1313
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto",
14-
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto"
14+
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto",
15+
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto",
16+
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto",
17+
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto"
1518
]
1619
}

test/cbmc/proofs/ARP/ARPSendGratuitous/Makefile.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"$(ENTRY)_harness.goto",
1111
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto",
1212
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto",
13-
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/tasks.goto"
13+
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto",
14+
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/tasks.goto",
15+
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto"
1416
],
1517
"DEF":
1618
[

test/cbmc/proofs/ARP/ARP_FreeRTOS_OutputARPRequest/Configurations.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
"$(ENTRY)_harness.goto",
3838
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto",
3939
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto",
40-
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto"
40+
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto",
41+
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto",
42+
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto"
4143
],
4244
#That is the minimal required size for an ARPPacket_t plus offset in the buffer.
4345
"MINIMUM_PACKET_BYTES": 50,

test/cbmc/proofs/ARP/ARP_FreeRTOS_OutputARPRequest/OutputARPRequest_harness.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "FreeRTOS_IP_Private.h"
3636
#include "FreeRTOS_ARP.h"
3737

38+
/* CBMC includes. */
39+
#include "cbmc.h"
3840

3941
ARPPacket_t xARPPacket;
4042
NetworkBufferDescriptor_t xNetworkBuffer;
@@ -56,22 +58,37 @@ NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedS
5658
{
5759
#ifdef CBMC_PROOF_ASSUMPTION_HOLDS
5860
#if ( ipconfigETHERNET_MINIMUM_PACKET_BYTES > 0 )
59-
xNetworkBuffer.pucEthernetBuffer = malloc( ipconfigETHERNET_MINIMUM_PACKET_BYTES );
61+
xNetworkBuffer.pucEthernetBuffer = safeMalloc( ipconfigETHERNET_MINIMUM_PACKET_BYTES );
6062
#else
61-
xNetworkBuffer.pucEthernetBuffer = malloc( xRequestedSizeBytes );
63+
xNetworkBuffer.pucEthernetBuffer = safeMalloc( xRequestedSizeBytes );
6264
#endif
6365
#else
6466
uint32_t malloc_size;
6567
__CPROVER_assert( !__CPROVER_overflow_mult( 2, xRequestedSizeBytes ) );
6668
__CPROVER_assume( malloc_size > 0 && malloc_size < 2 * xRequestedSizeBytes );
67-
xNetworkBuffer.pucEthernetBuffer = malloc( malloc_size );
69+
xNetworkBuffer.pucEthernetBuffer = safeMalloc( malloc_size );
6870
#endif
6971
__CPROVER_assume( xNetworkBuffer.pucEthernetBuffer != NULL );
7072

7173
xNetworkBuffer.xDataLength = xRequestedSizeBytes;
7274
return &xNetworkBuffer;
7375
}
7476

77+
/* STUB!
78+
* In this function, it only allocates network buffer by pxGetNetworkBufferWithDescriptor
79+
* stub function above here. In this case, we should just free the allocated pucEthernetBuffer.
80+
*/
81+
void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer )
82+
{
83+
__CPROVER_assert( pxNetworkBuffer != NULL,
84+
"Precondition: pxNetworkBuffer != NULL" );
85+
86+
if( pxNetworkBuffer->pucEthernetBuffer != NULL )
87+
{
88+
free( pxNetworkBuffer->pucEthernetBuffer );
89+
}
90+
}
91+
7592
BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDescriptor,
7693
NetworkBufferDescriptor_t * const pxNetworkBuffer,
7794
BaseType_t xReleaseAfterSend )
@@ -81,6 +98,14 @@ BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDes
8198
__CPROVER_assert( pxNetworkBuffer->pucEthernetBuffer != NULL, "The ethernet buffer cannot be NULL." );
8299
}
83100

101+
BaseType_t xIsCallingFromIPTask( void )
102+
{
103+
BaseType_t xReturn;
104+
105+
__CPROVER_assume( xReturn == pdFALSE || xReturn == pdTRUE );
106+
107+
return xReturn;
108+
}
84109

85110
void harness()
86111
{
@@ -92,16 +117,16 @@ void harness()
92117
* Assumes one endpoint and interface is present.
93118
*/
94119

95-
pxNetworkEndPoints = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
120+
pxNetworkEndPoints = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
96121
__CPROVER_assume( pxNetworkEndPoints != NULL );
97122

98123
/* Interface init. */
99-
pxNetworkEndPoints->pxNetworkInterface = ( NetworkInterface_t * ) malloc( sizeof( NetworkInterface_t ) );
124+
pxNetworkEndPoints->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) );
100125
__CPROVER_assume( pxNetworkEndPoints->pxNetworkInterface != NULL );
101126

102127
if( nondet_bool() )
103128
{
104-
pxNetworkEndPoints->pxNext = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
129+
pxNetworkEndPoints->pxNext = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
105130
__CPROVER_assume( pxNetworkEndPoints->pxNext != NULL );
106131
pxNetworkEndPoints->pxNext->pxNext = NULL;
107132
pxNetworkEndPoints->pxNext->pxNetworkInterface = pxNetworkEndPoints->pxNetworkInterface;

test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/Configurations.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto",
1515
"$(FREERTOS_PLUS_TCP)/source/portable/BufferManagement/BufferAllocation_1.goto",
1616
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto",
17-
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/queue.goto"
17+
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/queue.goto",
18+
"$(FREERTOS_PLUS_TCP)/test/cbmc/proofs/CBMCStubLibrary/tasksStubs.goto",
19+
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto"
1820
],
1921
"DEF":
2022
[

0 commit comments

Comments
 (0)