add initial Setup

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
niklasschoeningandClaude Opus 5.5 committed 2026-10-16 18:25:42 +02:00
commit bdb5db2009
1955 files changed
+1004711

No files matched your search

@@ -0,0 +1,28 @@
{
"ENTRY": "prvHandleListen",
"CBMCFLAGS":
[
"--unwind 1",
"--nondet-static"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_State_Handling.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_State_Handling_IPv4.goto"
],
"DEF":
[
"FREERTOS_TCP_ENABLE_VERIFICATION",
"ipconfigNETWORK_MTU=586"
],
"INSTFLAGS":
[
],
"INC":
[
"$(FREERTOS_PLUS_TCP)/test/cbmc/include"
]
}
@@ -0,0 +1,140 @@
/*
* 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_TCP_State_Handling.h"
/* CBMC includes. */
#include "cbmc.h"
#include "../../utility/memory_assignments.c"
/* Abstraction of uxIPHeaderSizePacket. This test case only uses to test IPv4 path. */
size_t uxIPHeaderSizePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer )
{
return ipSIZE_OF_IPv4_HEADER;
}
/* Abstraction of FreeRTOS_socket. Return NULL or valid socket handler. */
Socket_t FreeRTOS_socket( BaseType_t xDomain,
BaseType_t xType,
BaseType_t xProtocol )
{
return ensure_FreeRTOS_Socket_t_is_allocated();
}
BaseType_t vSocketBind( FreeRTOS_Socket_t * pxSocket,
struct freertos_sockaddr * pxBindAddress,
size_t uxAddressLength,
BaseType_t xInternal )
{
BaseType_t xRet;
__CPROVER_assert( pxSocket != NULL,
"FreeRTOS precondition: pxSocket != NULL" );
__CPROVER_assert( pxBindAddress != NULL,
"FreeRTOS precondition: pxBindAddress != NULL" );
return xRet;
}
void * vSocketClose( FreeRTOS_Socket_t * pxSocket )
{
__CPROVER_assert( pxSocket != NULL, "Closing socket cannot be NULL" );
return NULL;
}
BaseType_t prvTCPSendReset( NetworkBufferDescriptor_t * pxNetworkBuffer )
{
BaseType_t xReturn;
__CPROVER_assume( ( xReturn == pdTRUE ) || ( xReturn == pdFALSE ) );
return xReturn;
}
void vTCPStateChange( FreeRTOS_Socket_t * pxSocket,
enum eTCP_STATE eTCPState )
{
}
BaseType_t prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket )
{
BaseType_t xReturn;
__CPROVER_assume( ( xReturn == pdTRUE ) || ( xReturn == pdFALSE ) );
return xReturn;
}
void prvSocketSetMSS( FreeRTOS_Socket_t * pxSocket )
{
__CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" );
}
size_t FreeRTOS_GetLocalAddress( ConstSocket_t xSocket,
struct freertos_sockaddr * pxAddress )
{
size_t uxReturn;
__CPROVER_assert( pxAddress != NULL, "pxAddress cannot be NULL" );
return uxReturn;
}
void harness()
{
size_t xDataLength;
FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated();
NetworkBufferDescriptor_t * pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) safeMalloc( sizeof( FreeRTOS_Socket_t ) );
/* The length of buffer must be larger than or equal to TCP minimum requirement. */
__CPROVER_assume( xDataLength >= sizeof( TCPPacket_t ) && xDataLength <= ipconfigNETWORK_MTU );
/* Socket is guaranteed to be non-NULL. */
__CPROVER_assume( pxSocket != NULL );
/* Network buffer is guaranteed to be non-NULL. */
__CPROVER_assume( pxNetworkBuffer != NULL );
pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) safeMalloc( xDataLength );
/* Network buffer is guaranteed to be non-NULL. */
__CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL );
pxNetworkBuffer->xDataLength = xDataLength;
pxNetworkBuffer->pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
prvHandleListen( pxSocket, pxNetworkBuffer );
}
@@ -0,0 +1,30 @@
{
"ENTRY": "prvHandleListen_IPv6",
"IPV6_ADDRESS_SIZE": 17,
"CBMCFLAGS":
[
"--unwind 1",
"--unwindset memcmp.0:{IPV6_ADDRESS_SIZE}",
"--nondet-static"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_State_Handling.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_State_Handling_IPv6.goto"
],
"DEF":
[
"FREERTOS_TCP_ENABLE_VERIFICATION",
"ipconfigNETWORK_MTU=586"
],
"INSTFLAGS":
[
],
"INC":
[
"$(FREERTOS_PLUS_TCP)/test/cbmc/include"
]
}
@@ -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_TCP_State_Handling.h"
/* CBMC includes. */
#include "cbmc.h"
#include "../../utility/memory_assignments.c"
/* Abstraction of uxIPHeaderSizePacket. This test case only uses to test IPv4 path. */
size_t uxIPHeaderSizePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer )
{
return ipSIZE_OF_IPv6_HEADER;
}
/* Abstraction of FreeRTOS_socket. Return NULL or valid socket handler. */
Socket_t FreeRTOS_socket( BaseType_t xDomain,
BaseType_t xType,
BaseType_t xProtocol )
{
return ensure_FreeRTOS_Socket_t_is_allocated();
}
BaseType_t vSocketBind( FreeRTOS_Socket_t * pxSocket,
struct freertos_sockaddr * pxBindAddress,
size_t uxAddressLength,
BaseType_t xInternal )
{
BaseType_t xRet;
__CPROVER_assert( pxSocket != NULL,
"FreeRTOS precondition: pxSocket != NULL" );
__CPROVER_assert( pxBindAddress != NULL,
"FreeRTOS precondition: pxBindAddress != NULL" );
return xRet;
}
void * vSocketClose( FreeRTOS_Socket_t * pxSocket )
{
__CPROVER_assert( pxSocket != NULL, "Closing socket cannot be NULL" );
return NULL;
}
void prvSocketSetMSS( FreeRTOS_Socket_t * pxSocket )
{
__CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" );
}
BaseType_t prvTCPSendReset( NetworkBufferDescriptor_t * pxNetworkBuffer )
{
BaseType_t xReturn;
__CPROVER_assume( ( xReturn == pdTRUE ) || ( xReturn == pdFALSE ) );
return xReturn;
}
void vTCPStateChange( FreeRTOS_Socket_t * pxSocket,
enum eTCP_STATE eTCPState )
{
}
BaseType_t prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket )
{
BaseType_t xReturn;
__CPROVER_assume( ( xReturn == pdTRUE ) || ( xReturn == pdFALSE ) );
return xReturn;
}
size_t FreeRTOS_GetLocalAddress( ConstSocket_t xSocket,
struct freertos_sockaddr * pxAddress )
{
size_t uxReturn;
__CPROVER_assert( pxAddress != NULL, "pxAddress cannot be NULL" );
return uxReturn;
}
void harness()
{
size_t xDataLength;
FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated();
NetworkBufferDescriptor_t * pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) safeMalloc( sizeof( FreeRTOS_Socket_t ) );
/* The length of buffer must be larger than or equal to TCP minimum requirement. */
__CPROVER_assume( xDataLength >= sizeof( TCPPacket_IPv6_t ) && xDataLength <= ipconfigNETWORK_MTU );
/* Socket is guaranteed to be non-NULL. */
__CPROVER_assume( pxSocket != NULL );
/* Network buffer is guaranteed to be non-NULL. */
__CPROVER_assume( pxNetworkBuffer != NULL );
pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) safeMalloc( xDataLength );
/* Network buffer is guaranteed to be non-NULL. */
__CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL );
pxNetworkBuffer->xDataLength = xDataLength;
pxNetworkBuffer->pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
/* There must be endpoint for network buffer or assertion triggered in prvHandleListen_IPV6. */
__CPROVER_assume( pxNetworkBuffer->pxEndPoint != NULL );
prvHandleListen( pxSocket, pxNetworkBuffer );
}
@@ -0,0 +1,18 @@
{
"ENTRY": "SendData",
"CBMCFLAGS":
[
"--unwind 1",
"--nondet-static"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto"
],
"INC":
[
"$(FREERTOS_PLUS_TCP)/test/cbmc/include"
]
}
@@ -0,0 +1,144 @@
/*
* 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_TCP_IP.h"
/* CBMC includes. */
#include "cbmc.h"
/****************************************************************
* Declare the IP Header Size external to the harness so it can be
* accessed by uxIPHeaderSizePacket.
****************************************************************/
size_t uxIPHeaderSizePacket_uxResult;
size_t uxIPHeaderSizePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer )
{
__CPROVER_assert( pxNetworkBuffer != NULL, "pxNetworkBuffer should not be NULL" );
__CPROVER_assert( pxNetworkBuffer->pucEthernetBuffer != NULL, "pucEthernetBuffer should not be NULL" );
return uxIPHeaderSizePacket_uxResult;
}
void prvTCPReturnPacket( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t * pxDescriptor,
uint32_t ulLen,
BaseType_t xReleaseAfterSend )
{
__CPROVER_assert( pxSocket != NULL, "pxSocket should not be NULL" );
__CPROVER_assert( pxDescriptor != NULL, "pxDescriptor should not be NULL" );
__CPROVER_assert( pxDescriptor->pucEthernetBuffer != NULL, "pucEthernetBuffer should not be NULL" );
}
void prvTCPReturnPacket_IPV4( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t * pxDescriptor,
uint32_t ulLen,
BaseType_t xReleaseAfterSend )
{
__CPROVER_assert( pxSocket != NULL, "pxSocket should not be NULL" );
__CPROVER_assert( pxDescriptor != NULL, "pxDescriptor should not be NULL" );
__CPROVER_assert( pxDescriptor->pucEthernetBuffer != NULL, "pucEthernetBuffer should not be NULL" );
}
/* Memory assignment for FreeRTOS_Socket_t */
FreeRTOS_Socket_t * ensure_FreeRTOS_Socket_t_is_allocated()
{
size_t buf_size; /* Give buffer_size an unconstrained value */
FreeRTOS_Socket_t * pxSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) );
__CPROVER_assume( pxSocket != NULL );
pxSocket->u.xTCP.rxStream = safeMalloc( sizeof( StreamBuffer_t ) );
pxSocket->u.xTCP.txStream = safeMalloc( sizeof( StreamBuffer_t ) );
pxSocket->u.xTCP.pxPeerSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) );
pxSocket->pxEndPoint = safeMalloc( sizeof( NetworkEndPoint_t ) );
pxSocket->u.xTCP.pxAckMessage = safeMalloc( sizeof( NetworkBufferDescriptor_t ) );
if( pxSocket->u.xTCP.pxAckMessage != NULL )
{
__CPROVER_assume( ( buf_size > ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + sizeof( TCPHeader_t ) ) ) && ( buf_size < ipconfigNETWORK_MTU ) );
pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer = safeMalloc( buf_size );
__CPROVER_assume( pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer != NULL );
}
return pxSocket;
}
/*
* In this function, it only allocates network buffer by harness.
*/
void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer )
{
__CPROVER_assert( pxNetworkBuffer != NULL,
"Precondition: pxNetworkBuffer != NULL" );
if( pxNetworkBuffer->pucEthernetBuffer != NULL )
{
free( pxNetworkBuffer->pucEthernetBuffer );
}
free( pxNetworkBuffer );
}
void harness()
{
FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated();
NetworkBufferDescriptor_t * pxNetworkBuffer;
uint32_t ulReceiveLength;
BaseType_t xByteCount;
size_t buf_size; /* Give buffer_size an unconstrained value */
/* The code does not expect pxSocket/pxNetworkBuffer to be equal to NULL. */
pxNetworkBuffer = safeMalloc( sizeof( NetworkBufferDescriptor_t ) );
__CPROVER_assume( pxSocket != NULL );
__CPROVER_assume( pxNetworkBuffer != NULL );
if( nondet_bool() )
{
uxIPHeaderSizePacket_uxResult = ipSIZE_OF_IPv6_HEADER;
}
else
{
uxIPHeaderSizePacket_uxResult = ipSIZE_OF_IPv4_HEADER;
}
__CPROVER_assume( ( buf_size > ( ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket_uxResult + sizeof( TCPHeader_t ) ) ) && ( buf_size < ipconfigNETWORK_MTU ) );
pxNetworkBuffer->pucEthernetBuffer = safeMalloc( buf_size );
__CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL );
__CPROVER_havoc_object( pxNetworkBuffer->pucEthernetBuffer );
prvSendData( pxSocket, &pxNetworkBuffer, ulReceiveLength, xByteCount );
}
@@ -0,0 +1,68 @@
#
# 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": "TCPHandleState",
"TX_DRIVER":1,
"RX_MESSAGES":1,
"CBMCFLAGS":
[
"--unwind 1",
"--unwindset prvWinScaleFactor.0:2",
"--nondet-static"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_IP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_State_Handling.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Reception.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)/test/cbmc/stubs/cbmc.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto"
],
"DEF":
[
"ipconfigUSE_TCP=1",
"ipconfigZERO_COPY_TX_DRIVER={TX_DRIVER}",
"ipconfigUSE_LINKED_RX_MESSAGES={RX_MESSAGES}",
"FREERTOS_TCP_ENABLE_VERIFICATION",
"ipconfigNETWORK_MTU=586"
],
"INSTFLAGS":
[
],
"INC":
[
"$(FREERTOS_PLUS_TCP)/test/cbmc/include"
]
}
@@ -0,0 +1,22 @@
This is the memory safety proof for prvTCPHandleState.
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:
* prvTCPPrepareSend (proved independently)
* prvTCPReturnPacket (proved independently)
* lTCPAddRxdata
* lTCPWindowRxCheck
* lTCPWindowTxAdd
* ulTCPWindowTxAck
* vTCPWindowInit
* xTCPWindowRxEmpty
* xTCPWindowTxDone
* uxStreamBufferGet
* vReleaseNetworkBufferAndDescriptor
* vSocketWakeUpUser
* xTaskGetTickCount
@@ -0,0 +1,289 @@
/*
* 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_TCP_IP.h"
/* CBMC includes. */
#include "cbmc.h"
extern FreeRTOS_Socket_t * xSocketToListen;
/* Abstraction of xTaskGetCurrentTaskHandle */
TaskHandle_t xTaskGetCurrentTaskHandle( void )
{
static int xIsInit = 0;
static TaskHandle_t pxCurrentTCB;
TaskHandle_t xRandomTaskHandle; /* not initialized on purpose */
if( xIsInit == 0 )
{
pxCurrentTCB = xRandomTaskHandle;
xIsInit = 1;
}
return pxCurrentTCB;
}
/* This proof assumes that prvTCPPrepareSend and prvTCPReturnPacket are correct.
* These functions are proved to be correct separately. */
BaseType_t publicTCPHandleState( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t ** ppxNetworkBuffer );
void * vSocketClose( FreeRTOS_Socket_t * pxSocket )
{
__CPROVER_assert( pxSocket != NULL, "Closing socket cannot be NULL." );
return NULL;
}
void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket )
{
__CPROVER_assert( pxSocket != NULL, "Closing socket cannot be NULL." );
return NULL;
}
/* Memory assignment for FreeRTOS_Socket_t */
FreeRTOS_Socket_t * ensure_FreeRTOS_Socket_t_is_allocated()
{
size_t buf_size; /* Give buffer_size an unconstrained value */
FreeRTOS_Socket_t * pxSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) );
__CPROVER_assume( pxSocket != NULL );
pxSocket->u.xTCP.rxStream = safeMalloc( sizeof( StreamBuffer_t ) );
pxSocket->u.xTCP.txStream = safeMalloc( sizeof( StreamBuffer_t ) );
pxSocket->u.xTCP.pxPeerSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) );
pxSocket->pxEndPoint = safeMalloc( sizeof( NetworkEndPoint_t ) );
pxSocket->u.xTCP.pxAckMessage = safeMalloc( sizeof( NetworkBufferDescriptor_t ) );
if( pxSocket->u.xTCP.pxAckMessage != NULL )
{
__CPROVER_assume( ( buf_size > ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + sizeof( TCPHeader_t ) ) ) && ( buf_size < ipconfigNETWORK_MTU ) );
pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer = safeMalloc( buf_size );
__CPROVER_assume( pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer != NULL );
}
return pxSocket;
}
/* lTCPAddRxdata is proven separately. */
int32_t lTCPAddRxdata( FreeRTOS_Socket_t * pxSocket,
size_t uxOffset,
const uint8_t * pcData,
uint32_t ulByteCount )
{
return nondet_int32();
}
/* prvSendData is proven separately. */
BaseType_t prvSendData( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t ** ppxNetworkBuffer,
uint32_t ulReceiveLength,
BaseType_t xByteCount )
{
__CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" );
__CPROVER_assert( *ppxNetworkBuffer != NULL, "*ppxNetworkBuffer cannot be NULL" );
return nondet_BaseType();
}
/* prvTCPPrepareSend is proven separately. */
int32_t prvTCPPrepareSend( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t ** ppxNetworkBuffer,
UBaseType_t uxOptionsLength )
{
__CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" );
__CPROVER_assert( *ppxNetworkBuffer != NULL, "*ppxNetworkBuffer cannot be NULL" );
return nondet_int32();
}
/* Mock all window APIs */
int32_t lTCPWindowRxCheck( TCPWindow_t * pxWindow,
uint32_t ulSequenceNumber,
uint32_t ulLength,
uint32_t ulSpace,
uint32_t * pulSkipCount )
{
__CPROVER_assert( pxWindow != NULL, "pxWindow cannot be NULL" );
__CPROVER_assert( __CPROVER_r_ok( pxWindow, sizeof( TCPWindow_t ) ), "pxWindow must be readable" );
*pulSkipCount = nondet_uint32();
return nondet_int32();
}
uint32_t ulTCPWindowTxAck( TCPWindow_t * pxWindow,
uint32_t ulSequenceNumber )
{
__CPROVER_assert( pxWindow != NULL, "pxWindow cannot be NULL" );
__CPROVER_assert( __CPROVER_r_ok( pxWindow, sizeof( TCPWindow_t ) ), "pxWindow must be readable" );
return nondet_uint32();
}
void vTCPWindowInit( TCPWindow_t * pxWindow,
uint32_t ulAckNumber,
uint32_t ulSequenceNumber,
uint32_t ulMSS )
{
__CPROVER_assert( pxWindow != NULL, "pxWindow cannot be NULL" );
__CPROVER_assert( __CPROVER_r_ok( pxWindow, sizeof( TCPWindow_t ) ), "pxWindow must be readable" );
}
BaseType_t xTCPWindowRxEmpty( const TCPWindow_t * pxWindow )
{
__CPROVER_assert( pxWindow != NULL, "pxWindow cannot be NULL" );
__CPROVER_assert( __CPROVER_r_ok( pxWindow, sizeof( TCPWindow_t ) ), "pxWindow must be readable" );
return nondet_BaseType();
}
BaseType_t xTCPWindowTxDone( const TCPWindow_t * pxWindow )
{
__CPROVER_assert( pxWindow != NULL, "pxWindow cannot be NULL" );
__CPROVER_assert( __CPROVER_r_ok( pxWindow, sizeof( TCPWindow_t ) ), "pxWindow must be readable" );
return nondet_BaseType();
}
/* Mock all stream buffer APIs */
size_t uxStreamBufferGet( StreamBuffer_t * const pxBuffer,
size_t uxOffset,
uint8_t * const pucData,
size_t uxMaxCount,
BaseType_t xPeek )
{
__CPROVER_assert( pxBuffer != NULL, "pxBuffer cannot be NULL" );
return nondet_sizet();
}
size_t uxStreamBufferGetSpace( const StreamBuffer_t * const pxBuffer )
{
__CPROVER_assert( pxBuffer != NULL, "pxBuffer cannot be NULL" );
return nondet_sizet();
}
/* Mock all transmission APIs. */
UBaseType_t prvSetOptions( FreeRTOS_Socket_t * pxSocket,
const NetworkBufferDescriptor_t * pxNetworkBuffer )
{
__CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" );
__CPROVER_assert( pxNetworkBuffer != NULL, "pxNetworkBuffer cannot be NULL" );
return nondet_ubasetype();
}
UBaseType_t prvSetSynAckOptions( FreeRTOS_Socket_t * pxSocket,
TCPHeader_t * pxTCPHeader )
{
__CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" );
__CPROVER_assert( pxTCPHeader != NULL, "pxTCPHeader cannot be NULL" );
return nondet_ubasetype();
}
void prvTCPAddTxData( FreeRTOS_Socket_t * pxSocket )
{
__CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" );
}
BaseType_t prvTCPSendReset( NetworkBufferDescriptor_t * pxNetworkBuffer )
{
__CPROVER_assert( pxNetworkBuffer != NULL, "pxNetworkBuffer cannot be NULL" );
return nondet_BaseType();
}
const char * FreeRTOS_inet_ntop( BaseType_t xAddressFamily,
const void * pvSource,
char * pcDestination,
socklen_t uxSize )
{
__CPROVER_assert( __CPROVER_r_ok( pcDestination, uxSize ), "input buffer must be available" );
__CPROVER_assert( ( xAddressFamily == FREERTOS_AF_INET6 && __CPROVER_r_ok( pvSource, 16 ) ) ||
( xAddressFamily == FREERTOS_AF_INET && __CPROVER_r_ok( pvSource, 4 ) ),
"input address must be available" );
}
void harness()
{
FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated();
__CPROVER_assume( pxSocket != NULL );
/* ucOptionLength is the number of valid bytes in ulOptionsData[].
* ulOptionsData[] is initialized as uint32_t ulOptionsData[ipSIZE_TCP_OPTIONS/sizeof(uint32_t)].
* This assumption is required for a memcpy function that copies uxOptionsLength
* data from pxTCPHeader->ucOptdata to pxTCPWindow->ulOptionsData.*/
__CPROVER_assume( pxSocket->u.xTCP.xTCPWindow.ucOptionLength == sizeof( uint32_t ) * ipSIZE_TCP_OPTIONS / sizeof( uint32_t ) );
/* uxRxWinSize is initialized as size_t. This assumption is required to terminate `while(uxWinSize > 0xfffful)` loop.*/
__CPROVER_assume( pxSocket->u.xTCP.uxRxWinSize >= 0 && pxSocket->u.xTCP.uxRxWinSize <= sizeof( size_t ) );
/* uxRxWinSize is initialized as uint16_t. This assumption is required to terminate `while(uxWinSize > 0xfffful)` loop.*/
__CPROVER_assume( pxSocket->u.xTCP.usMSS == sizeof( uint16_t ) );
/* ucPeerWinScaleFactor is limited in range [0,14]. */
__CPROVER_assume( pxSocket->u.xTCP.ucPeerWinScaleFactor <= tcpTCP_OPT_WSOPT_MAXIMUM_VALUE );
if( xIsCallingFromIPTask() == pdFALSE )
{
__CPROVER_assume( pxSocket->u.xTCP.bits.bPassQueued == pdFALSE_UNSIGNED );
__CPROVER_assume( pxSocket->u.xTCP.bits.bPassAccept == pdFALSE_UNSIGNED );
}
NetworkBufferDescriptor_t * pxNetworkBuffer = safeMalloc( sizeof( NetworkBufferDescriptor_t ) );
__CPROVER_assume( pxNetworkBuffer != NULL );
FreeRTOS_Socket_t xSck;
xSocketToListen = &xSck;
/* Call to init the socket list. */
vListInitialise( &xBoundTCPSocketsList );
/* Allocates min. buffer size required for the proof */
pxNetworkBuffer->pucEthernetBuffer = safeMalloc( sizeof( TCPPacket_t ) + uxIPHeaderSizeSocket( pxSocket ) );
__CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL );
pxNetworkBuffer->xDataLength = sizeof( TCPPacket_t ) + uxIPHeaderSizeSocket( pxSocket );
if( pxSocket->u.xTCP.bits.bReuseSocket == pdFALSE )
{
/* Make sure we have parent socket if reuse is set to FALSE to avoid assertion in vTCPStateChange(). */
__CPROVER_assume( pxSocket->u.xTCP.pxPeerSocket != NULL );
}
publicTCPHandleState( pxSocket, &pxNetworkBuffer );
}
@@ -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": "TCPPrepareSend",
"CBMCFLAGS":
[
"--unwind 1",
"--unwindset __CPROVER_file_local_FreeRTOS_TCP_IP_c_vTCPRemoveTCPChild.0:1",
"--nondet-static"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_IP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto"
],
"OPT":
[
"--export-file-local-symbols"
],
"DEF":
[
"FREERTOS_TCP_ENABLE_VERIFICATION",
"CBMC_REQUIRE_NETWORKBUFFER_ETHERNETBUFFER_NONNULL"
],
"INC":
[
"$(FREERTOS_PLUS_TCP)/test/cbmc/include"
]
}
@@ -0,0 +1,15 @@
This is the memory safety proof for prvTCPPrepareSend.
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:
* ulTCPWindowTxGet
* xTCPWindowTxDone
* xTaskGetTickCount
* uxStreamBufferGet
* vReleaseNetworkBufferAndDescriptor
* vSocketWakeUpUser
@@ -0,0 +1,166 @@
/*
* 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_TCP_IP.h"
#include "FreeRTOS_Stream_Buffer.h"
/* CBMC includes. */
#include "cbmc.h"
/* This proof assumes that pxGetNetworkBufferWithDescriptor is implemented correctly. */
int32_t publicTCPPrepareSend( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t ** ppxNetworkBuffer,
UBaseType_t uxOptionsLength );
/* Memory assignment for FreeRTOS_Socket_t */
FreeRTOS_Socket_t * ensure_FreeRTOS_Socket_t_is_allocated()
{
size_t buf_size; /* Give buffer_size an unconstrained value */
FreeRTOS_Socket_t * pxSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) + sizeof( IPTCPSocket_t ) );
__CPROVER_assume( pxSocket != NULL );
pxSocket->u.xTCP.rxStream = safeMalloc( sizeof( StreamBuffer_t ) );
pxSocket->u.xTCP.txStream = safeMalloc( sizeof( StreamBuffer_t ) );
pxSocket->u.xTCP.pxPeerSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) );
pxSocket->pxEndPoint = safeMalloc( sizeof( NetworkEndPoint_t ) );
pxSocket->u.xTCP.pxAckMessage = safeMalloc( sizeof( NetworkBufferDescriptor_t ) );
if( pxSocket->u.xTCP.pxAckMessage != NULL )
{
__CPROVER_assume( ( buf_size > ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + sizeof( TCPHeader_t ) ) ) && ( buf_size < ipconfigNETWORK_MTU ) );
pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer = safeMalloc( buf_size );
__CPROVER_assume( pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer != NULL );
}
return pxSocket;
}
/* Get rid of configASSERT in FreeRTOS_TCP_IP.c */
BaseType_t xIsCallingFromIPTask( void )
{
return pdTRUE;
}
/* Mock FreeRTOS_TCP_State_Handling.h APIs */
BaseType_t prvTCPSocketIsActive( eIPTCPState_t eStatus )
{
return nondet_BaseType();
}
/* Mock FreeRTOS_TCP_WIN.h APIs */
BaseType_t xTCPWindowTxDone( const TCPWindow_t * pxWindow )
{
__CPROVER_assert( pxWindow != NULL, "pxWindow cannot be NULL" );
return nondet_uint32();
}
uint32_t ulTCPWindowTxGet( TCPWindow_t * pxWindow,
uint32_t ulWindowSize,
int32_t * plPosition )
{
uint32_t ulReturn = nondet_uint32();
__CPROVER_assert( pxWindow != NULL, "pxWindow cannot be NULL" );
__CPROVER_assert( plPosition != NULL, "plPosition cannot be NULL" );
/* This function returns the data length of next sending window, which is never larger than network MTU. */
__CPROVER_assume( ulReturn < ipconfigNETWORK_MTU );
return ulReturn;
}
/* Mock FreeRTOS_Stream_Buffers.h APIs */
size_t uxStreamBufferDistance( const StreamBuffer_t * const pxBuffer,
size_t uxLower,
size_t uxUpper )
{
__CPROVER_assert( pxBuffer != NULL, "pxBuffer cannot be NULL" );
return nondet_sizet();
}
size_t uxStreamBufferGet( StreamBuffer_t * const pxBuffer,
size_t uxOffset,
uint8_t * const pucData,
size_t uxMaxCount,
BaseType_t xPeek )
{
__CPROVER_assert( pxBuffer != NULL, "pxBuffer cannot be NULL" );
return nondet_sizet();
}
void * vSocketClose( FreeRTOS_Socket_t * pxSocket )
{
__CPROVER_assert( pxSocket != NULL, "Closing socket cannot be NULL." );
return NULL;
}
void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket )
{
__CPROVER_assert( pxSocket != NULL, "Closing socket cannot be NULL." );
return NULL;
}
void harness()
{
NetworkBufferDescriptor_t * pxNetworkBuffer;
FreeRTOS_Socket_t * pxSocket;
size_t socketSize = sizeof( FreeRTOS_Socket_t );
/* Allocates min. buffer size required for the proof */
size_t bufferSize;
pxSocket = ensure_FreeRTOS_Socket_t_is_allocated();
__CPROVER_assume( pxSocket != NULL );
if( pxSocket->u.xTCP.bits.bReuseSocket == pdFALSE )
{
/* Make sure we have parent socket if reuse is set to FALSE to avoid assertion in vTCPStateChange(). */
__CPROVER_assume( pxSocket->u.xTCP.pxPeerSocket != NULL );
}
bufferSize = sizeof( TCPPacket_t ) + ipSIZE_OF_IPv6_HEADER;
pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( bufferSize, 0 );
__CPROVER_assume( pxNetworkBuffer != NULL );
__CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL );
/* Call to init the socket list. */
vListInitialise( &xBoundTCPSocketsList );
if( pxSocket )
{
publicTCPPrepareSend( pxSocket, &pxNetworkBuffer, 0 );
}
}
@@ -0,0 +1,60 @@
#
# 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": "TCPReturnPacket",
"RX_MESSAGES":1,
"CBMCFLAGS":
[
"--unwind 1",
"--nondet-static"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Stream_Buffer.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_IP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission_IPv4.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto"
],
"DEF":
[
"ipconfigUSE_LINKED_RX_MESSAGES={RX_MESSAGES}",
"FREERTOS_TCP_ENABLE_VERIFICATION",
"CBMC_REQUIRE_NETWORKBUFFER_ETHERNETBUFFER_NONNULL"
],
"INC":
[
"$(FREERTOS_PLUS_TCP)/test/cbmc/include"
]
}
@@ -0,0 +1,10 @@
This is the memory safety proof for prvTCPReturnPacket.
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:
* usGenerateChecksum
* usGenerateProtocolChecksum
* xNetworkInterfaceOutput
@@ -0,0 +1,260 @@
/*
* 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_ARP.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_TCP_IP.h"
#include "FreeRTOS_TCP_Transmission.h"
/* CBMC includes */
#include "cbmc.h"
/* prvTCPReturnPacket_IPV6 is proven separately. */
void prvTCPReturnPacket_IPV6( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t * pxDescriptor,
uint32_t ulLen,
BaseType_t xReleaseAfterSend )
{
__CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" );
__CPROVER_assert( pxDescriptor != NULL, "pxDescriptor cannot be NULL" );
}
/* Memory assignment for FreeRTOS_Socket_t */
FreeRTOS_Socket_t * ensure_FreeRTOS_Socket_t_is_allocated()
{
size_t buf_size; /* Give buffer_size an unconstrained value */
FreeRTOS_Socket_t * pxSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) + sizeof( IPTCPSocket_t ) );
__CPROVER_assume( pxSocket != NULL );
pxSocket->u.xTCP.rxStream = safeMalloc( sizeof( StreamBuffer_t ) );
pxSocket->u.xTCP.txStream = safeMalloc( sizeof( StreamBuffer_t ) );
pxSocket->u.xTCP.pxPeerSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) );
pxSocket->pxEndPoint = safeMalloc( sizeof( NetworkEndPoint_t ) );
pxSocket->u.xTCP.pxAckMessage = safeMalloc( sizeof( NetworkBufferDescriptor_t ) );
if( pxSocket->u.xTCP.pxAckMessage != NULL )
{
__CPROVER_assume( ( buf_size > ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + sizeof( TCPHeader_t ) ) ) && ( buf_size < ipconfigNETWORK_MTU ) );
pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer = safeMalloc( buf_size );
__CPROVER_assume( pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer != NULL );
}
return pxSocket;
}
/*
* 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 );
}
return 0;
}
/* Abstraction of this functions creates an endpoint and assign it to network interface
* endpoint, real endpoint doesn't matter in this test. */
void prvTCPReturn_SetEndPoint( const FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t * pxNetworkBuffer,
size_t uxIPHeaderSize )
{
NetworkEndPoint_t * pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assert( pxNetworkBuffer != NULL, "The network interface cannot be NULL." );
__CPROVER_assume( pxEndPoint != NULL );
/* Add an interface */
pxEndPoint->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) );
__CPROVER_assume( pxEndPoint->pxNetworkInterface != NULL );
pxEndPoint->pxNetworkInterface->pfOutput = NetworkInterfaceOutputFunction_Stub;
pxNetworkBuffer->pxEndPoint = pxEndPoint;
}
/* Abstraction of pxDuplicateNetworkBufferWithDescriptor*/
NetworkBufferDescriptor_t * pxDuplicateNetworkBufferWithDescriptor( const NetworkBufferDescriptor_t * const pxNetworkBuffer,
size_t xNewLength )
{
NetworkBufferDescriptor_t * pxLocalNetworkBuffer;
EthernetHeader_t * pxHeader;
pxLocalNetworkBuffer = pxGetNetworkBufferWithDescriptor( xNewLength, 0 );
if( pxLocalNetworkBuffer != NULL )
{
/* In this test case, we only focus on IPv4. */
pxHeader = ( ( const EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer );
__CPROVER_assume( pxHeader->usFrameType != ipIPv6_FRAME_TYPE );
/* Add an end point to the network buffer present. Its assumed that the
* network interface layer correctly assigns the end point to the generated buffer. */
pxLocalNetworkBuffer->pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxLocalNetworkBuffer->pxEndPoint != NULL );
pxLocalNetworkBuffer->pxEndPoint->pxNext = NULL;
/* Add an interface */
pxLocalNetworkBuffer->pxEndPoint->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) );
__CPROVER_assume( pxLocalNetworkBuffer->pxEndPoint->pxNetworkInterface != NULL );
pxLocalNetworkBuffer->pxEndPoint->pxNetworkInterface->pfOutput = NetworkInterfaceOutputFunction_Stub;
}
return pxLocalNetworkBuffer;
}
uint16_t usGenerateProtocolChecksum( const uint8_t * const pucEthernetBuffer,
size_t uxBufferLength,
BaseType_t xOutgoingPacket )
{
uint16_t usReturn;
__CPROVER_assert( pucEthernetBuffer != NULL, "The ethernet buffer cannot be NULL" );
__CPROVER_assert( __CPROVER_r_ok( pucEthernetBuffer, uxBufferLength ), "pucEthernetBuffer should be readable." );
return usReturn;
}
uint16_t usGenerateChecksum( uint16_t usSum,
const uint8_t * pucNextData,
size_t uxByteCount )
{
uint16_t usReturn;
__CPROVER_assert( pucNextData != NULL, "The next data pointer cannot be NULL" );
__CPROVER_assert( __CPROVER_r_ok( pucNextData, uxByteCount ), "The pucNextData should be readable." );
return usReturn;
}
/* This function has been tested separately. Therefore, we assume that the implementation is correct. */
eResolutionLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress,
MACAddress_t * const pxMACAddress,
struct xNetworkEndPoint ** ppxEndPoint )
{
/* Assume random ARP lookup result. */
eResolutionLookupResult_t eReturn;
/* Make sure NULL pointers are not passed as arguments. */
__CPROVER_assert( pulIPAddress != NULL, "The pulIPAddress cannot be NULL" );
__CPROVER_assert( pxMACAddress != NULL, "The pxMACAddress cannot be NULL" );
if( eReturn == eResolutionCacheHit )
{
/* If its a cache hit, update ppxEndPoint with a valid endpoint. */
struct xNetworkEndPoint * pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxEndPoint != NULL );
pxEndPoint->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) );
__CPROVER_assume( pxEndPoint->pxNetworkInterface != NULL );
pxEndPoint->pxNetworkInterface->pfOutput = NetworkInterfaceOutputFunction_Stub;
*ppxEndPoint = pxEndPoint;
}
else
{
/* In case of miss there isn't a matching endpoint available. */
*ppxEndPoint = NULL;
}
return eReturn;
}
void harness()
{
FreeRTOS_Socket_t * pxSocket;
NetworkBufferDescriptor_t * pxNetworkBuffer;
BaseType_t xReleaseAfterSend;
uint32_t ulLen;
EthernetHeader_t * pxHeader;
pxSocket = ensure_FreeRTOS_Socket_t_is_allocated();
if( pxSocket != NULL )
{
/* In this test case, we only focus on IPv4. */
__CPROVER_assume( pxSocket->bits.bIsIPv6 == pdFALSE_UNSIGNED );
}
__CPROVER_assume( ( ulLen >= sizeof( TCPPacket_t ) ) && ( ulLen < ipconfigNETWORK_MTU - ipSIZE_OF_ETH_HEADER ) );
pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( ulLen + ipSIZE_OF_ETH_HEADER, 0 );
/* The code does not expect both of these to be equal to NULL at the same time. */
__CPROVER_assume( pxSocket != NULL || pxNetworkBuffer != NULL );
/* ucPeerWinScaleFactor is limited in range [0,14]. */
__CPROVER_assume( pxSocket->u.xTCP.ucMyWinScaleFactor <= tcpTCP_OPT_WSOPT_MAXIMUM_VALUE );
/* If network buffer is properly created. */
if( pxNetworkBuffer != NULL )
{
/* In this test case, we only focus on IPv4. */
pxHeader = ( ( const EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer );
__CPROVER_assume( pxHeader->usFrameType != ipIPv6_FRAME_TYPE );
/* Add an end point to the network buffer present. Its assumed that the
* network interface layer correctly assigns the end point to the generated buffer. */
pxNetworkBuffer->pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
if( pxNetworkBuffer->pxEndPoint != NULL )
{
/* Add an interface */
pxNetworkBuffer->pxEndPoint->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) );
__CPROVER_assume( pxNetworkBuffer->pxEndPoint->pxNetworkInterface != NULL );
pxNetworkBuffer->pxEndPoint->pxNetworkInterface->pfOutput = NetworkInterfaceOutputFunction_Stub;
}
}
/* If not. */
else
{
/* Assume that the length is proper. The length should be between this range. It
* is made so by the functions up the call tree. Essentially, this is equal to a
* TCP packet header with and without TCP options. */
__CPROVER_assume( ( ulLen >= ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ) &&
( ulLen <= ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + 40 /* Maximum option bytes. */ ) );
}
prvTCPReturnPacket( pxSocket, pxNetworkBuffer, ulLen, xReleaseAfterSend );
}
@@ -0,0 +1,32 @@
{
"ENTRY": "TCPReturnPacket_IPv6",
"RX_MESSAGES":1,
"CBMCFLAGS":
[
"--unwind 1",
"--nondet-static"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Stream_Buffer.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_IP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission_IPv6.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto"
],
"DEF":
[
"ipconfigUSE_LINKED_RX_MESSAGES={RX_MESSAGES}",
"FREERTOS_TCP_ENABLE_VERIFICATION",
"CBMC_REQUIRE_NETWORKBUFFER_ETHERNETBUFFER_NONNULL"
],
"INC":
[
"$(FREERTOS_PLUS_TCP)/test/cbmc/include"
]
}
@@ -0,0 +1,239 @@
/*
* 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_TCP_IP.h"
#include "FreeRTOS_TCP_Transmission.h"
#include "FreeRTOS_ND.h"
/* CBMC includes. */
#include "cbmc.h"
/*
* 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 );
}
return 0;
}
/* Memory assignment for FreeRTOS_Socket_t */
FreeRTOS_Socket_t * ensure_FreeRTOS_Socket_t_is_allocated()
{
size_t buf_size; /* Give buffer_size an unconstrained value */
FreeRTOS_Socket_t * pxSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) + sizeof( IPTCPSocket_t ) );
__CPROVER_assume( pxSocket != NULL );
pxSocket->u.xTCP.rxStream = safeMalloc( sizeof( StreamBuffer_t ) );
pxSocket->u.xTCP.txStream = safeMalloc( sizeof( StreamBuffer_t ) );
pxSocket->u.xTCP.pxPeerSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) );
pxSocket->pxEndPoint = safeMalloc( sizeof( NetworkEndPoint_t ) );
pxSocket->u.xTCP.pxAckMessage = safeMalloc( sizeof( NetworkBufferDescriptor_t ) );
if( pxSocket->u.xTCP.pxAckMessage != NULL )
{
__CPROVER_assume( ( buf_size > ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + sizeof( TCPHeader_t ) ) ) && ( buf_size < ipconfigNETWORK_MTU ) );
pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer = safeMalloc( buf_size );
__CPROVER_assume( pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer != NULL );
}
return pxSocket;
}
void prvTCPReturnPacket_IPV4( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t * pxDescriptor,
uint32_t ulLen,
BaseType_t xReleaseAfterSend )
{
__CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" );
__CPROVER_assert( pxDescriptor != NULL, "pxDescriptor cannot be NULL" );
}
/* 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 this functions creates an endpoint and assign it to network interface
* endpoint, real endpoint doesn't matter in this test. */
void prvTCPReturn_SetEndPoint( const FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t * pxNetworkBuffer,
size_t uxIPHeaderSize )
{
NetworkEndPoint_t * pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxEndPoint != NULL );
/* Add an interface */
pxEndPoint->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) );
__CPROVER_assume( pxEndPoint->pxNetworkInterface != NULL );
pxEndPoint->pxNetworkInterface->pfOutput = NetworkInterfaceOutputFunction_Stub;
pxNetworkBuffer->pxEndPoint = pxEndPoint;
}
/* Abstraction of pxDuplicateNetworkBufferWithDescriptor*/
NetworkBufferDescriptor_t * pxDuplicateNetworkBufferWithDescriptor( const NetworkBufferDescriptor_t * const pxNetworkBuffer,
size_t xNewLength )
{
NetworkBufferDescriptor_t * pxLocalNetworkBuffer;
EthernetHeader_t * pxHeader;
pxLocalNetworkBuffer = pxGetNetworkBufferWithDescriptor( xNewLength, 0 );
if( pxLocalNetworkBuffer != NULL )
{
/* In this test case, we only focus on IPv6. */
pxHeader = ( ( const EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer );
__CPROVER_assume( pxHeader->usFrameType == ipIPv6_FRAME_TYPE );
/* Add an end point to the network buffer present. Its assumed that the
* network interface layer correctly assigns the end point to the generated buffer. */
pxLocalNetworkBuffer->pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxLocalNetworkBuffer->pxEndPoint != NULL );
pxLocalNetworkBuffer->pxEndPoint->pxNext = NULL;
/* Add an interface */
pxLocalNetworkBuffer->pxEndPoint->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) );
__CPROVER_assume( pxLocalNetworkBuffer->pxEndPoint->pxNetworkInterface != NULL );
pxLocalNetworkBuffer->pxEndPoint->pxNetworkInterface->pfOutput = NetworkInterfaceOutputFunction_Stub;
}
return pxLocalNetworkBuffer;
}
uint16_t usGenerateProtocolChecksum( const uint8_t * const pucEthernetBuffer,
size_t uxBufferLength,
BaseType_t xOutgoingPacket )
{
uint16_t usReturn;
__CPROVER_assert( pucEthernetBuffer != NULL, "The ethernet buffer cannot be NULL" );
__CPROVER_assert( __CPROVER_r_ok( pucEthernetBuffer, uxBufferLength ), "pucEthernetBuffer should be readable." );
return usReturn;
}
uint16_t usGenerateChecksum( uint16_t usSum,
const uint8_t * pucNextData,
size_t uxByteCount )
{
uint16_t usReturn;
__CPROVER_assert( pucNextData != NULL, "The next data pointer cannot be NULL" );
__CPROVER_assert( __CPROVER_r_ok( pucNextData, uxByteCount ), "The pucNextData should be readable." );
return usReturn;
}
void harness()
{
FreeRTOS_Socket_t * pxSocket;
NetworkBufferDescriptor_t * pxNetworkBuffer;
BaseType_t xReleaseAfterSend;
uint32_t ulLen;
EthernetHeader_t * pxHeader;
pxSocket = ensure_FreeRTOS_Socket_t_is_allocated();
if( pxSocket != NULL )
{
/* In this test case, we only focus on IPv6. */
__CPROVER_assume( pxSocket->bits.bIsIPv6 != pdFALSE_UNSIGNED );
}
__CPROVER_assume( ( ulLen >= sizeof( TCPPacket_IPv6_t ) ) && ( ulLen < ipconfigNETWORK_MTU - ipSIZE_OF_ETH_HEADER ) );
pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( ulLen + ipSIZE_OF_ETH_HEADER, 0 );
/* The code does not expect both of these to be equal to NULL at the same time. */
__CPROVER_assume( pxSocket != NULL || pxNetworkBuffer != NULL );
/* ucPeerWinScaleFactor is limited in range [0,14]. */
__CPROVER_assume( pxSocket->u.xTCP.ucMyWinScaleFactor <= tcpTCP_OPT_WSOPT_MAXIMUM_VALUE );
/* If network buffer is properly created. */
if( pxNetworkBuffer != NULL )
{
/* In this test case, we only focus on IPv6. */
pxHeader = ( ( const EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer );
__CPROVER_assume( pxHeader->usFrameType == ipIPv6_FRAME_TYPE );
/* Add an end point to the network buffer present. Its assumed that the
* network interface layer correctly assigns the end point to the generated buffer. */
pxNetworkBuffer->pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
if( pxNetworkBuffer->pxEndPoint != NULL )
{
/* Add an interface */
pxNetworkBuffer->pxEndPoint->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) );
__CPROVER_assume( pxNetworkBuffer->pxEndPoint->pxNetworkInterface != NULL );
pxNetworkBuffer->pxEndPoint->pxNetworkInterface->pfOutput = NetworkInterfaceOutputFunction_Stub;
}
}
/* If not. */
else
{
/* Assume that the length is proper. The length should be between this range. It
* is made so by the functions up the call tree. Essentially, this is equal to a
* TCP packet header with and without TCP options. */
__CPROVER_assume( ( ulLen >= ipSIZE_OF_IPv6_HEADER + ipSIZE_OF_TCP_HEADER ) &&
( ulLen <= ipSIZE_OF_IPv6_HEADER + ipSIZE_OF_TCP_HEADER + 40 /* Maximum option bytes. */ ) );
}
prvTCPReturnPacket( pxSocket, pxNetworkBuffer, ulLen, xReleaseAfterSend );
}