generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 207
Fix CBMC proofs for DNS #718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tony-josi-aws
merged 30 commits into
FreeRTOS:dev/IPv6_integration
from
tony-josi-aws:fix_cbmc_proof_dns
Feb 23, 2023
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
f30e185
Use CBMC XML output to enable VSCode debugger (#673)
karkhaz e703699
wip
tony-josi-aws ba95154
wip DNSgetHostByName
tony-josi-aws 7d09c1e
wip DNSgetHostByName
tony-josi-aws c243eee
fixed cbmc proof for DNS_ReadNameField
tony-josi-aws ae10fc0
wip DNSgetHostByName_a_harness
tony-josi-aws f07501f
Fix CBMC prooff for DNSgetHostByName
tony-josi-aws e08f38e
Merge branch 'dev/IPv6_integration' into fix_cbmc_proof_dns
tony-josi-aws fd1690e
wip fix DNSgetHostByName_a CBMC proof
tony-josi-aws 241535f
fixed cbmc target func not called issue in DNSclear
tony-josi-aws 8dac64d
fixed cbmc target func not called issue in DNSlookup
tony-josi-aws 88f699f
fix DNSgetHostByName_a CBMC proof
tony-josi-aws 07e208a
update comments
tony-josi-aws e3d4b4c
more asserts
tony-josi-aws 22e6eb6
fixing formatting
tony-josi-aws 3a9405d
updating as per review comments
tony-josi-aws 6e229f9
fix dns after review comments
tony-josi-aws 45910b3
adding more asserts
tony-josi-aws cb85b0c
adds more asserts
tony-josi-aws 653c089
minor fix
tony-josi-aws 3680cac
fixing comments
tony-josi-aws 93b9c21
fixing comments
tony-josi-aws d6ebdab
fixing minor issue
tony-josi-aws 5f9ad1d
Merge branch 'dev/IPv6_integration' into fix_cbmc_proof_dns
tony-josi-aws 89955c6
fixing DNS_ReadReply() signature
tony-josi-aws 5661ba2
making code more consistant
tony-josi-aws ff8c448
adding more asserts
tony-josi-aws 7d454ec
making code more consistent
tony-josi-aws 4c4023b
Merge branch 'dev/IPv6_integration' of github.com:FreeRTOS/FreeRTOS-P…
tony-josi-aws 74d8bd1
Merge branch 'dev/IPv6_integration' into fix_cbmc_proof_dns
tony-josi-aws File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,15 +22,17 @@ | |
| uint32_t FreeRTOS_dnslookup( const char * pcHostName ); | ||
| Socket_t DNS_CreateSocket( TickType_t uxReadTimeout_ticks ); | ||
| void DNS_CloseSocket( Socket_t xDNSSocket ); | ||
| void DNS_ReadReply( 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 xBufferLength, | ||
| BaseType_t xExpected ); | ||
| size_t uxBufferLength, | ||
| struct freertos_addrinfo ** ppxAddressInfo, | ||
| BaseType_t xExpected, | ||
| uint16_t usPort ); | ||
|
|
||
| /**************************************************************** | ||
| * We abstract: | ||
|
|
@@ -61,8 +63,10 @@ uint32_t DNS_ParseDNSReply( uint8_t * pucUDPPayloadBuffer, | |
| ****************************************************************/ | ||
|
|
||
| uint32_t DNS_ParseDNSReply( uint8_t * pucUDPPayloadBuffer, | ||
| size_t xBufferLength, | ||
| BaseType_t xExpected ) | ||
| size_t uxBufferLength, | ||
| struct freertos_addrinfo ** ppxAddressInfo, | ||
| BaseType_t xExpected, | ||
| uint16_t usPort ) | ||
| { | ||
| uint32_t size; | ||
|
|
||
|
|
@@ -94,32 +98,39 @@ uint32_t DNS_SendRequest( Socket_t xDNSSocket, | |
| * We stub out this function which returned a dns_buffer filled with random data | ||
| * | ||
| ****************************************************************/ | ||
| void DNS_ReadReply( Socket_t xDNSSocket, | ||
| BaseType_t DNS_ReadReply( ConstSocket_t xDNSSocket, | ||
| struct freertos_sockaddr * xAddress, | ||
| struct xDNSBuffer * pxDNSBuf ) | ||
| { | ||
| BaseType_t ret; | ||
| int len; | ||
|
|
||
| pxDNSBuf->pucPayloadBuffer = safeMalloc( len ); | ||
| __CPROVER_assume( ( len > sizeof( DNSMessage_t ) ) && ( len < CBMC_MAX_OBJECT_SIZE ) ); | ||
|
|
||
| pxDNSBuf->pucPayloadBuffer = malloc( len ); | ||
|
|
||
| pxDNSBuf->uxPayloadLength = len; | ||
|
|
||
| __CPROVER_assume( len < CBMC_MAX_OBJECT_SIZE ); | ||
| __CPROVER_assume( pxDNSBuf->pucPayloadBuffer != NULL ); | ||
|
|
||
| __CPROVER_havoc_slice( pxDNSBuf->pucPayloadBuffer, pxDNSBuf->uxPayloadSize ); | ||
| __CPROVER_havoc_slice( pxDNSBuf->pucPayloadBuffer, pxDNSBuf->uxPayloadLength ); | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
|
|
||
| void DNS_CloseSocket( Socket_t xDNSSocket ) | ||
| { | ||
| __CPROVER_assert( xDNSSocket != NULL, "The xDNSSocket cannot be NULL." ); | ||
AniruddhaKanhere marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| free( xDNSSocket ); | ||
| } | ||
|
|
||
| Socket_t DNS_CreateSocket( TickType_t uxReadTimeout_ticks ) | ||
| { | ||
| Socket_t sock; | ||
|
|
||
| Socket_t sock = malloc( sizeof(struct xSOCKET) ); | ||
| return sock; | ||
|
|
||
| } | ||
|
|
||
| uint32_t FreeRTOS_dnslookup( const char * pcHostName ) | ||
|
|
@@ -132,6 +143,16 @@ uint32_t FreeRTOS_dnslookup( const char * pcHostName ) | |
| 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 | ||
|
|
@@ -144,14 +165,40 @@ uint32_t FreeRTOS_dnslookup( const char * pcHostName ) | |
|
|
||
| size_t prvCreateDNSMessage( uint8_t * pucUDPPayloadBuffer, | ||
| const char * pcHostName, | ||
| TickType_t uxIdentifier ) | ||
| TickType_t uxIdentifier, | ||
| UBaseType_t uxHostType ) | ||
| { | ||
| __CPROVER_havoc_object( pucUDPPayloadBuffer ); | ||
| size_t size; | ||
|
|
||
| return size; | ||
| } | ||
|
|
||
| /*We assume that the pxGetNetworkBufferWithDescriptor function is implemented correctly and returns a valid data structure. */ | ||
| /*This is the mock to mimic the correct expected behavior. If this allocation fails, this might invalidate the proof. */ | ||
| NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes, | ||
| TickType_t xBlockTimeTicks ) | ||
| { | ||
| NetworkBufferDescriptor_t * pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) malloc( sizeof( NetworkBufferDescriptor_t ) ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we using malloc and safeMalloc? Why not stick to one?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
|
|
||
| if( pxNetworkBuffer != NULL ) | ||
| { | ||
| pxNetworkBuffer->pucEthernetBuffer = malloc( 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; | ||
| } | ||
|
|
||
| /**************************************************************** | ||
| * The proof for FreeRTOS_gethostbyname. | ||
| ****************************************************************/ | ||
|
|
@@ -160,12 +207,28 @@ 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 = safeMalloc( len ); | ||
| char * pcHostName = malloc( len ); | ||
|
|
||
| __CPROVER_assume( len > 0 ); /* prvProcessDNSCache strcmp */ | ||
| __CPROVER_assume( pcHostName != NULL ); | ||
| pcHostName[ len - 1 ] = NULL; | ||
|
|
||
| FreeRTOS_gethostbyname( pcHostName ); | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.