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,88 @@
/*
* 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"
#include "list.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_DNS.h"
#include "FreeRTOS_IP_Private.h"
#include "cbmc.h"
size_t __CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage( uint8_t * pucUDPPayloadBuffer,
const char * pcHostName,
TickType_t uxIdentifier,
UBaseType_t uxHostType );
void harness()
{
size_t uxExpectedPayloadLength;
TickType_t uxIdentifier;
UBaseType_t uxHostType;
size_t len;
/* Make sure the string has a valid but bounded length */
__CPROVER_assume( len > 0 && len <= MAX_HOSTNAME_LEN );
/* pcHostName is tested to be valid prior */
char * pcHostName = malloc( len );
__CPROVER_assume( pcHostName != NULL );
if( len && pcHostName )
{
/* Make sure the string ends with a NULL, this is expected */
pcHostName[ len - 1 ] = NULL;
}
/* prvCreateDNSMessage() is expected to be called with a ethernet buffer of
* the following size */
uxExpectedPayloadLength = sizeof( DNSMessage_t ) +
strlen( pcHostName ) +
sizeof( uint16_t ) +
sizeof( uint16_t ) + 2U;
/* Add header size */
if( nondet_bool() )
{
uxExpectedPayloadLength += ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + ipSIZE_OF_UDP_HEADER;
}
else
{
uxExpectedPayloadLength += ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_UDP_HEADER;
}
/* pucUDPPayloadBuffer is tested to be valid prior */
uint8_t * pucUDPPayloadBuffer = malloc( uxExpectedPayloadLength );
__CPROVER_assume( pucUDPPayloadBuffer != NULL );
__CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage( pucUDPPayloadBuffer, pcHostName, uxIdentifier, uxHostType );
}
@@ -0,0 +1,29 @@
{
"ENTRY": "CreateDNSMessage",
"MAX_HOSTNAME_LEN": 5,
"HOSTNAME_UNWIND": "__eval {MAX_HOSTNAME_LEN} + 1",
"USE_CACHE": 1,
"CBMCFLAGS":
[
"--unwind 1",
"--unwindset strlen.0:{HOSTNAME_UNWIND}",
"--unwindset strcpy.0:{HOSTNAME_UNWIND}",
"--unwindset __CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage.0:{HOSTNAME_UNWIND}",
"--unwindset __CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage.1:{HOSTNAME_UNWIND}",
"--nondet-static"
],
"OPT":
[
"--export-file-local-symbols"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS.goto"
],
"DEF":
[
"ipconfigUSE_DNS=1",
"MAX_HOSTNAME_LEN={MAX_HOSTNAME_LEN}"
]
}
@@ -0,0 +1,32 @@
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "queue.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_DNS.h"
#include "FreeRTOS_IP_Private.h"
/* CBMC includes. */
#include "cbmc.h"
/* Function DNS_ParseDNSReply is proven to be correct separately. */
uint32_t DNS_ParseDNSReply( uint8_t * pucUDPPayloadBuffer,
size_t uxBufferLength,
struct freertos_addrinfo ** ppxAddressInfo,
BaseType_t xExpected,
uint16_t usPort )
{
__CPROVER_assert( pucUDPPayloadBuffer != NULL, "pucUDPPayloadBuffer cannot be NULL" );
return nondet_uint32();
}
void harness()
{
NetworkBufferDescriptor_t xNetworkBuffer;
xNetworkBuffer.pucEthernetBuffer = malloc( sizeof( UDPPacket_t ) + sizeof( DNSMessage_t ) );
__CPROVER_assume( xNetworkBuffer.pucEthernetBuffer != NULL );
xDNSHandlePacket( &xNetworkBuffer );
}
@@ -0,0 +1,13 @@
{
"ENTRY": "DNShandlePacket",
"CBMCFLAGS": "--unwind 1",
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto"
],
"DEF":
[
]
}
@@ -0,0 +1,142 @@
/*
* 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_DNS.h"
#include "FreeRTOS_DNS_Parser.h"
#include "FreeRTOS_IP_Private.h"
#include "cbmc.h"
const BaseType_t xBufferAllocFixedSize = pdFALSE;
NetworkBufferDescriptor_t xNetworkBuffer;
NetworkBufferDescriptor_t * pxUDPPayloadBuffer_to_NetworkBuffer( const void * pvBuffer )
{
__CPROVER_assert( pvBuffer != NULL, "Precondition: pvBuffer != NULL" );
NetworkBufferDescriptor_t * pxRBuf;
if( nondet_bool() )
{
pxRBuf = NULL;
}
else
{
pxRBuf = &xNetworkBuffer;
}
return pxRBuf;
}
NetworkBufferDescriptor_t * pxResizeNetworkBufferWithDescriptor( NetworkBufferDescriptor_t * pxNetworkBuffer,
size_t xNewSizeBytes )
{
NetworkBufferDescriptor_t * pxRBuf;
__CPROVER_assert( pxNetworkBuffer != NULL, "pxNetworkBuffer: pvBuffer != NULL" );
uint8_t * pucNewBuffer = safeMalloc( xNewSizeBytes );
__CPROVER_assume( pucNewBuffer != NULL );
if( pxNetworkBuffer->pucEthernetBuffer )
{
free( pxNetworkBuffer->pucEthernetBuffer );
}
pxNetworkBuffer->pucEthernetBuffer = pucNewBuffer;
if( nondet_bool() )
{
pxRBuf = NULL;
}
else
{
pxRBuf = pxNetworkBuffer;
}
return pxRBuf;
}
/* prepareReplyDNSMessage is proved separately */
void prepareReplyDNSMessage( NetworkBufferDescriptor_t * pxNetworkBuffer,
BaseType_t lNetLength )
{
__CPROVER_assert( pxNetworkBuffer != NULL, "pxNetworkBuffer: pvBuffer != NULL" );
}
BaseType_t xApplicationDNSQueryHook_Multi( struct xNetworkEndPoint * pxEndPoint,
const char * pcName )
{
BaseType_t xReturn;
__CPROVER_assert( strlen( pcName ) < ipconfigDNS_CACHE_NAME_LENGTH, "The length of domain name must be less than cache size" );
__CPROVER_assume( xReturn == pdFALSE || xReturn == pdTRUE );
return xReturn;
}
/* vReturnEthernetFrame() is proved separately */
void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer,
BaseType_t xReleaseAfterSend )
{
__CPROVER_assert( pxNetworkBuffer != NULL, "xNetworkBuffer != NULL" );
__CPROVER_assert( pxNetworkBuffer->pucEthernetBuffer != NULL, "pxNetworkBuffer->pucEthernetBuffer != NULL" );
__CPROVER_assert( __CPROVER_r_ok( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength ), "Data must be valid" );
}
void harness()
{
uint32_t ulIPAddress;
NetworkEndPoint_t * pxNetworkEndPoint_Temp = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
BaseType_t xDataSize;
__CPROVER_assume( ( xDataSize > 0 ) && ( xDataSize < ( ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ) ) );
xNetworkBuffer.pucEthernetBuffer = safeMalloc( xDataSize );
xNetworkBuffer.xDataLength = xDataSize;
__CPROVER_assume( xNetworkBuffer.pucEthernetBuffer != NULL );
if( nondet_bool() )
{
__CPROVER_assume( pxNetworkEndPoint_Temp != NULL );
xNetworkBuffer.pxEndPoint = pxNetworkEndPoint_Temp;
}
else
{
xNetworkBuffer.pxEndPoint = NULL;
}
DNS_TreatNBNS( xNetworkBuffer.pucEthernetBuffer, xNetworkBuffer.xDataLength, ulIPAddress );
}
@@ -0,0 +1,30 @@
{
"ENTRY": "DNS_TreatNBNS",
"USE_CACHE":1,
"NBNS_NAME_MAX_LENGTH":17,
"DNS_CACHE_NAME_LENGTH": 255,
"CBMCFLAGS":
[
"--unwind 1",
"--unwindset DNS_TreatNBNS.0:{NBNS_NAME_MAX_LENGTH}",
"--unwindset prvFindEntryIndex.0:2",
"--unwindset strcmp.0:{NBNS_NAME_MAX_LENGTH}",
"--unwindset strlen.0:{NBNS_NAME_MAX_LENGTH}",
"--unwindset strncpy.0:{DNS_CACHE_NAME_LENGTH}"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Parser.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Cache.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto"
],
"DEF":
[
"ipconfigUSE_DNS_CACHE={USE_CACHE}",
"ipconfigUSE_NBNS=1",
"ipconfigNETWORK_MTU=586"
]
}
@@ -0,0 +1,19 @@
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "queue.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_DNS.h"
#include "FreeRTOS_IP_Private.h"
void FreeRTOS_dnsclear( void );
void harness()
{
if( ipconfigUSE_DNS_CACHE != 0 )
{
FreeRTOS_dnsclear();
}
}
@@ -0,0 +1,20 @@
{
"ENTRY": "DNSclear",
################################################################
# This configuration flag uses DNS cache
"USE_CACHE":1,
"CBMCFLAGS":
[
"--unwind 1",
"--nondet-static"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Cache.goto"
],
"DEF":
[
"ipconfigUSE_DNS_CACHE={USE_CACHE}"
]
}
@@ -0,0 +1,303 @@
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_UDP_IP.h"
#include "FreeRTOS_DNS.h"
#include "FreeRTOS_DHCP.h"
#include "NetworkBufferManagement.h"
#include "NetworkInterface.h"
/* CBMC includes. */
#include "cbmc.h"
uint32_t FreeRTOS_dnslookup( const char * pcHostName );
Socket_t DNS_CreateSocket( TickType_t uxReadTimeout_ticks );
void DNS_CloseSocket( Socket_t xDNSSocket );
BaseType_t DNS_ReadReply( ConstSocket_t xDNSSocket,
struct freertos_sockaddr * xAddress,
struct xDNSBuffer * pxDNSBuf );
uint32_t DNS_SendRequest( Socket_t xDNSSocket,
struct freertos_sockaddr * xAddress,
struct xDNSBuffer * pxDNSBuf );
uint32_t DNS_ParseDNSReply( uint8_t * pucUDPPayloadBuffer,
size_t uxBufferLength,
struct freertos_addrinfo ** ppxAddressInfo,
BaseType_t xExpected,
uint16_t usPort );
size_t __CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage( uint8_t * pucUDPPayloadBuffer,
const char * pcHostName,
TickType_t uxIdentifier,
UBaseType_t uxHostType );
uintptr_t __CPROVER_file_local_FreeRTOS_IP_Utils_c_void_ptr_to_uintptr( const void * pvPointer );
/****************************************************************
* We abstract:
*
* All kernel task scheduling functions since we are doing
* sequential verification and the sequential verification of these
* sequential primitives is done elsewhere.
*
* Many methods in the FreeRTOS TCP API in stubs/freertos_api.c
*
* DNS_ParseDNSReply proved memory safe elsewhere
*
* prvCreateDNSMessage
*
* This proof assumes the length of pcHostName is bounded by
* MAX_HOSTNAME_LEN. We have to bound this length because we have to
* bound the iterations of strcmp.
****************************************************************/
/*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 * ) safeMalloc( sizeof( NetworkBufferDescriptor_t ) );
if( pxNetworkBuffer != NULL )
{
pxNetworkBuffer->pucEthernetBuffer = safeMalloc( xRequestedSizeBytes + ipUDP_PAYLOAD_IP_TYPE_OFFSET );
if( pxNetworkBuffer->pucEthernetBuffer == NULL )
{
free( pxNetworkBuffer );
pxNetworkBuffer = NULL;
}
else
{
pxNetworkBuffer->pucEthernetBuffer = ( ( uint8_t * ) pxNetworkBuffer->pucEthernetBuffer ) + ipUDP_PAYLOAD_IP_TYPE_OFFSET;
pxNetworkBuffer->xDataLength = xRequestedSizeBytes;
}
}
return pxNetworkBuffer;
}
/*
* In this function, it only allocates network buffer by pxGetNetworkBufferWithDescriptor
* stub function above here. In this case, we should free both network buffer descriptor and pucEthernetBuffer.
*/
void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer )
{
__CPROVER_assert( pxNetworkBuffer != NULL,
"Precondition: pxNetworkBuffer != NULL" );
free( pxNetworkBuffer->pucEthernetBuffer - ipUDP_PAYLOAD_IP_TYPE_OFFSET );
free( pxNetworkBuffer );
}
/* FreeRTOS_ReleaseUDPPayloadBuffer is mocked here and the memory
* is not freed as the buffer allocated by the FreeRTOS_recvfrom is static
* memory */
void FreeRTOS_ReleaseUDPPayloadBuffer( void * pvBuffer )
{
__CPROVER_assert( pvBuffer != NULL,
"FreeRTOS precondition: pvBuffer != NULL" );
}
/****************************************************************
* Abstract DNS_ParseDNSReply proved memory safe in ParseDNSReply.
*
* We stub out his function to fill the payload buffer with
* unconstrained data and return an unconstrained size.
*
* The function under test uses only the return value of this
* function.
****************************************************************/
uint32_t DNS_ParseDNSReply( uint8_t * pucUDPPayloadBuffer,
size_t uxBufferLength,
struct freertos_addrinfo ** ppxAddressInfo,
BaseType_t xExpected,
uint16_t usPort )
{
uint32_t size;
__CPROVER_havoc_object( pucUDPPayloadBuffer );
return size;
}
/****************************************************************
* Abstract DNS_SendRequest
*
* We stub out this function with return constraint of true or false
*
****************************************************************/
uint32_t DNS_SendRequest( Socket_t xDNSSocket,
struct freertos_sockaddr * xAddress,
struct xDNSBuffer * pxDNSBuf )
{
uint32_t ret;
__CPROVER_assume( ret >= 0 );
__CPROVER_assume( ret <= 1 );
return ret;
}
/****************************************************************
* Abstract DNS_BindSocket
*
* We stub out this function with return constraint of true or false
*
****************************************************************/
BaseType_t DNS_BindSocket( Socket_t xSocket,
uint16_t usPort )
{
BaseType_t xReturn;
__CPROVER_assume( xReturn == pdTRUE || xReturn == pdFALSE );
return xReturn;
}
/****************************************************************
* Abstract DNS_ReadReply
*
* We stub out this function which returned a dns_buffer filled with random data
*
****************************************************************/
BaseType_t DNS_ReadReply( ConstSocket_t xDNSSocket,
struct freertos_sockaddr * xAddress,
struct xDNSBuffer * pxDNSBuf )
{
int len;
uintptr_t uxTypeOffset;
const uint8_t * pucIPType;
uint8_t ucIPType;
NetworkBufferDescriptor_t * pxNetworkEndPoints;
__CPROVER_assume( ( len > sizeof( DNSMessage_t ) ) && ( len < ipconfigNETWORK_MTU ) );
pxNetworkEndPoints = pxGetNetworkBufferWithDescriptor( len, 0 );
__CPROVER_assume( pxNetworkEndPoints != NULL );
__CPROVER_assume( pxNetworkEndPoints->pucEthernetBuffer != NULL );
pxDNSBuf->pucPayloadBuffer = pxNetworkEndPoints->pucEthernetBuffer;
pxDNSBuf->uxPayloadLength = len;
__CPROVER_havoc_slice( pxDNSBuf->pucPayloadBuffer, pxDNSBuf->uxPayloadLength );
/* When IPv6 is supported, find out the type of the packet.
* It is stored 48 bytes before the payload buffer as 0x40 or 0x60. */
uxTypeOffset = __CPROVER_file_local_FreeRTOS_IP_Utils_c_void_ptr_to_uintptr( pxDNSBuf->pucPayloadBuffer );
uxTypeOffset -= ipUDP_PAYLOAD_IP_TYPE_OFFSET;
pucIPType = ( const uint8_t * ) uxTypeOffset;
/* For an IPv4 packet, pucIPType points to 6 bytes before the pucEthernetBuffer,
* for a IPv6 packet, pucIPType will point to the first byte of the IP-header: 'ucVersionTrafficClass'. */
ucIPType = pucIPType[ 0 ] & 0xf0U;
/* To help the translation from a UDP payload pointer to a networkBuffer,
* a byte was stored at a certain negative offset (-48 bytes).
* It must have a value of either 0x4x or 0x6x. */
__CPROVER_assume( ( ucIPType == ipTYPE_IPv4 ) || ( ucIPType == ipTYPE_IPv6 ) );
return nondet_basetype();
}
void DNS_CloseSocket( Socket_t xDNSSocket )
{
__CPROVER_assert( xDNSSocket != NULL, "The xDNSSocket cannot be NULL." );
free( xDNSSocket );
}
Socket_t DNS_CreateSocket( TickType_t uxReadTimeout_ticks )
{
Socket_t sock = malloc( sizeof( struct xSOCKET ) );
return sock;
}
uint32_t FreeRTOS_dnslookup( const char * pcHostName )
{
int ret;
__CPROVER_assume( ret < 0xFFFF );
__CPROVER_assume( ret > 0 );
return ret;
}
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 ret;
return ret;
}
/****************************************************************
* Abstract prvCreateDNSMessage
*
* This function writes a header, a hostname, and a constant amount of
* data into the payload buffer, and returns the amount of data
* written. This abstraction just fills the entire buffer with
* unconstrained data and returns and unconstrained length.
****************************************************************/
size_t __CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage( uint8_t * pucUDPPayloadBuffer,
const char * pcHostName,
TickType_t uxIdentifier,
UBaseType_t uxHostType )
{
__CPROVER_havoc_object( pucUDPPayloadBuffer );
size_t size;
return size;
}
uint32_t Prepare_CacheLookup( const char * pcHostName,
BaseType_t xFamily,
struct freertos_addrinfo ** ppxAddressInfo )
{
return nondet_uint32();
}
/****************************************************************
* The proof for FreeRTOS_gethostbyname.
****************************************************************/
void harness()
{
size_t len;
pxNetworkEndPoints = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxNetworkEndPoints != NULL );
/* Asserts are added in the src code to make sure ucDNSIndex
* will be less than ipconfigENDPOINT_DNS_ADDRESS_COUNT */
__CPROVER_assume( pxNetworkEndPoints->ipv6_settings.ucDNSIndex < ipconfigENDPOINT_DNS_ADDRESS_COUNT );
__CPROVER_assume( pxNetworkEndPoints->ipv4_settings.ucDNSIndex < ipconfigENDPOINT_DNS_ADDRESS_COUNT );
pxNetworkEndPoints->pxNext = NULL;
/* Interface init. */
pxNetworkEndPoints->pxNetworkInterface = ( NetworkInterface_t * ) malloc( sizeof( NetworkInterface_t ) );
__CPROVER_assume( pxNetworkEndPoints->pxNetworkInterface != NULL );
pxNetworkEndPoints->pxNetworkInterface->pfOutput = &NetworkInterfaceOutputFunction_Stub;
__CPROVER_assume( len <= MAX_HOSTNAME_LEN );
char * pcHostName = malloc( len );
__CPROVER_assume( len > 0 ); /* prvProcessDNSCache strcmp */
__CPROVER_assume( pcHostName != NULL );
pcHostName[ len - 1 ] = NULL;
FreeRTOS_gethostbyname( pcHostName );
}
@@ -0,0 +1,51 @@
{
"ENTRY": "DNSgetHostByName",
################################################################
# This configuration sets callback to 0.
# It also sets MAX_HOSTNAME_LEN to 10 to bound strcmp.
# According to the specification MAX_HOST_NAME is upto 255.
"callback": 0,
"MAX_HOSTNAME_LEN": 10,
"ENDPOINT_DNS_ADDRESS_COUNT": 5,
"HOSTNAME_UNWIND": "__eval {MAX_HOSTNAME_LEN} + 1",
"ENDPOINT_DNS_ADDRESS_COUNT_UNWIND": "__eval {ENDPOINT_DNS_ADDRESS_COUNT} + 1",
"DNS_CACHE_ENTRIES": 2,
"CBMCFLAGS":
[
"--unwind 1",
"--unwindset strchr.0:{HOSTNAME_UNWIND}",
"--unwindset __CPROVER_file_local_FreeRTOS_DNS_c_prvIncreaseDNS4Index.0:{ENDPOINT_DNS_ADDRESS_COUNT_UNWIND}",
"--unwindset __CPROVER_file_local_FreeRTOS_DNS_c_prvIncreaseDNS6Index.0:{ENDPOINT_DNS_ADDRESS_COUNT_UNWIND}",
"--unwindset __CPROVER_file_local_FreeRTOS_DNS_c_prvFillSockAddress.0:2,__CPROVER_file_local_FreeRTOS_DNS_c_prvFillSockAddress.1:2",
"--unwindset __CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage.0:{HOSTNAME_UNWIND},__CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage.1:{HOSTNAME_UNWIND},strlen.0:{HOSTNAME_UNWIND},__builtin___strcpy_chk.0:{HOSTNAME_UNWIND},strcmp.0:{HOSTNAME_UNWIND},strcpy.0:{HOSTNAME_UNWIND}",
"--unwindset __CPROVER_file_local_FreeRTOS_DNS_c_prvGetHostByNameOp_WithRetry.0:{HOSTNAME_UNWIND}",
"--nondet-static"
],
"OPT":
[
"--export-file-local-symbols"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Parser.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto"
],
"DEF":
[
"ipconfigUSE_IPv6=1",
"ipconfigDNS_USE_CALLBACKS={callback}",
"MAX_HOSTNAME_LEN={MAX_HOSTNAME_LEN}",
"ipconfigENDPOINT_DNS_ADDRESS_COUNT={ENDPOINT_DNS_ADDRESS_COUNT}",
"ipconfigDNS_CACHE_ENTRIES={DNS_CACHE_ENTRIES}"
]
}
@@ -0,0 +1,9 @@
{ "expected-missing-functions":
[
"vLoggingPrintf",
"xApplicationGetRandomNumber",
"xTaskGetTickCount"
],
"proof-name": "DNSgetHostByName",
"proof-root": "tools/cbmc/proofs"
}
@@ -0,0 +1,299 @@
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_UDP_IP.h"
#include "FreeRTOS_DNS.h"
#include "FreeRTOS_DHCP.h"
#include "NetworkBufferManagement.h"
#include "NetworkInterface.h"
/* CBMC includes. */
#include "cbmc.h"
uintptr_t __CPROVER_file_local_FreeRTOS_IP_Utils_c_void_ptr_to_uintptr( const void * pvPointer );
/****************************************************************
* We abstract:
*
* All kernel task scheduling functions since we are doing
* sequential verification and the sequential verification of these
* sequential primitives is done elsewhere.
*
* Many methods in the FreeRTOS TCP API in stubs/freertos_api.c
*
* DNS_ParseDNSReply proved memory safe elsewhere
*
* prvCreateDNSMessage
*
* This proof assumes the length of pcHostName is bounded by
* MAX_HOSTNAME_LEN. We have to bound this length because we have to
* bound the iterations of strcmp.
****************************************************************/
/*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 * ) safeMalloc( sizeof( NetworkBufferDescriptor_t ) );
if( pxNetworkBuffer != NULL )
{
pxNetworkBuffer->pucEthernetBuffer = safeMalloc( xRequestedSizeBytes + ipBUFFER_PADDING + ipUDP_PAYLOAD_IP_TYPE_OFFSET );
if( pxNetworkBuffer->pucEthernetBuffer == NULL )
{
free( pxNetworkBuffer );
pxNetworkBuffer = NULL;
}
else
{
pxNetworkBuffer->pucEthernetBuffer = ( ( uint8_t * ) pxNetworkBuffer->pucEthernetBuffer ) + ipBUFFER_PADDING + ipUDP_PAYLOAD_IP_TYPE_OFFSET;
pxNetworkBuffer->xDataLength = xRequestedSizeBytes;
}
}
return pxNetworkBuffer;
}
/*
* In this function, it only allocates network buffer by pxGetNetworkBufferWithDescriptor
* stub function above here. In this case, we should free both network buffer descriptor and pucEthernetBuffer.
*/
void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer )
{
__CPROVER_assert( pxNetworkBuffer != NULL,
"Precondition: pxNetworkBuffer != NULL" );
free( pxNetworkBuffer->pucEthernetBuffer - ( ipUDP_PAYLOAD_IP_TYPE_OFFSET + ipBUFFER_PADDING ) );
free( pxNetworkBuffer );
}
/* FreeRTOS_ReleaseUDPPayloadBuffer is mocked here and the memory
* is not freed as the buffer allocated by the FreeRTOS_recvfrom is static
* memory */
void FreeRTOS_ReleaseUDPPayloadBuffer( void * pvBuffer )
{
__CPROVER_assert( pvBuffer != NULL,
"FreeRTOS precondition: pvBuffer != NULL" );
}
/****************************************************************
* Abstract DNS_ParseDNSReply proved memory safe in ParseDNSReply.
*
* We stub out his function to fill the payload buffer with
* unconstrained data and return an unconstrained size.
*
* The function under test uses only the return value of this
* function.
****************************************************************/
uint32_t DNS_ParseDNSReply( uint8_t * pucUDPPayloadBuffer,
size_t uxBufferLength,
struct freertos_addrinfo ** ppxAddressInfo,
BaseType_t xExpected,
uint16_t usPort )
{
__CPROVER_assert( pucUDPPayloadBuffer != NULL,
"Precondition: pucUDPPayloadBuffer != NULL" );
__CPROVER_havoc_object( pucUDPPayloadBuffer );
return nondet_uint32();
}
/****************************************************************
* Abstract prvCreateDNSMessage
*
* This function writes a header, a hostname, and a constant amount of
* data into the payload buffer, and returns the amount of data
* written. This abstraction just fills the entire buffer with
* unconstrained data and returns and unconstrained length.
****************************************************************/
size_t __CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage( uint8_t * pucUDPPayloadBuffer,
const char * pcHostName,
TickType_t uxIdentifier,
UBaseType_t uxHostType )
{
__CPROVER_assert( pucUDPPayloadBuffer != NULL,
"Precondition: pucUDPPayloadBuffer != NULL" );
__CPROVER_assert( pcHostName != NULL,
"Precondition: pcHostName != NULL" );
__CPROVER_havoc_object( pucUDPPayloadBuffer );
return nondet_sizet();
}
/****************************************************************
* A stub for a function callback.
****************************************************************/
void func( const char * pcHostName,
void * pvSearchID,
struct freertos_addrinfo * pxAddressInfo )
{
__CPROVER_assert( pcHostName != NULL,
"Precondition: pcHostName != NULL" );
__CPROVER_assert( pvSearchID != NULL,
"Precondition: pvSearchID != NULL" );
/* pxAddressInfo is not validated for not being NULL as
* pxAddressInfo could be NULL if there is a timeout or other errors. */
}
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 ret;
return ret;
}
Socket_t DNS_CreateSocket( TickType_t uxReadTimeout_ticks )
{
Socket_t xSock = safeMalloc( sizeof( struct xSOCKET ) );
return xSock;
}
void DNS_CloseSocket( Socket_t xDNSSocket )
{
__CPROVER_assert( xDNSSocket != NULL, "The xDNSSocket cannot be NULL." );
free( xDNSSocket );
}
/****************************************************************
* Abstract DNS_BindSocket
*
* We stub out this function with return constraint of true or false
*
****************************************************************/
BaseType_t DNS_BindSocket( Socket_t xSocket,
uint16_t usPort )
{
BaseType_t xReturn;
__CPROVER_assume( xReturn == pdTRUE || xReturn == pdFALSE );
return xReturn;
}
/****************************************************************
* Abstract DNS_SendRequest
*
* We stub out this function with return constraint of true or false
*
****************************************************************/
uint32_t DNS_SendRequest( Socket_t xDNSSocket,
struct freertos_sockaddr * xAddress,
struct xDNSBuffer * pxDNSBuf )
{
uint32_t ret;
__CPROVER_assume( ret >= 0 );
__CPROVER_assume( ret <= 1 );
return ret;
}
/****************************************************************
* Abstract DNS_ReadReply
*
* We stub out this function which returned a dns_buffer filled with random data
*
****************************************************************/
BaseType_t DNS_ReadReply( ConstSocket_t xDNSSocket,
struct freertos_sockaddr * xAddress,
struct xDNSBuffer * pxDNSBuf )
{
int len;
NetworkBufferDescriptor_t * pxNetworkBuffer;
__CPROVER_assume( ( len > sizeof( DNSMessage_t ) ) && ( len < ipconfigNETWORK_MTU ) );
pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( len, 0 );
__CPROVER_assume( pxNetworkBuffer != NULL );
__CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL );
pxDNSBuf->pucPayloadBuffer = pxNetworkBuffer->pucEthernetBuffer;
pxDNSBuf->uxPayloadLength = len;
__CPROVER_havoc_slice( pxDNSBuf->pucPayloadBuffer, pxDNSBuf->uxPayloadLength );
return nondet_basetype();
}
/* Function xDNSSetCallBack is proven to be correct separately. */
BaseType_t xDNSSetCallBack( const char * pcHostName,
void * pvSearchID,
FOnDNSEvent pCallbackFunction,
TickType_t xTimeout,
TickType_t xIdentifier,
BaseType_t xIsIPv6 )
{
BaseType_t xReturn;
__CPROVER_assume( xReturn == pdTRUE || xReturn == pdFALSE );
return xReturn;
}
uint32_t Prepare_CacheLookup( const char * pcHostName,
BaseType_t xFamily,
struct freertos_addrinfo ** ppxAddressInfo )
{
( *ppxAddressInfo ) = ( struct freertos_addrinfo * ) malloc( sizeof( struct freertos_addrinfo ) );
__CPROVER_assume( ( *ppxAddressInfo ) != NULL );
__CPROVER_assume( ( *ppxAddressInfo )->ai_next == NULL );
uint32_t ulRet;
return ulRet;
}
/****************************************************************
* The proof for FreeRTOS_gethostbyname_a.
****************************************************************/
void harness()
{
size_t len;
pxNetworkEndPoints = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxNetworkEndPoints != NULL );
/* Asserts are added in the src code to make sure ucDNSIndex
* will be less than ipconfigENDPOINT_DNS_ADDRESS_COUNT */
__CPROVER_assume( pxNetworkEndPoints->ipv6_settings.ucDNSIndex < ipconfigENDPOINT_DNS_ADDRESS_COUNT );
__CPROVER_assume( pxNetworkEndPoints->ipv4_settings.ucDNSIndex < ipconfigENDPOINT_DNS_ADDRESS_COUNT );
__CPROVER_assume( pxNetworkEndPoints->pxNext == NULL );
/* Interface init. */
pxNetworkEndPoints->pxNetworkInterface = ( NetworkInterface_t * ) malloc( sizeof( NetworkInterface_t ) );
__CPROVER_assume( pxNetworkEndPoints->pxNetworkInterface != NULL );
__CPROVER_assume( len <= MAX_HOSTNAME_LEN );
char * pcHostName = safeMalloc( len );
__CPROVER_assume( len > 0 ); /* prvProcessDNSCache strcmp */
__CPROVER_assume( pcHostName != NULL );
pcHostName[ len - 1 ] = NULL;
FOnDNSEvent pCallback = &func;
TickType_t xTimeout;
void * pvSearchID;
__CPROVER_assume( pvSearchID != NULL );
FreeRTOS_gethostbyname_a( pcHostName, pCallback, pvSearchID, xTimeout );
}
@@ -0,0 +1,42 @@
{
"ENTRY": "DNSgetHostByName_a",
################################################################
# This configuration flag sets callback to 1. It also sets MAX_HOSTNAME_LEN to 10 and MAX_REQ_SIZE to 50 for performance issues.
# According to the specification MAX_HOST_NAME is upto 255.
"callback": 1,
"MAX_HOSTNAME_LEN": 10,
"ENDPOINT_DNS_ADDRESS_COUNT": 5,
"HOSTNAME_UNWIND": "__eval {MAX_HOSTNAME_LEN} + 1",
"CBMCFLAGS":
[
"--unwind 1",
"--unwindset __CPROVER_file_local_FreeRTOS_DNS_c_prvFillSockAddress.0:2,__CPROVER_file_local_FreeRTOS_DNS_c_prvFillSockAddress.1:2",
"--unwindset FreeRTOS_freeaddrinfo.0:2",
"--unwindset strchr.0:{HOSTNAME_UNWIND}",
"--unwindset strncpy.0:255",
"--unwindset __CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage.0:{HOSTNAME_UNWIND},__CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage.1:{HOSTNAME_UNWIND},prvGetHostByName.0:{HOSTNAME_UNWIND},prvProcessDNSCache.0:5,strlen.0:{HOSTNAME_UNWIND},__builtin___strcpy_chk.0:{HOSTNAME_UNWIND},strcmp.0:{HOSTNAME_UNWIND},xTaskResumeAll.0:{HOSTNAME_UNWIND},xTaskResumeAll.1:{HOSTNAME_UNWIND},strcpy.0:{HOSTNAME_UNWIND}",
"--nondet-static"
],
"OPT":
[
"--export-file-local-symbols"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Parser.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto"
],
"DEF":
[
"ipconfigDNS_USE_CALLBACKS={callback}",
"MAX_HOSTNAME_LEN={MAX_HOSTNAME_LEN}",
# This value is defined only when ipconfigUSE_DNS_CACHE==1
"ipconfigDNS_CACHE_NAME_LENGTH=254",
"ipconfigENDPOINT_DNS_ADDRESS_COUNT={ENDPOINT_DNS_ADDRESS_COUNT}"
]
}
@@ -0,0 +1,13 @@
{ "expected-missing-functions":
[
"vLoggingPrintf",
"xApplicationGetRandomNumber",
"vListInsertEnd",
"vTaskSetTimeOutState",
"vTaskSuspendAll",
"xTaskGetTickCount",
"xTaskResumeAll"
],
"proof-name": "DNSgetHostByName_a",
"proof-root": "tools/cbmc/proofs"
}
@@ -0,0 +1,85 @@
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "queue.h"
#include "list.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_DNS.h"
#include "FreeRTOS_IP_Private.h"
/* CBMC includes. */
#include "cbmc.h"
/* This proof assumes the length of pcHostName is bounded by MAX_HOSTNAME_LEN. This also abstracts the concurrency. */
void vDNSInitialise( void );
BaseType_t xDNSSetCallBack( const char * pcHostName,
void * pvSearchID,
FOnDNSEvent pCallbackFunction,
TickType_t xTimeout,
TickType_t xIdentifier,
BaseType_t xIsIPv6 );
/* Abstraction of uxListRemove from list. This also abstracts the concurrency. */
void vListInitialise( List_t * const pxList )
{
__CPROVER_assert( pxList != NULL, "pxList cannot be NULL" );
pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd );
pxList->xListEnd.xItemValue = portMAX_DELAY;
/* The list end next and previous pointers point to itself so we know
* when the list is empty. */
pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd );
pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd );
pxList->uxNumberOfItems = ( UBaseType_t ) 0U;
}
/* Abstraction of uxListRemove from list. This also abstracts the concurrency. */
UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
{
List_t * const pxList = pxItemToRemove->pxContainer;
pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
if( pxList->pxIndex == pxItemToRemove )
{
pxList->pxIndex = pxItemToRemove->pxPrevious;
}
pxItemToRemove->pxContainer = NULL;
( pxList->uxNumberOfItems )--;
return pxList->uxNumberOfItems;
}
/* The function func mimics the callback function.*/
void func( const char * pcHostName,
void * pvSearchID,
uint32_t ulIPAddress )
{
}
void harness()
{
vDNSInitialise(); /* We initialize the callbacklist in order to be able to check for functions that timed out. */
size_t pvSearchID;
FOnDNSEvent pCallback = func;
TickType_t xTimeout;
TickType_t xIdentifier;
BaseType_t xIsIPv6;
size_t len;
BaseType_t xReturn;
__CPROVER_assume( len > 0 && len <= MAX_HOSTNAME_LEN );
char * pcHostName = safeMalloc( len );
__CPROVER_assume( pcHostName != NULL );
__CPROVER_havoc_slice( pcHostName, len - 1 );
pcHostName[ len - 1 ] = NULL;
xReturn = xDNSSetCallBack( pcHostName, &pvSearchID, pCallback, xTimeout, xIdentifier, xIsIPv6 ); /* Add an item to be able to check the cancel function if the list is non-empty. */
FreeRTOS_gethostbyname_cancel( &pvSearchID );
}
@@ -0,0 +1,33 @@
{
"ENTRY": "DNSgetHostByName_cancel",
################################################################
# This configuration flag sets callback to 1. It also sets MAX_HOSTNAME_LEN to 10 for performance issues.
# According to the specification MAX_HOST_NAME is upto 255.
"callback": 1,
"MAX_HOSTNAME_LEN": 10,
"HOSTNAME_UNWIND": "__eval {MAX_HOSTNAME_LEN} + 1",
"CBMCFLAGS":
[
"--unwind 1",
"--unwindset prvProcessDNSCache.0:5,strlen.0:{HOSTNAME_UNWIND},__builtin___strcpy_chk.0:{HOSTNAME_UNWIND},vDNSCheckCallBack.0:2,strcpy.0:{HOSTNAME_UNWIND}",
"--unwindset strncpy.0:{HOSTNAME_UNWIND}"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Timers.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Callback.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":
[
"ipconfigDNS_USE_CALLBACKS={callback}",
"MAX_HOSTNAME_LEN={MAX_HOSTNAME_LEN}",
# This value is defined only when ipconfigUSE_DNS_CACHE==1
"ipconfigDNS_CACHE_NAME_LENGTH=254"
]
}
@@ -0,0 +1,42 @@
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "queue.h"
#include "list.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_DNS.h"
#include "FreeRTOS_IP_Private.h"
/* This assumes that the length of the hostname is bounded by MAX_HOSTNAME_LEN. */
void * safeMalloc( size_t xWantedSize )
{
if( xWantedSize == 0 )
{
return NULL;
}
uint8_t byte;
return byte ? malloc( xWantedSize ) : NULL;
}
void harness()
{
if( ipconfigUSE_DNS_CACHE != 0 )
{
size_t len;
__CPROVER_assume( len >= 0 && len <= MAX_HOSTNAME_LEN );
char * pcHostName = safeMalloc( len ); /* malloc is replaced by safeMalloc */
if( len && pcHostName )
{
pcHostName[ len - 1 ] = NULL;
}
if( pcHostName ) /* guarding against NULL pointer */
{
FreeRTOS_dnslookup( pcHostName );
}
}
}
@@ -0,0 +1,27 @@
{
"ENTRY": "DNSlookup",
################################################################
# This configuration uses DNS cache and the MAX_HOSTNAME_LEN is set to 255 according to the specification
"MAX_HOSTNAME_LEN": 255,
"HOSTNAME_UNWIND": "__eval {MAX_HOSTNAME_LEN} + 1",
"USE_CACHE": 1,
"CBMCFLAGS":
[
"--unwind 1",
"--unwindset prvFindEntryIndex.0:3",
"--unwindset prvProcessDNSCache.0:5,strcmp.0:{HOSTNAME_UNWIND}",
"--nondet-static"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Cache.goto",
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/tasks.goto"
],
"DEF":
[
"ipconfigUSE_DNS_CACHE={USE_CACHE}",
"MAX_HOSTNAME_LEN={MAX_HOSTNAME_LEN}"
],
"OPT" : "-m32"
}
@@ -0,0 +1,21 @@
{
"ENTRY": "NBNSHandlePacket",
"USE_CACHE":1,
"CBMCFLAGS":
[
"--unwind 1",
"--nondet-static"
],
"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_DNS.goto"
],
"DEF":
[
"ipconfigUSE_DNS_CACHE={USE_CACHE}",
"ipconfigUSE_NBNS=1"
]
}
@@ -0,0 +1,41 @@
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "queue.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_DNS.h"
#include "FreeRTOS_DNS_Parser.h"
#include "FreeRTOS_IP_Private.h"
#include "cbmc.h"
NetworkBufferDescriptor_t xNetworkBuffer;
/* DNS_TreatNBNS is proved separately */
void DNS_TreatNBNS( uint8_t * pucPayload,
size_t uxBufferLength,
uint32_t ulIPAddress )
{
__CPROVER_assert( pucPayload != NULL, "Precondition: pucPayload != NULL" );
}
void harness()
{
uint32_t ulIPAddress;
BaseType_t xDataSize;
/* Assume an upper limit on max memory that can be allocated */
__CPROVER_assume( ( xDataSize < ( ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ) ) );
xNetworkBuffer.xDataLength = xDataSize;
xNetworkBuffer.pucEthernetBuffer = safeMalloc( xDataSize );
/* pucEthernetBuffer being not NULL is pre validated before the call to ulNBNSHandlePacket */
__CPROVER_assume( xNetworkBuffer.pucEthernetBuffer != NULL );
xNetworkBuffer.pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
ulNBNSHandlePacket( &xNetworkBuffer );
}
@@ -0,0 +1,22 @@
{
"ENTRY": "prepareReplyDNSMessage",
"USE_CACHE":1,
"CBMCFLAGS":
[
"--unwind 1",
"--nondet-static"
],
"OBJS":
[
"$(ENTRY)_harness.goto",
"$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto",
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Parser.goto"
],
"DEF":
[
"ipconfigUSE_DNS_CACHE={USE_CACHE}",
"ipconfigUSE_NBNS=1"
]
}
@@ -0,0 +1,117 @@
/*
* 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_DNS.h"
#include "FreeRTOS_DNS_Parser.h"
#include "FreeRTOS_IP_Private.h"
#include "cbmc.h"
NetworkBufferDescriptor_t xNetworkBuffer;
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;
}
/* The checksum generation is stubbed out since the actual checksum
* does not matter. The stub will return an indeterminate value each time. */
uint16_t usGenerateChecksum( uint16_t usSum,
const uint8_t * pucNextData,
size_t uxByteCount )
{
uint16_t usReturn;
__CPROVER_assert( pucNextData != NULL, "Next data cannot be NULL" );
/* Return an indeterminate value. */
return usReturn;
}
/* The checksum generation is stubbed out since the actual checksum
* does not matter. The stub will return an indeterminate value each time. */
uint16_t usGenerateProtocolChecksum( const uint8_t * const pucEthernetBuffer,
size_t uxBufferLength,
BaseType_t xOutgoingPacket )
{
uint16_t usReturn;
__CPROVER_assert( pucEthernetBuffer != NULL, "Ethernet buffer cannot be NULL" );
/* Return an indeterminate value. */
return usReturn;
}
void harness()
{
uint32_t ulIPAddress;
uint16_t usLength;
/* Assume at least 1 valid endpoint */
pxNetworkEndPoint_Temp = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) );
__CPROVER_assume( pxNetworkEndPoint_Temp != NULL );
BaseType_t xDataSize;
/* The pucEthernetBuffer is re adjusted to the following size before the
* call to prepareReplyDNSMessage by pxResizeNetworkBufferWithDescriptor. If buffer allocation
* scheme #1 (BufferAllocation_1.c) is used we assert if the needed size is actually present
* in the buffer. */
__CPROVER_assume( ( xDataSize > ( sizeof( UDPPacket_t ) + sizeof( NBNSRequest_t ) + sizeof( NBNSAnswer_t ) - 2 * sizeof( uint16_t ) ) ) && ( xDataSize < ipconfigNETWORK_MTU ) );
xNetworkBuffer.pucEthernetBuffer = safeMalloc( xDataSize );
xNetworkBuffer.pxEndPoint = pxNetworkEndPoint_Temp;
/* xNetworkBuffer.pucEthernetBuffer is checked if its valid before the call to
* prepareReplyDNSMessage() */
__CPROVER_assume( xNetworkBuffer.pucEthernetBuffer != NULL );
xNetworkBuffer.xDataLength = xDataSize;
prepareReplyDNSMessage( &xNetworkBuffer, usLength );
}