1 /*
2 * FreeRTOS memory safety proofs with CBMC.
3 * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 * http://aws.amazon.com/freertos
26 * http://www.FreeRTOS.org
27 */
28
29 /* FreeRTOS includes. */
30 #include "FreeRTOS.h"
31 #include "queue.h"
32
33 /* FreeRTOS+TCP includes. */
34 #include "FreeRTOS_IP.h"
35 #include "FreeRTOS_IP_Private.h"
36 #include "FreeRTOS_ARP.h"
37
38
39 ARPPacket_t xARPPacket;
40 NetworkBufferDescriptor_t xNetworkBuffer;
41
42 /* STUB!
43 * We assume that the pxGetNetworkBufferWithDescriptor function is
44 * implemented correctly and returns a valid data structure.
45 * This is the mock to mimic the expected behavior.
46 * If this allocation fails, this might invalidate the proof.
47 * FreeRTOS_OutputARPRequest calls pxGetNetworkBufferWithDescriptor
48 * to get a NetworkBufferDescriptor. Then it calls vARPGenerateRequestPacket
49 * passing this buffer along in the function call. vARPGenerateRequestPacket
50 * casts the pointer xNetworkBuffer.pucEthernetBuffer into an ARPPacket_t pointer
51 * and writes a complete ARPPacket to it. Therefore the buffer has to be at least of the size
52 * of an ARPPacket to guarantee memory safety.
53 */
pxGetNetworkBufferWithDescriptor(size_t xRequestedSizeBytes,TickType_t xBlockTimeTicks)54 NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes,
55 TickType_t xBlockTimeTicks )
56 {
57 #ifdef CBMC_PROOF_ASSUMPTION_HOLDS
58 #if ( ipconfigETHERNET_MINIMUM_PACKET_BYTES > 0 )
59 xNetworkBuffer.pucEthernetBuffer = malloc( ipconfigETHERNET_MINIMUM_PACKET_BYTES );
60 #else
61 xNetworkBuffer.pucEthernetBuffer = malloc( xRequestedSizeBytes );
62 #endif
63 #else
64 uint32_t malloc_size;
65 __CPROVER_assert( !__CPROVER_overflow_mult( 2, xRequestedSizeBytes ) );
66 __CPROVER_assume( malloc_size > 0 && malloc_size < 2 * xRequestedSizeBytes );
67 xNetworkBuffer.pucEthernetBuffer = malloc( malloc_size );
68 #endif
69 __CPROVER_assume( xNetworkBuffer.pucEthernetBuffer != NULL );
70
71 xNetworkBuffer.xDataLength = xRequestedSizeBytes;
72 return &xNetworkBuffer;
73 }
74
75
harness()76 void harness()
77 {
78 uint32_t ulIPAddress;
79
80 FreeRTOS_OutputARPRequest( ulIPAddress );
81 }
82