-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Check mbedtls_platform_zeroize() calls #8143
Changes from all commits
42b02a9
351a391
daddf11
7eced7d
d9572c0
b2fafa5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* mbedtls_config.h modifier that defines mbedtls_platform_zeroize() to be | ||
* memset(), so that the compile can check arguments for us. | ||
* Used for testing. | ||
*/ | ||
/* | ||
* Copyright The Mbed TLS Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License 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 <string.h> | ||
|
||
/* Define _ALT so we don't get the built-in implementation. The test code will | ||
* also need to define MBEDTLS_TEST_DEFINES_ZEROIZE so we don't get the | ||
* declaration. */ | ||
#define MBEDTLS_PLATFORM_ZEROIZE_ALT | ||
|
||
#define mbedtls_platform_zeroize(buf, len) memset(buf, 0, len) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5117,6 +5117,16 @@ support_build_cmake_custom_config_file () { | |
} | ||
|
||
|
||
component_build_zeroize_checks () { | ||
msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()" | ||
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. A side note, we've considered running clang-tidy and its I thought we had an open issue for clang-tidy but turns out we don't, I'll file one (as part of the huge tech debt backlog, so don't hold your breath). |
||
|
||
scripts/config.py full | ||
|
||
# Only compile - we're looking for sizeof-pointer-memaccess warnings | ||
make CC=gcc CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess" | ||
} | ||
|
||
|
||
component_test_zeroize () { | ||
# Test that the function mbedtls_platform_zeroize() is not optimized away by | ||
# different combinations of compilers and optimization flags by using an | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could define
MBEDTLS_TEST_DEFINES_ZEROIZE
in this file. It's ok if definingMBEDTLS_USER_CONFIG_FILE
(factor 1) to point to a file undertests
(factor 2) results in an insecure build. But needing both definitions is ok too, this isn't a thing we need to do often.