first commit

This commit is contained in:
fewikay committed 2026-10-16 13:08:06 +02:00
commit 92cbe97616
1978 files changed
+1688498

No files matched your search

@@ -0,0 +1,73 @@
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "list.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_ARP.h"
/*We assume that the pxGetNetworkBufferWithDescriptor function is implemented correctly and returns a valid data structure. */
/*This is the mock to mimic the correct expected behavior. If this allocation fails, this might invalidate the proof. */
NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes,
TickType_t xBlockTimeTicks )
{
NetworkBufferDescriptor_t * pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) malloc( sizeof( NetworkBufferDescriptor_t ) );
__CPROVER_assume( pxNetworkBuffer != NULL );
pxNetworkBuffer->pucEthernetBuffer = malloc( xRequestedSizeBytes );
__CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL );
pxNetworkBuffer->xDataLength = xRequestedSizeBytes;
return pxNetworkBuffer;
}
BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDescriptor,
NetworkBufferDescriptor_t * const pxNetworkBuffer,
BaseType_t xReleaseAfterSend )
{
__CPROVER_assert( pxDescriptor != NULL, "The network interface cannot be NULL." );
__CPROVER_assert( pxNetworkBuffer != NULL, "The network buffer descriptor cannot be NULL." );
__CPROVER_assert( pxNetworkBuffer->pucEthernetBuffer != NULL, "The Ethernet buffer cannot be NULL." );
return 0;
}
void FreeRTOS_OutputAdvertiseIPv6( NetworkEndPoint_t * pxEndPoint )
{
__CPROVER_assert( pxEndPoint != NULL, "The Endpoint cannot be NULL." );
}
void harness()
{
/*
* For this proof, its assumed that the endpoints and interfaces are correctly
* initialised and the pointers are set correctly.
* Assumes two endpoints and interface is present.
*/
pxNetworkEndPoints = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxNetworkEndPoints != NULL );
/* Interface init. */
pxNetworkEndPoints->pxNetworkInterface = ( NetworkInterface_t * ) malloc( sizeof( NetworkInterface_t ) );
__CPROVER_assume( pxNetworkEndPoints->pxNetworkInterface != NULL );
if( nondet_bool() )
{
pxNetworkEndPoints->pxNext = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxNetworkEndPoints->pxNext != NULL );
pxNetworkEndPoints->pxNext->pxNext = NULL;
pxNetworkEndPoints->pxNext->pxNetworkInterface = pxNetworkEndPoints->pxNetworkInterface;
}
else
{
pxNetworkEndPoints->pxNext = NULL;
}
pxNetworkEndPoints->pxNetworkInterface->pfOutput = NetworkInterfaceOutputFunction_Stub;
/* No assumption is added for pfOutput as its pointed to a static object/memory location. */
vARPAgeCache();
}
@@ -0,0 +1,26 @@
{
"ENTRY": "ARPAgeCache",
"CBMCFLAGS":
[
"--unwind 1",
"--unwindset vARPAgeCache.0:7",
"--unwindset FreeRTOS_OutputARPRequest.0:3",
"--unwindset FreeRTOS_InterfaceEndPointOnNetMask.0:3",
"--unwindset vARPAgeCache.1:3",
"--nondet-static"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto",
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/tasks.goto"
],
"DEF":
[
]
}
@@ -0,0 +1,2 @@
Assuming that xNetworkInterfaceOutput is memory safe,
this harness proves the memory safety of the vARPAgeCache function.
@@ -0,0 +1,39 @@
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "queue.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_ARP.h"
void harness()
{
/*
* The assumption made here is that the buffer pointed by pucEthernetBuffer
* is at least allocated to sizeof(ARPPacket_t) size but eventually a even larger buffer.
* This is not checked inside vARPGenerateRequestPacket.
*/
uint8_t ucBUFFER_SIZE;
__CPROVER_assume( ucBUFFER_SIZE >= sizeof( ARPPacket_t ) && ucBUFFER_SIZE < 2 * sizeof( ARPPacket_t ) );
void * xBuffer = malloc( ucBUFFER_SIZE );
__CPROVER_assume( xBuffer != NULL );
NetworkBufferDescriptor_t xNetworkBuffer2;
xNetworkBuffer2.pucEthernetBuffer = xBuffer;
xNetworkBuffer2.xDataLength = ucBUFFER_SIZE;
/*
* This proof assumes one end point is present.
*/
xNetworkBuffer2.pxEndPoint = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( xNetworkBuffer2.pxEndPoint != NULL );
xNetworkBuffer2.pxEndPoint->pxNext = NULL;
/* vARPGenerateRequestPacket asserts buffer has room for a packet */
__CPROVER_assume( xNetworkBuffer2.xDataLength >= sizeof( ARPPacket_t ) );
vARPGenerateRequestPacket( &xNetworkBuffer2 );
}
@@ -0,0 +1,16 @@
{
"ENTRY": "ARPGenerateRequestPacket",
"CBMCFLAGS":
[
"--unwind 1"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto"
],
"DEF":
[
]
}
@@ -0,0 +1,3 @@
Given that the pointer target of xNetworkDescriptor.pucEthernetBuffer is allocated
to the size claimed in xNetworkDescriptor.xDataLength,
this harness proves the memory safety of ARPGenerateRequestPacket.
@@ -0,0 +1,43 @@
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "queue.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_ARP.h"
void harness()
{
uint32_t ulIPAddress;
MACAddress_t xMACAddress;
struct xNetworkEndPoint * pxEndPoint = NULL;
/*
* For this proof, its assumed that the endpoints and interfaces are correctly
* initialised and the pointers are set correctly.
* Assumes one endpoint and interface is present.
*/
pxNetworkEndPoints = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxNetworkEndPoints != NULL );
/* Interface init. */
pxNetworkEndPoints->pxNetworkInterface = ( NetworkInterface_t * ) malloc( sizeof( NetworkInterface_t ) );
__CPROVER_assume( pxNetworkEndPoints->pxNetworkInterface != NULL );
if( nondet_bool() )
{
pxNetworkEndPoints->pxNext = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxNetworkEndPoints->pxNext != NULL );
pxNetworkEndPoints->pxNext->pxNext = NULL;
pxNetworkEndPoints->pxNext->pxNetworkInterface = pxNetworkEndPoints->pxNetworkInterface;
}
else
{
pxNetworkEndPoints->pxNext = NULL;
}
eARPGetCacheEntry( &ulIPAddress, &xMACAddress, &pxEndPoint );
}
@@ -0,0 +1,49 @@
{
"ENTRY": "ARPGetCacheEntry",
"CBMCFLAGS":
[
"--unwind 1",
"--unwindset prvCacheLookup.0:7",
"--unwindset FreeRTOS_FindEndPointOnIP_IPv4.0:3",
"--unwindset FreeRTOS_InterfaceEndPointOnNetMask.0:3",
"--unwindset xIsIPv4Broadcast.0:3",
"--unwindset eARPGetCacheEntry.0:3",
"--unwindset FreeRTOS_FindGateWay.0:3",
"--nondet-static"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IPv4.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IPv4_Utils.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto"
],
"DEF":
[
{
"ARPGetCacheEntry_default":[
"ipconfigARP_STORES_REMOTE_ADDRESSES=0",
"ipconfigUSE_LLMNR=0"
]
},
{
"ARPGetCacheEntry_LLMNR": [
"ipconfigARP_STORES_REMOTE_ADDRESSES=0",
"ipconfigUSE_LLMNR=1"
]
},
{
"ARPGetCacheEntry_STORE_REMOTE": [
"ipconfigARP_STORES_REMOTE_ADDRESSES=1",
"ipconfigUSE_LLMNR=0"
]
},
{
"ARPGetCacheEntry_REMOTE_LLMNR": [
"ipconfigARP_STORES_REMOTE_ADDRESSES=1",
"ipconfigUSE_LLMNR=1"
]
}
]
}
@@ -0,0 +1,4 @@
The combined proofs in the subdirectories prove that ARPGetCacheEntry
is memory safe for all possible combinations of ipconfigARP_STORES_REMOTE_ADDRESSES
and ipconfigUSE_LLMNR. These are the only configuration
parameters used inside the ARPGetCacheEntry.
@@ -0,0 +1,28 @@
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "queue.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_ARP.h"
extern ARPCacheRow_t xARPCache[ ipconfigARP_CACHE_ENTRIES ];
static NetworkEndPoint_t xEndPoint_Temp;
void harness()
{
MACAddress_t xMACAddress;
uint32_t ulIPAddress;
NetworkInterface_t ** ppxInterface = ( NetworkInterface_t ** ) malloc( sizeof( NetworkInterface_t * ) );
if( ppxInterface )
{
*ppxInterface = ( NetworkInterface_t * ) malloc( sizeof( NetworkInterface_t ) );
__CPROVER_assume( *ppxInterface != NULL );
}
eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, ppxInterface );
}
@@ -0,0 +1,16 @@
{
"ENTRY": "ARPGetCacheEntryByMac",
"CBMCFLAGS":
[
"--unwind 7"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto"
],
"DEF":
[
"ipconfigUSE_ARP_REVERSED_LOOKUP=1", "ipconfigARP_CACHE_ENTRIES=6"
]
}
@@ -0,0 +1,4 @@
ARPGetCacheEntryByMac is memory safe,
if it is enabled.
ARPGetCacheEntryByMac does not use multiple configurations internally.
@@ -0,0 +1,116 @@
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "queue.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_ARP.h"
#include "FreeRTOS_Routing.h"
/* CBMC includes. */
#include "cbmc.h"
/* This pointer is maintained by the IP-task. Defined in FreeRTOS_IP.c */
extern NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer;
NetworkEndPoint_t * pxNetworkEndPoint_Temp;
/* Stub FreeRTOS_FindEndPointOnNetMask_IPv6 as its not relevant to the
* correctness of the proof */
NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask_IPv6( const IPv6_Address_t * pxIPv6Address )
{
__CPROVER_assert( pxIPv6Address != NULL, "Precondition: pxIPv6Address != NULL" );
/* Assume at least one end-point is available */
return pxNetworkEndPoint_Temp;
}
/* Stub FreeRTOS_FindEndPointOnNetMask_IPv6 as its not relevant to the
* correctness of the proof */
NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress )
{
/* Assume at least one end-point is available */
return pxNetworkEndPoint_Temp;
}
/* Get rid of configASSERT in FreeRTOS_TCP_IP.c */
BaseType_t xIsCallingFromIPTask( void )
{
return pdTRUE;
}
/* This is an output function and need not be tested with this proof. */
void FreeRTOS_OutputARPRequest_Multi( NetworkEndPoint_t * pxEndPoint,
uint32_t ulIPAddress )
{
}
/* This function is proved elsewhere hence stubbing it out */
eResolutionLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress,
MACAddress_t * const pxMACAddress,
struct xNetworkEndPoint ** ppxEndPoint )
{
eResolutionLookupResult_t eReturn;
__CPROVER_assert( pulIPAddress != NULL, "pulIPAddress cannot be NULL." );
__CPROVER_assert( pxMACAddress != NULL, "pxMACAddress cannot be NULL." );
__CPROVER_assert( ppxEndPoint != NULL, "ppxEndPoint cannot be NULL." );
/* Return random value */
return eReturn;
}
void harness()
{
NetworkBufferDescriptor_t * pxLocalBuffer;
NetworkBufferDescriptor_t * pxNetworkBuffer2;
TickType_t xBlockTimeTicks;
uint16_t usEthernetBufferSize;
/*
* The assumption made here is that the buffer pointed by pucEthernetBuffer
* is at least allocated to sizeof(ARPPacket_t) size but eventually an even larger buffer.
* This is not checked inside eARPProcessPacket.
*/
uint8_t ucBUFFER_SIZE;
/* Non deterministically determine whether the pxARPWaitingNetworkBuffer will
* point to some valid data or will it be NULL. */
if( nondet_bool() )
{
/* The packet must at least be as big as an IP Packet. The size is not
* checked in the function as the pointer is stored by the IP-task itself
* and therefore it will always be of the required size. */
__CPROVER_assume( usEthernetBufferSize >= sizeof( IPPacket_t ) );
pxLocalBuffer = pxGetNetworkBufferWithDescriptor( usEthernetBufferSize, xBlockTimeTicks );
/* Since this pointer is maintained by the IP-task, either the pointer
* pxARPWaitingNetworkBuffer will be NULL or pxLocalBuffer->pucEthernetBuffer
* will be non-NULL. */
__CPROVER_assume( pxLocalBuffer != NULL );
__CPROVER_assume( pxLocalBuffer->pucEthernetBuffer != NULL );
__CPROVER_assume( pxLocalBuffer->xDataLength == usEthernetBufferSize );
pxARPWaitingNetworkBuffer = pxLocalBuffer;
}
else
{
pxARPWaitingNetworkBuffer = NULL;
}
pxNetworkBuffer2 = pxGetNetworkBufferWithDescriptor( ucBUFFER_SIZE + sizeof( ARPPacket_t ), xBlockTimeTicks );
__CPROVER_assume( pxNetworkBuffer2 != NULL );
__CPROVER_assume( pxNetworkBuffer2->pucEthernetBuffer != NULL );
/*
* This proof assumes one end point is present.
*/
pxNetworkBuffer2->pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxNetworkBuffer2->pxEndPoint != NULL );
pxNetworkBuffer2->pxEndPoint->pxNext = NULL;
/* eARPProcessPacket will be called in the source code only after checking if
* pxNetworkBuffer2->pucEthernetBuffer is not NULL, hence, __CPROVER_assume( xBuffer != NULL ); */
eARPProcessPacket( pxNetworkBuffer2 );
}
@@ -0,0 +1,19 @@
{
"ENTRY": "ARPProcessPacket",
"CBMCFLAGS":
[
"--unwind 1",
"--unwindset vARPRefreshCacheEntry.0:7,memcmp.0:17,xIsIPInARPCache.0:7",
"--unwindset prvFindCacheEntry.0:7",
"--nondet-static"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto",
"$(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"
]
}
@@ -0,0 +1,4 @@
The proofs in the subdirectories show that
ARPProcessPacket is memory safe independent
of the configuration value of
ipconfigARP_USE_CLASH_DETECTION.
@@ -0,0 +1,44 @@
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "queue.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_ARP.h"
void harness()
{
MACAddress_t xMACAddress;
uint32_t ulIPAddress;
/*
* For this proof, its assumed that the endpoints and interfaces are correctly
* initialised and the pointers are set correctly.
* Assumes one endpoints and interface is present.
*/
pxNetworkEndPoints = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxNetworkEndPoints != NULL );
/* Interface init. */
pxNetworkEndPoints->pxNetworkInterface = ( NetworkInterface_t * ) malloc( sizeof( NetworkInterface_t ) );
__CPROVER_assume( pxNetworkEndPoints->pxNetworkInterface != NULL );
if( nondet_bool() )
{
pxNetworkEndPoints->pxNext = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxNetworkEndPoints->pxNext != NULL );
pxNetworkEndPoints->pxNext->pxNext = NULL;
pxNetworkEndPoints->pxNext->pxNetworkInterface = pxNetworkEndPoints->pxNetworkInterface;
}
else
{
pxNetworkEndPoints->pxNext = NULL;
}
NetworkEndPoint_t * pxEndPoint = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxEndPoint != NULL );
vARPRefreshCacheEntry( &xMACAddress, ulIPAddress, pxEndPoint );
vARPRefreshCacheEntry( NULL, ulIPAddress, pxEndPoint );
}
@@ -0,0 +1,20 @@
{
"ENTRY": "ARPRefreshCacheEntry",
"CBMCFLAGS":
[
"--unwind 1",
"--unwindset FreeRTOS_InterfaceEndPointOnNetMask.0:3",
"--unwindset prvFindCacheEntry.0:7,memcmp.0:17"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto"
],
"DEF":
[
{"NOT_STORE_REMOTE":["ipconfigARP_STORES_REMOTE_ADDRESSES=0"]},
{"STORE_REMOTE":["ipconfigARP_STORES_REMOTE_ADDRESSES=1"]}
]
}
@@ -0,0 +1,4 @@
The proofs in this directory guarantee together that
ARPRefreshCacheEntry is memory safe independent
of the configuration value of
ipconfigARP_STORES_REMOTE_ADDRESSES.
@@ -0,0 +1,13 @@
/* / * FreeRTOS includes. * / */
#include "FreeRTOS.h"
#include "queue.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_ARP.h"
void harness()
{
vARPSendGratuitous();
}
@@ -0,0 +1,20 @@
{
"ENTRY": "ARPSendGratuitous",
"CBMCFLAGS":
[
"--unwind 1",
"--nondet-static"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto",
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/tasks.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto"
],
"DEF":
[
]
}
@@ -0,0 +1,6 @@
Abstracting xQueueGenericSend away
and including tasks.c and FreeRTOS_IP.c:
The ARPSendGratuitous function is memory safe,
if xQueueGenericSend is memory safe.
queue.c is not compiled into the proof binary.
@@ -0,0 +1,19 @@
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "queue.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_ARP.h"
void harness()
{
NetworkEndPoint_t * pxEndPoint_Test = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
/*
* Here the assumption that pxEndPoint_Test != NULL [__CPROVER_assume( pxEndPoint_Test != NULL );]
* is not made as pxEndPoint_Test == NULL is a valid use case.
*/
FreeRTOS_ClearARP( pxEndPoint_Test );
}
@@ -0,0 +1,16 @@
{
"ENTRY": "ClearARP",
"CBMCFLAGS":
[
"--unwind 1",
"--unwindset FreeRTOS_ClearARP.0:7"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto"
],
"DEF":
[
]
}
@@ -0,0 +1,2 @@
This proof demonstrates the memory safety of the ClearARP function in the FreeRTOS_ARP.c file.
No restrictions are made.
@@ -0,0 +1,61 @@
#
# FreeRTOS memory safety proofs with CBMC.
# Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use, copy,
# modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# http://aws.amazon.com/freertos
# http://www.FreeRTOS.org
#
{
"ENTRY": "OutputARPRequest",
"CBMCFLAGS":
[
"--unwind 20"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto"
],
#That is the minimal required size for an ARPPacket_t plus offset in the buffer.
"MINIMUM_PACKET_BYTES": 50,
"DEF":
[
{
"CBMC_PROOF_ASSUMPTION_HOLDS_Packet_bytes": [
"CBMC_PROOF_ASSUMPTION_HOLDS=1",
"ipconfigETHERNET_MINIMUM_PACKET_BYTES={MINIMUM_PACKET_BYTES}"
]
},
{
"CBMC_PROOF_ASSUMPTION_HOLDS_no_packet_bytes": ["CBMC_PROOF_ASSUMPTION_HOLDS=1"]
},
{
"CBMC_PROOF_ASSUMPTION_DOES_NOT_HOLD": ["CBMC_PROOF_ASSUMPTION_HOLDS=0"]
}
]
}
@@ -0,0 +1,143 @@
/*
* FreeRTOS memory safety proofs with CBMC.
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "queue.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_ARP.h"
/* CBMC includes. */
#include "cbmc.h"
ARPPacket_t xARPPacket;
NetworkBufferDescriptor_t xNetworkBuffer;
/* STUB!
* We assume that the pxGetNetworkBufferWithDescriptor function is
* implemented correctly and returns a valid data structure.
* This is the mock to mimic the expected behavior.
* If this allocation fails, this might invalidate the proof.
* FreeRTOS_OutputARPRequest calls pxGetNetworkBufferWithDescriptor
* to get a NetworkBufferDescriptor. Then it calls vARPGenerateRequestPacket
* passing this buffer along in the function call. vARPGenerateRequestPacket
* casts the pointer xNetworkBuffer.pucEthernetBuffer into an ARPPacket_t pointer
* and writes a complete ARPPacket to it. Therefore the buffer has to be at least of the size
* of an ARPPacket to guarantee memory safety.
*/
NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes,
TickType_t xBlockTimeTicks )
{
#ifdef CBMC_PROOF_ASSUMPTION_HOLDS
#if ( ipconfigETHERNET_MINIMUM_PACKET_BYTES > 0 )
xNetworkBuffer.pucEthernetBuffer = safeMalloc( ipconfigETHERNET_MINIMUM_PACKET_BYTES );
#else
xNetworkBuffer.pucEthernetBuffer = safeMalloc( xRequestedSizeBytes );
#endif
#else
uint32_t malloc_size;
__CPROVER_assert( !__CPROVER_overflow_mult( 2, xRequestedSizeBytes ) );
__CPROVER_assume( malloc_size > 0 && malloc_size < 2 * xRequestedSizeBytes );
xNetworkBuffer.pucEthernetBuffer = safeMalloc( malloc_size );
#endif
__CPROVER_assume( xNetworkBuffer.pucEthernetBuffer != NULL );
xNetworkBuffer.xDataLength = xRequestedSizeBytes;
return &xNetworkBuffer;
}
/* STUB!
* In this function, it only allocates network buffer by pxGetNetworkBufferWithDescriptor
* stub function above here. In this case, we should just free the allocated pucEthernetBuffer.
*/
void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer )
{
__CPROVER_assert( pxNetworkBuffer != NULL,
"Precondition: pxNetworkBuffer != NULL" );
if( pxNetworkBuffer->pucEthernetBuffer != NULL )
{
free( pxNetworkBuffer->pucEthernetBuffer );
}
}
BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDescriptor,
NetworkBufferDescriptor_t * const pxNetworkBuffer,
BaseType_t xReleaseAfterSend )
{
__CPROVER_assert( pxDescriptor != NULL, "The network interface cannot be NULL." );
__CPROVER_assert( pxNetworkBuffer != NULL, "The network buffer descriptor cannot be NULL." );
__CPROVER_assert( pxNetworkBuffer->pucEthernetBuffer != NULL, "The ethernet buffer cannot be NULL." );
}
BaseType_t xIsCallingFromIPTask( void )
{
BaseType_t xReturn;
__CPROVER_assume( xReturn == pdFALSE || xReturn == pdTRUE );
return xReturn;
}
void harness()
{
uint32_t ulIPAddress;
/*
* For this proof, its assumed that the endpoints and interfaces are correctly
* initialised and the pointers are set correctly.
* Assumes one endpoint and interface is present.
*/
pxNetworkEndPoints = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxNetworkEndPoints != NULL );
/* Interface init. */
pxNetworkEndPoints->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) );
__CPROVER_assume( pxNetworkEndPoints->pxNetworkInterface != NULL );
if( nondet_bool() )
{
pxNetworkEndPoints->pxNext = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxNetworkEndPoints->pxNext != NULL );
pxNetworkEndPoints->pxNext->pxNext = NULL;
pxNetworkEndPoints->pxNext->pxNetworkInterface = pxNetworkEndPoints->pxNetworkInterface;
}
else
{
pxNetworkEndPoints->pxNext = NULL;
}
pxNetworkEndPoints->pxNetworkInterface->pfOutput = &NetworkInterfaceOutputFunction_Stub;
/* No assumption is added for pfOutput as its pointed to a static object/memory location. */
FreeRTOS_OutputARPRequest( ulIPAddress );
}
@@ -0,0 +1,29 @@
This is the memory safety proof for FreeRTOS_OutputARPRequest.
This proof is a work-in-progress. Proof assumptions are described in
the harness. The proof also assumes the following functions are
memory safe and have no side effects relevant to the memory safety of
this function:
* xNetworkInterfaceOutput
This proof checks FreeRTOS_OutputARPRequest in multiple configuration:
* The config_CBMC_PROOF_ASSUMPTION_HOLDS_no_packet_bytes proof
guarantees that for a buffer allocated to xDataLength,
the code executed by the FreeRTOS_OutputARPRequest function
call of FreeRTOS_ARP.c is memory safe.
* If the ipconfigETHERNET_MINIMUM_PACKET_BYTES is set and the
buffer allocated by pxGetNetworkBufferWithDescriptor allocates
a buffer of at least ipconfigETHERNET_MINIMUM_PACKET_BYTES,
the config_CBMC_PROOF_ASSUMPTION_HOLDS_Packet_bytes proof
guarantees that the code executed by the
FreeRTOS_OutputARPRequest function call
of FreeRTOS_ARP.c is memory safe.
* The third configuration in the subdirectory
config_CBMC_PROOF_ASSUMPTION_DOES_NOT_HOLD demonstrates
that the code is not memory safe, if the allocation
code violates our assumption.
* All proofs mock the pxGetNetworkBufferWithDescriptor
function for modelling the assumptions about the
buffer management layer.
@@ -0,0 +1,16 @@
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "queue.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOSIPConfig.h"
#include "FreeRTOS_ARP.h"
void FreeRTOS_PrintARPCache( void );
void harness()
{
FreeRTOS_PrintARPCache();
}
@@ -0,0 +1,18 @@
{
"ENTRY": "FreeRTOS_PrintARPCache",
"CBMCFLAGS":
[
"--unwind 7",
"--nondet-static"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto"
],
"DEF":
[
"ipconfigARP_CACHE_ENTRIES=6",
"ipconfigHAS_PRINTF=1"
]
}
@@ -0,0 +1,4 @@
FreeRTOS_PrintARPCache_harness.c is memory safe,
assuming vLoggingPrintf is correct and memory safe.
FreeRTOS_PrintARPCache does not use multiple configurations.
@@ -0,0 +1,51 @@
{
"ENTRY": "OutputARPRequest",
"MINIMUM_PACKET_BYTES": 50,
"CBMCFLAGS":
[
"--unwind {MINIMUM_PACKET_BYTES}",
"--unwindset xNetworkBuffersInitialise.0:3,xNetworkBuffersInitialise.1:3,vListInsert.0:3,pxGetNetworkBufferWithDescriptor.0:3,pxGetNetworkBufferWithDescriptor.1:3,uxNetworkInterfaceAllocateRAMToBuffers.0:3"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto",
"$(FREERTOS_PLUS_TCP)/source/portable/BufferManagement/BufferAllocation_1.goto",
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto",
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/queue.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/proofs/CBMCStubLibrary/tasksStubs.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto"
],
"DEF":
[
{
"minimal_configuration":
[
"ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS=2",
"configUSE_TRACE_FACILITY=0",
"configGENERATE_RUN_TIME_STATS=0",
"ipconfigUSE_LINKED_RX_MESSAGES=0"
]
},
{
"minimal_configuration_minimal_packet_size":
[
"ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS=2",
"configUSE_TRACE_FACILITY=0",
"configGENERATE_RUN_TIME_STATS=0",
"ipconfigETHERNET_MINIMUM_PACKET_BYTES={MINIMUM_PACKET_BYTES}"
]
},
{
"minimal_configuration_linked_rx_messages":
[
"ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS=2",
"configUSE_TRACE_FACILITY=0",
"configGENERATE_RUN_TIME_STATS=0",
"ipconfigUSE_LINKED_RX_MESSAGES=1"
]
}
]
}
@@ -0,0 +1,123 @@
/* This harness is linked against
* libraries/freertos_plus/standard/freertos_plus_tcp/source/portable/BufferManagement/BufferAllocation_1.goto
*/
#include <stdint.h>
#include <stdio.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_ARP.h"
#include "FreeRTOS_UDP_IP.h"
#include "FreeRTOS_DHCP.h"
#if ( ipconfigUSE_LLMNR == 1 )
#include "FreeRTOS_DNS.h"
#endif /* ipconfigUSE_LLMNR */
#include "NetworkInterface.h"
#include "NetworkBufferManagement.h"
size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
{
/*
* In the case of buffer allocation scheme 1 the network buffers are
* fixed size and its asserted in xNetworkBuffersInitialise call that the
* buffer is at least ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER bytes
*
* Refer:
* configASSERT( ( uxMaxNetworkInterfaceAllocatedSizeBytes >= ( ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ) ) );
*
*/
size_t xAllocSize = ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER;
for( int x = 0; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ )
{
NetworkBufferDescriptor_t * current = &pxNetworkBuffers[ x ];
current->pucEthernetBuffer = malloc( xAllocSize );
__CPROVER_assume( current->pucEthernetBuffer != NULL );
current->xDataLength = sizeof( ARPPacket_t );
}
return xAllocSize;
}
/* The code expects that the Semaphore creation relying on pvPortMalloc
* is successful. This is checked by an assert statement, that gets
* triggered when the allocation fails. Nevertheless, the code is perfectly
* guarded against a failing Semaphore allocation. To make the assert pass,
* it is assumed for now, that pvPortMalloc doesn't fail. Using a model allowing
* failures of the allocation might be possible
* after removing the assert in l.105 of BufferAllocation_1.c, from a memory
* safety point of view. */
void * pvPortMalloc( size_t xWantedSize )
{
void * ptr = malloc( xWantedSize );
__CPROVER_assume( ptr != NULL );
return ptr;
}
/*
* This function is implemented by a third party.
* After looking through a couple of samples in the demos folder, it seems
* like the only shared contract is that you want to add the if statement
* for releasing the buffer to the end. Apart from that, it is up to the vendor,
* how to write this code out to the network.
*/
BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDescriptor,
NetworkBufferDescriptor_t * const pxNetworkBuffer,
BaseType_t xReleaseAfterSend )
{
__CPROVER_assert( pxDescriptor != NULL, "The network interface cannot be NULL." );
__CPROVER_assert( pxNetworkBuffer != NULL, "The network buffer descriptor cannot be NULL." );
__CPROVER_assert( pxNetworkBuffer->pucEthernetBuffer != NULL, "The ethernet buffer cannot be NULL." );
if( xReleaseAfterSend != pdFALSE )
{
vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
}
}
BaseType_t xIsCallingFromIPTask( void )
{
BaseType_t xReturn;
__CPROVER_assume( xReturn == pdFALSE || xReturn == pdTRUE );
return xReturn;
}
void harness()
{
BaseType_t xRes = xNetworkBuffersInitialise();
/*
* For this proof, its assumed that the endpoints and interfaces are correctly
* initialised and the pointers are set correctly.
* Assumes one endpoint and interface is present.
*/
pxNetworkEndPoints = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxNetworkEndPoints != NULL );
pxNetworkEndPoints->pxNext = NULL;
/* Interface init. */
pxNetworkEndPoints->pxNetworkInterface = ( NetworkInterface_t * ) malloc( sizeof( NetworkInterface_t ) );
__CPROVER_assume( pxNetworkEndPoints->pxNetworkInterface != NULL );
pxNetworkEndPoints->pxNetworkInterface->pxNext = NULL;
pxNetworkEndPoints->pxNetworkInterface->pfOutput = NetworkInterfaceOutputFunction_Stub;
/* No assumption is added for pfOutput as its pointed to a static object/memory location. */
if( xRes == pdPASS )
{
uint32_t ulIPAddress;
FreeRTOS_OutputARPRequest( ulIPAddress );
}
}
@@ -0,0 +1,27 @@
This is the memory safety proof for ```FreeRTOS_OutputARPRequest```
method combined with the BufferAllocation_1.c allocation strategy.
This proof is a work-in-progress. Proof assumptions are described in
the harness. The proof also assumes the following functions are
memory safe and have no side effects relevant to the memory safety of
this function:
* vPortEnterCritical
* vPortExitCritical
* vPortGenerateSimulatedInterrupt
* vAssertCalled
* xTaskGetSchedulerState
* pvTaskIncrementMutexHeldCount
* xTaskRemoveFromEventList
* xTaskPriorityDisinherit
This proof checks ```FreeRTOS_OutputARPRequest``` in multiple configurations.
All assume the memory safety of uxNetworkInterfaceAllocateRAMToBuffers.
* The ```config_minimal_configuration``` proof sets
```ipconfigUSE_LINKED_RX_MESSAGES=0```.
* The ```config_minimal_configuration_linked_rx_messages``` proof sets
```ipconfigUSE_LINKED_RX_MESSAGES=1```.
* The ```minimal_configuration_minimal_packet_size``` proof sets
```ipconfigETHERNET_MINIMUM_PACKET_BYTES``` to 50.
All harnesses include the queue.c file, but test only for the happy path.
@@ -0,0 +1,52 @@
{
"ENTRY": "OutputARPRequest",
"MINIMUM_PACKET_BYTES": 50,
"CBMCFLAGS":
[
"--unwind {MINIMUM_PACKET_BYTES}",
"--unwindset xNetworkBuffersInitialise.0:3,xNetworkBuffersInitialise.1:3,vListInsert.0:3,pxGetNetworkBufferWithDescriptor.0:3,pxGetNetworkBufferWithDescriptor.1:3,uxNetworkInterfaceAllocateRAMToBuffers.0:3"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto",
"$(FREERTOS_PLUS_TCP)/source/portable/BufferManagement/BufferAllocation_2.goto",
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto",
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/queue.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/proofs/CBMCStubLibrary/tasksStubs.goto"
],
"DEF":
[
{
"minimal_configuration":
[
"ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS=2",
"configUSE_TRACE_FACILITY=0",
"configGENERATE_RUN_TIME_STATS=0",
"ipconfigUSE_LINKED_RX_MESSAGES=0"
]
},
{
"minimal_configuration_minimal_packet_size":
[
"ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS=2",
"configUSE_TRACE_FACILITY=0",
"configGENERATE_RUN_TIME_STATS=0",
"ipconfigETHERNET_MINIMUM_PACKET_BYTES={MINIMUM_PACKET_BYTES}",
"ipconfigUSE_TCP=1"
]
},
{
"minimal_configuration_linked_rx_messages":
[
"ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS=2",
"configUSE_TRACE_FACILITY=0",
"configGENERATE_RUN_TIME_STATS=0",
"ipconfigUSE_LINKED_RX_MESSAGES=1"
]
}
]
}
@@ -0,0 +1,94 @@
/* This harness is linked against
* libraries/freertos_plus/standard/freertos_plus_tcp/source/portable/BufferManagement/BufferAllocation_2.goto
*/
#include <stdint.h>
#include <stdio.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_ARP.h"
#include "FreeRTOS_UDP_IP.h"
#include "FreeRTOS_DHCP.h"
#if ( ipconfigUSE_LLMNR == 1 )
#include "FreeRTOS_DNS.h"
#endif /* ipconfigUSE_LLMNR */
#include "NetworkInterface.h"
#include "NetworkBufferManagement.h"
void * pvPortMalloc( size_t xWantedSize )
{
void * ptr = malloc( xWantedSize );
__CPROVER_assume( ptr != NULL );
return ptr;
}
void vPortFree( void * pv )
{
free( pv );
}
/*
* This function function writes a buffer to the network. We stub it
* out here, and assume it has no side effects relevant to memory safety.
*/
BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDescriptor,
NetworkBufferDescriptor_t * const pxNetworkBuffer,
BaseType_t xReleaseAfterSend )
{
__CPROVER_assert( pxDescriptor != NULL, "The network interface cannot be NULL." );
__CPROVER_assert( pxNetworkBuffer != NULL, "The network buffer descriptor cannot be NULL." );
__CPROVER_assert( pxNetworkBuffer->pucEthernetBuffer != NULL, "The ethernet buffer cannot be NULL." );
if( xReleaseAfterSend != pdFALSE )
{
vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
}
}
BaseType_t xIsCallingFromIPTask( void )
{
BaseType_t xReturn;
__CPROVER_assume( xReturn == pdFALSE || xReturn == pdTRUE );
return xReturn;
}
void harness()
{
BaseType_t xRes = xNetworkBuffersInitialise();
/*
* For this proof, its assumed that the endpoints and interfaces are correctly
* initialised and the pointers are set correctly.
* Assumes one endpoint and interface is present.
*/
pxNetworkEndPoints = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxNetworkEndPoints != NULL );
pxNetworkEndPoints->pxNext = NULL;
/* Interface init. */
pxNetworkEndPoints->pxNetworkInterface = ( NetworkInterface_t * ) malloc( sizeof( NetworkInterface_t ) );
__CPROVER_assume( pxNetworkEndPoints->pxNetworkInterface != NULL );
pxNetworkEndPoints->pxNetworkInterface->pxNext = NULL;
pxNetworkEndPoints->pxNetworkInterface->pfOutput = NetworkInterfaceOutputFunction_Stub;
/* No assumption is added for pfOutput as its pointed to a static object/memory location. */
if( xRes == pdPASS )
{
uint32_t ulIPAddress;
FreeRTOS_OutputARPRequest( ulIPAddress );
}
}
@@ -0,0 +1,49 @@
This is the memory safety proof for FreeRTOS_OutputARPRequest
method combined with the BufferAllocation_2.c allocation strategy.
This proof is a work-in-progress. Proof assumptions are described in
the harness. The proof also assumes the following functions are
memory safe and have no side effects relevant to the memory safety of
this function:
* vPortEnterCritical
* vPortExitCritical
* vPortGenerateSimulatedInterrupt
* vAssertCalled
* xTaskGetSchedulerState
* pvTaskIncrementMutexHeldCount
* xTaskRemoveFromEventList
* xTaskPriorityDisinherit
* pvPortMalloc
* pvPortFree
* xNetworkInterfaceOutput
* uxNetworkInterfaceAllocateRAMToBuffers
This proof disables the tracing library in the header.
This proof checks FreeRTOS_OutputARPRequest in multiple configuration:
* The proof in the directory config_minimal_configuration guarantees
that the implementation and interaction between
FreeRTOS_OutputARPRequest and
FreeRTOS-Plus-TCP/source/portable/BufferManagement/BufferAllocation_2.c
are memory save. This proof depends entirely of the implementation
correctness of uxNetworkInterfaceAllocateRAMToBuffers.
* The proof in directory minimal_configuration_minimal_packet_size
guarantees that using
FreeRTOS-Plus-TCP/source/portable/BufferManagement/BufferAllocation_2.c
along with the ipconfigETHERNET_MINIMUM_PACKET_BYTES is memory save
as long as TCP is enabled ( ipconfigUSE_TCP 1 ) and
ipconfigETHERNET_MINIMUM_PACKET_BYTES < sizeof( TCPPacket_t ).
* The directory minimal_configuration_minimal_packet_size_no_tcp
reminds that ipconfigETHERNET_MINIMUM_PACKET_BYTES must not be used
if TCP is disabled ( ipconfigUSE_TCP 1 ) along with the
FreeRTOS-Plus-TCP/source/portable/BufferManagement/BufferAllocation_2.c
allocator.
* The proof in directory
config_minimal_configuration_linked_rx_messages guarantees that the
ipconfigUSE_LINKED_RX_MESSAGES define does not interfere with the
memory safety claim.
All harnesses include the queue.c file, but test only for the happy path.
@@ -0,0 +1,24 @@
{
"ENTRY": "ulARPRemoveCacheEntryByMac",
"NUMBER_OF_CACHE_ENTRIES":6,
"CBMCFLAGS":
[
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto"
],
"INSTFLAGS":
[
],
"DEF":
[
"ipconfigUSE_ARP_REMOVE_ENTRY=1",
"ipconfigARP_CACHE_ENTRIES={NUMBER_OF_CACHE_ENTRIES}"
],
"INC":
[
"$(FREERTOS_PLUS_TCP)/test/cbmc/include"
]
}
@@ -0,0 +1,20 @@
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_ARP.h"
void harness()
{
const MACAddress_t xMACAddress;
/* The pointer passed to ulARPRemoveCacheEntryByMac cannot be NULL
* (see the API definition). */
ulARPRemoveCacheEntryByMac( &xMACAddress );
}
@@ -0,0 +1,17 @@
{
"ENTRY": "xCheckRequiresARPResolution",
"CBMCFLAGS":
[
"--unwind 1",
"--unwindset memcmp.0:10"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto"
],
"DEF":
[
]
}
@@ -0,0 +1,118 @@
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "queue.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_ARP.h"
#include "FreeRTOS_Routing.h"
/* CBMC includes. */
#include "cbmc.h"
/* Global variables. */
BaseType_t xIsIPv6;
/* Abstraction of xIsIPInARPCache. */
BaseType_t xIsIPInARPCache( uint32_t ulAddressToLookup )
{
BaseType_t xReturn;
__CPROVER_assume( ( xReturn == pdTRUE ) || ( xReturn == pdFALSE ) );
return xReturn;
}
/* Function uxIPHeaderSizePacket is proven to be correct separately.*/
size_t uxIPHeaderSizePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer )
{
size_t xReturn = ipSIZE_OF_IPv4_HEADER;
__CPROVER_assert( __CPROVER_r_ok( pxNetworkBuffer, sizeof( NetworkBufferDescriptor_t ) ), "pxNetworkBuffer must be readable" );
__CPROVER_assert( __CPROVER_r_ok( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength ), "pxNetworkBuffer;s buffer must be readable" );
if( xIsIPv6 )
{
xReturn = ipSIZE_OF_IPv6_HEADER;
}
return xReturn;
}
/* Abstraction of FreeRTOS_OutputARPRequest_Multi. */
void FreeRTOS_OutputARPRequest_Multi( NetworkEndPoint_t * pxEndPoint,
uint32_t ulIPAddress )
{
}
/* Abstraction of xIPv6_GetIPType. */
IPv6_Type_t xIPv6_GetIPType( const IPv6_Address_t * pxAddress )
{
IPv6_Type_t eType;
__CPROVER_assert( __CPROVER_r_ok( pxAddress, sizeof( IPv6_Address_t ) ), "pxAddress must be readable" );
return eType;
}
/* Abstraction of eNDGetCacheEntry. */
eResolutionLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress,
MACAddress_t * const pxMACAddress,
struct xNetworkEndPoint ** ppxEndPoint )
{
eResolutionLookupResult_t xReturn;
__CPROVER_assert( __CPROVER_r_ok( pxIPAddress, sizeof( IPv6_Address_t ) ), "pxIPAddress must be readable" );
__CPROVER_assert( __CPROVER_w_ok( pxMACAddress, sizeof( MACAddress_t ) ), "pxMACAddress must be writeable" );
return xReturn;
}
/* Abstraction of pxGetNetworkBufferWithDescriptor. */
NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes,
TickType_t xBlockTimeTicks )
{
NetworkBufferDescriptor_t * pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) safeMalloc( sizeof( NetworkBufferDescriptor_t ) );
return pxNetworkBuffer;
}
/* Abstraction of vNDSendNeighbourSolicitation. */
void vNDSendNeighbourSolicitation( NetworkBufferDescriptor_t * pxNetworkBuffer,
const IPv6_Address_t * pxIPAddress )
{
__CPROVER_assert( __CPROVER_r_ok( pxNetworkBuffer, sizeof( NetworkBufferDescriptor_t ) ), "pxNetworkBuffer must be readable" );
__CPROVER_assert( __CPROVER_r_ok( pxIPAddress, sizeof( IPv6_Address_t ) ), "pxIPAddress must be readable" );
}
void harness()
{
size_t xBufferLength;
NetworkBufferDescriptor_t * pxNetworkBuffer;
IPPacket_t * pxIPPacket;
IPHeader_t * pxIPHeader;
/* Make sure buffer size is enough, xCheckRequiresARPResolution is only called for
* IPv4 packets hence the minimum size should be sizeof( IPPacket_t ) */
__CPROVER_assume( ( xBufferLength >= sizeof( IPPacket_t ) ) && ( xBufferLength < ipconfigNETWORK_MTU ) );
pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) safeMalloc( sizeof( NetworkBufferDescriptor_t ) );
__CPROVER_assume( pxNetworkBuffer != NULL );
pxNetworkBuffer->xDataLength = xBufferLength;
pxNetworkBuffer->pucEthernetBuffer = safeMalloc( xBufferLength );
__CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL );
/* Its asserted in the code that xCheckRequiresARPResolution is only called on IPv4 frame types */
/* See assertion: configASSERT( ( pxIPPacket->xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE ) || ( pxIPPacket->xEthernetHeader.usFrameType == ipARP_FRAME_TYPE ) );
* in xCheckRequiresARPResolution() */
pxIPPacket = ( ( const IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer );
pxIPHeader = &( pxIPPacket->xIPHeader );
__CPROVER_assume( pxIPPacket->xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE );
pxNetworkBuffer->pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxNetworkBuffer->pxEndPoint != NULL );
( void ) xCheckRequiresARPResolution( pxNetworkBuffer );
}