first commit
This commit is contained in:
commit
92cbe97616
1978 files changed
+1688498
No files matched your search
+30
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"ENTRY": "prvPacketBuffer_to_NetworkBuffer",
|
||||
"CBMCFLAGS":
|
||||
[
|
||||
"--unwind 1",
|
||||
"--nondet-static"
|
||||
],
|
||||
"INSTFLAGS":
|
||||
[
|
||||
],
|
||||
"OBJS":
|
||||
[
|
||||
"$(ENTRY)_harness.goto",
|
||||
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto",
|
||||
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto"
|
||||
],
|
||||
"DEF":
|
||||
[
|
||||
"FREERTOS_TCP_ENABLE_VERIFICATION",
|
||||
"ipconfigUSE_TCP=1"
|
||||
],
|
||||
"OPT":
|
||||
[
|
||||
"--export-file-local-symbols"
|
||||
],
|
||||
"INC":
|
||||
[
|
||||
"$(FREERTOS_PLUS_TCP)/test/cbmc/include"
|
||||
]
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
/* CBMC includes. */
|
||||
#include "cbmc.h"
|
||||
|
||||
NetworkBufferDescriptor_t * __CPROVER_file_local_FreeRTOS_IP_Utils_c_prvPacketBuffer_to_NetworkBuffer( const void * pvBuffer,
|
||||
size_t uxOffset );
|
||||
|
||||
void harness()
|
||||
{
|
||||
size_t uxBufferLength;
|
||||
size_t uxOffset;
|
||||
NetworkBufferDescriptor_t * pxNetworkBuffer;
|
||||
|
||||
__CPROVER_assume( ( uxBufferLength > ipBUFFER_PADDING ) && ( uxBufferLength < ipBUFFER_PADDING + ipconfigNETWORK_MTU ) );
|
||||
__CPROVER_assume( uxOffset <= uxBufferLength - ipBUFFER_PADDING );
|
||||
|
||||
pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) safeMalloc( sizeof( NetworkBufferDescriptor_t ) );
|
||||
__CPROVER_assume( pxNetworkBuffer != NULL );
|
||||
|
||||
pxNetworkBuffer->pucEthernetBuffer = safeMalloc( uxBufferLength );
|
||||
__CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL );
|
||||
|
||||
( void ) __CPROVER_file_local_FreeRTOS_IP_Utils_c_prvPacketBuffer_to_NetworkBuffer( &( pxNetworkBuffer->pucEthernetBuffer[ ipBUFFER_PADDING + uxOffset ] ), uxOffset );
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"ENTRY": "pxDuplicateNetworkBufferWithDescriptor",
|
||||
"CBMCFLAGS":
|
||||
[
|
||||
"--unwind 1",
|
||||
"--nondet-static"
|
||||
],
|
||||
"INSTFLAGS":
|
||||
[
|
||||
],
|
||||
"OBJS":
|
||||
[
|
||||
"$(ENTRY)_harness.goto",
|
||||
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto",
|
||||
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto"
|
||||
],
|
||||
"DEF":
|
||||
[
|
||||
"FREERTOS_TCP_ENABLE_VERIFICATION",
|
||||
"ipconfigUSE_TCP=1"
|
||||
],
|
||||
"INC":
|
||||
[
|
||||
"$(FREERTOS_PLUS_TCP)/test/cbmc/include"
|
||||
]
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
/* CBMC includes. */
|
||||
#include "cbmc.h"
|
||||
|
||||
/* Abstraction of pxGetNetworkBufferWithDescriptor. */
|
||||
NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes,
|
||||
TickType_t xBlockTimeTicks )
|
||||
{
|
||||
NetworkBufferDescriptor_t * pxNetworkBuffer;
|
||||
|
||||
pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) safeMalloc( sizeof( NetworkBufferDescriptor_t ) );
|
||||
|
||||
if( pxNetworkBuffer )
|
||||
{
|
||||
pxNetworkBuffer->pucEthernetBuffer = safeMalloc( xRequestedSizeBytes );
|
||||
__CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL );
|
||||
|
||||
pxNetworkBuffer->xDataLength = xRequestedSizeBytes;
|
||||
}
|
||||
|
||||
return pxNetworkBuffer;
|
||||
}
|
||||
|
||||
/* Abstraction of uxIPHeaderSizePacket. This function is proven separately. */
|
||||
size_t uxIPHeaderSizePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer )
|
||||
{
|
||||
size_t xReturn;
|
||||
|
||||
__CPROVER_assert( pxNetworkBuffer != NULL, "pxNetworkBuffer should not be NULL" );
|
||||
__CPROVER_assume( ( xReturn == ipSIZE_OF_IPv4_HEADER ) || ( xReturn == ipSIZE_OF_IPv6_HEADER ) );
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
void harness()
|
||||
{
|
||||
size_t uxBufferLength;
|
||||
size_t uxNewLength;
|
||||
NetworkBufferDescriptor_t * pxNetworkBuffer;
|
||||
|
||||
__CPROVER_assume( uxBufferLength < ipconfigNETWORK_MTU );
|
||||
__CPROVER_assume( uxNewLength < ipconfigNETWORK_MTU );
|
||||
|
||||
pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) safeMalloc( sizeof( NetworkBufferDescriptor_t ) );
|
||||
__CPROVER_assume( pxNetworkBuffer != NULL );
|
||||
|
||||
pxNetworkBuffer->pucEthernetBuffer = safeMalloc( uxBufferLength );
|
||||
__CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL );
|
||||
|
||||
/* The data length of buffer must be set correctly in buffer management. */
|
||||
pxNetworkBuffer->xDataLength = uxBufferLength;
|
||||
|
||||
( void ) pxDuplicateNetworkBufferWithDescriptor( pxNetworkBuffer, uxNewLength );
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"ENTRY": "pxUDPPayloadBuffer_to_NetworkBuffer",
|
||||
"CBMCFLAGS":
|
||||
[
|
||||
"--unwind 1",
|
||||
"--nondet-static"
|
||||
],
|
||||
"INSTFLAGS":
|
||||
[
|
||||
],
|
||||
"OBJS":
|
||||
[
|
||||
"$(ENTRY)_harness.goto",
|
||||
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto",
|
||||
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto"
|
||||
],
|
||||
"DEF":
|
||||
[
|
||||
"FREERTOS_TCP_ENABLE_VERIFICATION",
|
||||
"ipconfigBUFFER_PADDING=14"
|
||||
],
|
||||
"OPT":
|
||||
[
|
||||
"--export-file-local-symbols"
|
||||
],
|
||||
"INC":
|
||||
[
|
||||
"$(FREERTOS_PLUS_TCP)/test/cbmc/include"
|
||||
]
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
/* CBMC includes. */
|
||||
#include "cbmc.h"
|
||||
|
||||
/* Global variables. */
|
||||
BaseType_t xIsIPv6;
|
||||
|
||||
/* Abstraction of prvPacketBuffer_to_NetworkBuffer. This function is proven separately. */
|
||||
NetworkBufferDescriptor_t * __CPROVER_file_local_FreeRTOS_IP_Utils_c_prvPacketBuffer_to_NetworkBuffer( const void * pvBuffer,
|
||||
size_t uxOffset )
|
||||
{
|
||||
__CPROVER_assert( pvBuffer != NULL, "pvBuffer shouldn't be NULL" );
|
||||
}
|
||||
|
||||
void harness()
|
||||
{
|
||||
size_t uxBufferLength;
|
||||
NetworkBufferDescriptor_t * pxNetworkBuffer;
|
||||
uint8_t * pucIPType;
|
||||
void * pvBuffer;
|
||||
|
||||
xIsIPv6 = nondet_bool();
|
||||
|
||||
/* Reserve the buffer with ipconfigBUFFER_PADDING to store IP type. */
|
||||
if( xIsIPv6 )
|
||||
{
|
||||
__CPROVER_assume( uxBufferLength > sizeof( UDPPacket_IPv6_t ) + ipconfigBUFFER_PADDING );
|
||||
}
|
||||
else
|
||||
{
|
||||
__CPROVER_assume( uxBufferLength > sizeof( UDPPacket_t ) + ipconfigBUFFER_PADDING );
|
||||
}
|
||||
|
||||
__CPROVER_assume( uxBufferLength < ipconfigNETWORK_MTU );
|
||||
|
||||
pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) safeMalloc( sizeof( NetworkBufferDescriptor_t ) );
|
||||
__CPROVER_assume( pxNetworkBuffer != NULL );
|
||||
|
||||
pxNetworkBuffer->pucEthernetBuffer = safeMalloc( uxBufferLength );
|
||||
__CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL );
|
||||
|
||||
if( xIsIPv6 )
|
||||
{
|
||||
pucIPType = &pxNetworkBuffer->pucEthernetBuffer[ ipconfigBUFFER_PADDING + sizeof( UDPPacket_IPv6_t ) - ipUDP_PAYLOAD_IP_TYPE_OFFSET ];
|
||||
pvBuffer = &pxNetworkBuffer->pucEthernetBuffer[ ipconfigBUFFER_PADDING + sizeof( UDPPacket_IPv6_t ) ];
|
||||
}
|
||||
else
|
||||
{
|
||||
pucIPType = &pxNetworkBuffer->pucEthernetBuffer[ ipconfigBUFFER_PADDING + sizeof( UDPPacket_t ) - ipUDP_PAYLOAD_IP_TYPE_OFFSET ];
|
||||
pvBuffer = &pxNetworkBuffer->pucEthernetBuffer[ ipconfigBUFFER_PADDING + sizeof( UDPPacket_t ) ];
|
||||
}
|
||||
|
||||
__CPROVER_assume( ( ( *pucIPType ) & 0xf0 == ipTYPE_IPv4 ) || ( ( *pucIPType ) & 0xf0 == ipTYPE_IPv6 ) );
|
||||
|
||||
( void ) pxUDPPayloadBuffer_to_NetworkBuffer( pvBuffer );
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"ENTRY": "usGenerateProtocolChecksum",
|
||||
"CBMCFLAGS":
|
||||
[
|
||||
"--unwind 1",
|
||||
"--nondet-static"
|
||||
],
|
||||
"INSTFLAGS":
|
||||
[
|
||||
"--remove-function-body prvChecksumIPv6Checks"
|
||||
],
|
||||
"OBJS":
|
||||
[
|
||||
"$(ENTRY)_harness.goto",
|
||||
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto",
|
||||
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto",
|
||||
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IPv4_Utils.goto"
|
||||
],
|
||||
"DEF":
|
||||
[
|
||||
"FREERTOS_TCP_ENABLE_VERIFICATION",
|
||||
"ipconfigUSE_TCP=1"
|
||||
],
|
||||
"INC":
|
||||
[
|
||||
"$(FREERTOS_PLUS_TCP)/test/cbmc/include"
|
||||
]
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
/* CBMC includes. */
|
||||
#include "cbmc.h"
|
||||
|
||||
/* Function usGenerateChecksum is proven to be correct separately.
|
||||
* Check if input buffer is readable. */
|
||||
uint16_t usGenerateChecksum( uint16_t usSum,
|
||||
const uint8_t * pucNextData,
|
||||
size_t uxByteCount )
|
||||
{
|
||||
__CPROVER_assert( __CPROVER_r_ok( pucNextData, uxByteCount ), "pucNextData should be readable." );
|
||||
}
|
||||
|
||||
void harness()
|
||||
{
|
||||
size_t uxBufferLength;
|
||||
uint8_t * pucEthernetBuffer;
|
||||
BaseType_t xOutgoingPacket;
|
||||
EthernetHeader_t * pxEthernetHeader;
|
||||
IPPacket_t * pxIPPacket;
|
||||
uint16_t usHeaderLength;
|
||||
|
||||
/* The buffer must contain enough buffer size for ethernet header + IPv4 header and less than MTU size. */
|
||||
__CPROVER_assume( uxBufferLength >= ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv4_HEADER + sizeof( ProtocolHeaders_t ) && uxBufferLength < ipconfigNETWORK_MTU );
|
||||
pucEthernetBuffer = safeMalloc( uxBufferLength );
|
||||
__CPROVER_assume( pucEthernetBuffer != NULL );
|
||||
|
||||
/* This test case verifies IPv4 only. */
|
||||
pxIPPacket = ( IPPacket_t * ) pucEthernetBuffer;
|
||||
__CPROVER_assume( pxIPPacket->xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE );
|
||||
|
||||
/* Make sure the length of buffer is enough for protocol header.
|
||||
* CBMC checks union structure before accessing it, so we need to make sure the buffer size is enough for whole union structure. */
|
||||
usHeaderLength = pxIPPacket->xIPHeader.ucVersionHeaderLength & ( uint8_t ) 0x0FU;
|
||||
usHeaderLength = usHeaderLength << 2;
|
||||
__CPROVER_assume( uxBufferLength >= ipSIZE_OF_ETH_HEADER + usHeaderLength + sizeof( ProtocolHeaders_t ) );
|
||||
/* IPv4 header length is checked in prvProcessIPPacket. */
|
||||
__CPROVER_assume( ( usHeaderLength <= ( uxBufferLength - ipSIZE_OF_ETH_HEADER ) ) && ( usHeaderLength >= ipSIZE_OF_IPv4_HEADER ) );
|
||||
|
||||
/* Set to valid input. */
|
||||
__CPROVER_assume( ( xOutgoingPacket == pdTRUE ) || ( xOutgoingPacket == pdFALSE ) );
|
||||
|
||||
( void ) usGenerateProtocolChecksum( pucEthernetBuffer, uxBufferLength, xOutgoingPacket );
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"ENTRY": "usGenerateProtocolChecksum_IPv6",
|
||||
"MAX_EXT_HEADER_NUM": 21,
|
||||
"CBMCFLAGS":
|
||||
[
|
||||
"--unwind 1",
|
||||
"--nondet-static",
|
||||
"--unwindset usGetExtensionHeaderLength.3:{MAX_EXT_HEADER_NUM}",
|
||||
"--unwindset prvPrepareExtensionHeaders.0:{MAX_EXT_HEADER_NUM}"
|
||||
],
|
||||
"INSTFLAGS":
|
||||
[
|
||||
"--remove-function-body prvChecksumIPv4Checks"
|
||||
],
|
||||
"OBJS":
|
||||
[
|
||||
"$(ENTRY)_harness.goto",
|
||||
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto",
|
||||
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto",
|
||||
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IPv6_Utils.goto"
|
||||
],
|
||||
"DEF":
|
||||
[
|
||||
"FREERTOS_TCP_ENABLE_VERIFICATION",
|
||||
"ipconfigUSE_TCP=1",
|
||||
"ipconfigNETWORK_MTU=200",
|
||||
"ipconfigTCP_MSS=586",
|
||||
"ipconfigUSE_DHCP=0"
|
||||
],
|
||||
"INC":
|
||||
[
|
||||
"$(FREERTOS_PLUS_TCP)/test/cbmc/include"
|
||||
]
|
||||
}
|
||||
+166
@@ -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"
|
||||
|
||||
/* CBMC includes. */
|
||||
#include "cbmc.h"
|
||||
|
||||
/* Function usGenerateChecksum is proven to be correct separately.
|
||||
* Check if input buffer is readable. */
|
||||
uint16_t usGenerateChecksum( uint16_t usSum,
|
||||
const uint8_t * pucNextData,
|
||||
size_t uxByteCount )
|
||||
{
|
||||
__CPROVER_assert( __CPROVER_r_ok( pucNextData, uxByteCount ), "pucNextData should be readable." );
|
||||
}
|
||||
|
||||
/* Check if input is a valid extension header ID. */
|
||||
BaseType_t xIsExtensionHeader( uint8_t ucCurrentHeader )
|
||||
{
|
||||
BaseType_t xReturn = pdFALSE;
|
||||
|
||||
switch( ucCurrentHeader )
|
||||
{
|
||||
case ipIPv6_EXT_HEADER_HOP_BY_HOP:
|
||||
case ipIPv6_EXT_HEADER_DESTINATION_OPTIONS:
|
||||
case ipIPv6_EXT_HEADER_ROUTING_HEADER:
|
||||
case ipIPv6_EXT_HEADER_FRAGMENT_HEADER:
|
||||
case ipIPv6_EXT_HEADER_AUTHEN_HEADER:
|
||||
case ipIPv6_EXT_HEADER_SECURE_PAYLOAD:
|
||||
case ipIPv6_EXT_HEADER_MOBILITY_HEADER:
|
||||
xReturn = pdTRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
/* Abstraction of xGetExtensionOrder. To ensure the result of prepared extension headers is same. */
|
||||
BaseType_t xGetExtensionOrder( uint8_t ucProtocol,
|
||||
uint8_t ucNextHeader )
|
||||
{
|
||||
BaseType_t xReturn = -1;
|
||||
|
||||
if( xIsExtensionHeader( ucProtocol ) != pdFALSE )
|
||||
{
|
||||
xReturn = 1;
|
||||
}
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
/* To guarantee the remaining buffer size greater than protocol header size to avoid dereference failure. */
|
||||
void prvPrepareExtensionHeaders( uint8_t * pucEthernetBuffer,
|
||||
size_t uxBufferLength )
|
||||
{
|
||||
size_t uxMinReminingSize = sizeof( ProtocolHeaders_t );
|
||||
const IPPacket_IPv6_t * pxIPPacket_IPv6 = ( const IPPacket_IPv6_t * ) pucEthernetBuffer;
|
||||
uint8_t ucNextHeader = 0U;
|
||||
size_t uxIndex = ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER;
|
||||
size_t uxHopSize = 0U;
|
||||
size_t uxReturn = uxBufferLength;
|
||||
uint8_t ucCurrentHeader;
|
||||
|
||||
pxIPPacket_IPv6 = ( ( const IPPacket_IPv6_t * ) pucEthernetBuffer );
|
||||
ucCurrentHeader = pxIPPacket_IPv6->xIPHeader.ucNextHeader;
|
||||
|
||||
/* Check if packet has extension header. */
|
||||
if( xIsExtensionHeader( ucCurrentHeader ) != pdFALSE )
|
||||
{
|
||||
while( ( uxIndex + 8U ) < uxBufferLength )
|
||||
{
|
||||
ucNextHeader = pucEthernetBuffer[ uxIndex ];
|
||||
|
||||
/* Read the length expressed in number of octets. */
|
||||
uxHopSize = ( size_t ) pucEthernetBuffer[ uxIndex + 1U ];
|
||||
/* And multiply by 8 and add the minimum size of 8. */
|
||||
uxHopSize = ( uxHopSize * 8U ) + 8U;
|
||||
|
||||
if( ( uxIndex + uxHopSize ) >= uxBufferLength )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
uxIndex = uxIndex + uxHopSize;
|
||||
|
||||
if( ( ucNextHeader == ipPROTOCOL_TCP ) ||
|
||||
( ucNextHeader == ipPROTOCOL_UDP ) ||
|
||||
( ucNextHeader == ipPROTOCOL_ICMP_IPv6 ) )
|
||||
{
|
||||
/* The remaining size of buffer after extension header must be greater than size of protocol header. */
|
||||
__CPROVER_assume( uxBufferLength - uxIndex >= sizeof( ProtocolHeaders_t ) );
|
||||
break;
|
||||
}
|
||||
|
||||
if( xIsExtensionHeader( ucNextHeader ) == pdFALSE )
|
||||
{
|
||||
/* The remaining size of buffer after extension header must be greater than size of protocol header. */
|
||||
__CPROVER_assume( uxBufferLength - uxIndex >= sizeof( ProtocolHeaders_t ) );
|
||||
break;
|
||||
}
|
||||
|
||||
ucCurrentHeader = ucNextHeader;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No extension headers. */
|
||||
/* The remaining size of buffer after extension header must be greater than size of protocol header. */
|
||||
__CPROVER_assume( uxBufferLength - uxIndex >= sizeof( ProtocolHeaders_t ) );
|
||||
}
|
||||
}
|
||||
|
||||
void harness()
|
||||
{
|
||||
size_t uxBufferLength;
|
||||
uint8_t * pucEthernetBuffer;
|
||||
BaseType_t xOutgoingPacket;
|
||||
IPPacket_IPv6_t * pxIPPacket;
|
||||
|
||||
/* The buffer must contain enough buffer size for ethernet header + IPv6 header and less than MTU size. */
|
||||
__CPROVER_assume( ( uxBufferLength >= ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + sizeof( ProtocolHeaders_t ) ) && ( uxBufferLength < ipconfigNETWORK_MTU ) );
|
||||
pucEthernetBuffer = safeMalloc( uxBufferLength );
|
||||
__CPROVER_assume( pucEthernetBuffer != NULL );
|
||||
__CPROVER_havoc_slice( pucEthernetBuffer, uxBufferLength );
|
||||
|
||||
/* This test case verifies IPv6 only. */
|
||||
pxIPPacket = ( IPPacket_IPv6_t * ) pucEthernetBuffer;
|
||||
__CPROVER_assume( pxIPPacket->xEthernetHeader.usFrameType == ipIPv6_FRAME_TYPE );
|
||||
|
||||
/* Check if buffer size is enough for extension headers + protocol headers. */
|
||||
prvPrepareExtensionHeaders( pucEthernetBuffer, uxBufferLength );
|
||||
|
||||
( void ) usGenerateProtocolChecksum( pucEthernetBuffer, uxBufferLength, xOutgoingPacket );
|
||||
}
|
||||
Reference in new issue
Block a user