-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Memory-safety proofs for aws_byte_buf (#331)
* Memory-safety proofs for aws_byte_buf Adds invariants and proof harnesses for the following functions: - aws_byte_buf_append - aws_byte_buf_append_dynamic - aws_byte_buf_append_with_lookup - aws_byte_buf_clean_up - aws_byte_buf_from_array - aws_byte_buf_from_empty_array - aws_byte_buf_init - aws_byte_buf_init_copy_from_cursor - aws_byte_buf_reserve - aws_byte_buf_secure_zero Signed-off-by: Felipe R. Monteiro <[email protected]>
- Loading branch information
1 parent
f0a8edf
commit 667ebed
Showing
39 changed files
with
481 additions
and
134 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use | ||
# this file except in compliance with the License. A copy of the License is | ||
# located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
########## | ||
|
||
# Sufficently long to get full coverage on the aws_byte_buf and aws_byte_cursor APIs | ||
# short enough that all proofs complete in less than a minute | ||
MAX_BUFFER_SIZE ?= 10 | ||
|
||
DEFINES += -DMAX_BUFFER_SIZE=$(MAX_BUFFER_SIZE) |
This file contains 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 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 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
jobos: ubuntu16 | ||
cbmcflags: "--bounds-check;--pointer-check;--div-by-zero-check;--signed-overflow-check;--unsigned-overflow-check;--pointer-overflow-check;--undefined-shift-check;--float-overflow-check;--nan-check;--unwinding-assertions;--function;aws_byte_buf_append_harness" | ||
cbmcflags: "--bounds-check;--pointer-check;--div-by-zero-check;--signed-overflow-check;--unsigned-overflow-check;--pointer-overflow-check;--undefined-shift-check;--float-overflow-check;--nan-check;--unwinding-assertions;--unwindset;memcpy_impl.0:11;--unwind;1" | ||
goto: aws_byte_buf_append_harness.goto | ||
expected: "SUCCESSFUL" |
This file contains 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 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 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
jobos: ubuntu16 | ||
cbmcflags: "--bounds-check;--div-by-zero-check;--float-overflow-check;--nan-check;--pointer-check;--pointer-overflow-check;--signed-overflow-check;--undefined-shift-check;--unsigned-overflow-check;--unwind;1;--unwinding-assertions;--object-bits;8" | ||
cbmcflags: "--bounds-check;--div-by-zero-check;--float-overflow-check;--nan-check;--pointer-check;--pointer-overflow-check;--signed-overflow-check;--undefined-shift-check;--unsigned-overflow-check;--unwinding-assertions;--unwind;1" | ||
goto: aws_byte_buf_append_dynamic_harness.goto | ||
expected: "SUCCESSFUL" |
This file contains 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 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
2 changes: 1 addition & 1 deletion
2
.cbmc-batch/jobs/aws_byte_buf_append_with_lookup/cbmc-batch.yaml
This file contains 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
jobos: ubuntu16 | ||
cbmcflags: "--bounds-check;--pointer-check;--div-by-zero-check;--signed-overflow-check;--unsigned-overflow-check;--pointer-overflow-check;--undefined-shift-check;--float-overflow-check;--nan-check;--unwinding-assertions;--unwindset;aws_byte_buf_append_with_lookup.0:11;--function;aws_byte_buf_append_with_lookup_harness" | ||
cbmcflags: "--bounds-check;--pointer-check;--div-by-zero-check;--signed-overflow-check;--unsigned-overflow-check;--pointer-overflow-check;--undefined-shift-check;--float-overflow-check;--nan-check;--unwinding-assertions;--unwindset;aws_byte_buf_append_with_lookup.0:11;--unwind;1" | ||
goto: aws_byte_buf_append_with_lookup_harness.goto | ||
expected: "SUCCESSFUL" |
This file contains 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use | ||
# this file except in compliance with the License. A copy of the License is | ||
# located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
########### | ||
include ../Makefile.aws_byte_buf | ||
|
||
MAX_BUFFER_SIZE=40 | ||
|
||
# This bound allows us to reach 100% coverage rate | ||
UNWINDSET += memset_impl.0:$(shell echo $$(($(MAX_BUFFER_SIZE) + 1))) | ||
|
||
CBMCFLAGS += | ||
|
||
DEPENDENCIES += $(HELPERDIR)/source/make_common_data_structures.c | ||
DEPENDENCIES += $(HELPERDIR)/source/proof_allocators.c | ||
DEPENDENCIES += $(HELPERDIR)/stubs/error.c | ||
DEPENDENCIES += $(HELPERDIR)/stubs/memset_override.c | ||
DEPENDENCIES += $(SRCDIR)/source/byte_buf.c | ||
DEPENDENCIES += $(SRCDIR)/source/common.c | ||
|
||
ENTRY = aws_byte_buf_clean_up_harness | ||
########### | ||
|
||
include ../Makefile.common |
30 changes: 30 additions & 0 deletions
30
.cbmc-batch/jobs/aws_byte_buf_clean_up/aws_byte_buf_clean_up_harness.c
This file contains 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
#include <aws/common/byte_buf.h> | ||
#include <proof_helpers/make_common_data_structures.h> | ||
|
||
void aws_byte_buf_clean_up_harness() { | ||
struct aws_byte_buf buf; | ||
|
||
ensure_byte_buf_has_allocated_buffer_member(&buf); | ||
__CPROVER_assume(aws_byte_buf_is_valid(&buf)); | ||
|
||
aws_byte_buf_clean_up(&buf); | ||
assert(buf.allocator == NULL); | ||
assert(buf.buffer == NULL); | ||
assert(buf.len == 0); | ||
assert(buf.capacity == 0); | ||
} |
4 changes: 2 additions & 2 deletions
4
...s/aws_byte_buf_from_c_str/cbmc-batch.yaml → ...obs/aws_byte_buf_clean_up/cbmc-batch.yaml
This file contains 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
jobos: ubuntu16 | ||
cbmcflags: "--bounds-check;--pointer-check;--div-by-zero-check;--signed-overflow-check;--unsigned-overflow-check;--pointer-overflow-check;--undefined-shift-check;--float-overflow-check;--nan-check;--unwinding-assertions;--unwindset;strlen.0:33;--function;aws_byte_buf_from_c_str_harness" | ||
goto: aws_byte_buf_from_c_str_harness.goto | ||
cbmcflags: "--bounds-check;--pointer-check;--div-by-zero-check;--signed-overflow-check;--unsigned-overflow-check;--pointer-overflow-check;--undefined-shift-check;--float-overflow-check;--nan-check;--unwinding-assertions;--unwindset;memset_impl.0:41;--unwind;1" | ||
goto: aws_byte_buf_clean_up_harness.goto | ||
expected: "SUCCESSFUL" |
This file contains 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
38 changes: 38 additions & 0 deletions
38
.cbmc-batch/jobs/aws_byte_buf_from_array/aws_byte_buf_from_array_harness.c
This file contains 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
#include <aws/common/byte_buf.h> | ||
#include <proof_helpers/make_common_data_structures.h> | ||
|
||
void aws_byte_buf_from_array_harness() { | ||
/* parameters */ | ||
size_t length; | ||
uint8_t *array; | ||
|
||
/* assumptions */ | ||
ASSUME_VALID_MEMORY_COUNT(array, length); | ||
|
||
/* operation under verification */ | ||
struct aws_byte_buf buf = aws_byte_buf_from_array(array, length); | ||
|
||
/* assertions */ | ||
assert(aws_byte_buf_is_valid(&buf)); | ||
assert(buf.len == length); | ||
assert(buf.capacity == length); | ||
assert(buf.allocator == NULL); | ||
if (buf.buffer) { | ||
assert_bytes_match(buf.buffer, array, buf.len); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
jobos: ubuntu16 | ||
cbmcflags: "--bounds-check;--pointer-check;--div-by-zero-check;--signed-overflow-check;--unsigned-overflow-check;--pointer-overflow-check;--undefined-shift-check;--float-overflow-check;--nan-check;--unwinding-assertions;--unwind;1" | ||
goto: aws_byte_buf_from_array_harness.goto | ||
expected: "SUCCESSFUL" |
Oops, something went wrong.