Skip to content
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

Make MBEDTLS_CHECK_PARAMS usable without defining mbedtls_param_failed #2697

Conversation

gilles-peskine-arm
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm commented Jun 13, 2019

Tweak config.h and platform_util.h so that config.pl full also enables the definition of MBEDTLS_PARAM_FAILED as assert. Adapt all.sh so that invalid-parameter tests are executed, but programs don't need to provide an mbedtls_param_failed function. Fix #2671

I also included two small commits:

The primary goal of this PR is to unblock #1622.

This PR requires the crypto submodule to have the changes from ARMmbed/mbed-crypto#148. To pass CI, I include a commit that updates the submodule, which should be removed once the precursor PR has been merged into the submodule.

Backports:

Fix the dependency on libmbedcrypto.a, which is now located under
crypto.

Fix Mbed-TLS#2682
For unit tests and sample programs, CFLAGS=-m32 is enough to get a
32-bit build, because these programs are all compiled directly
from *.c to the executable in one shot. But with makefile rules that
first build object files and then link them, LDFLAGS=-m32 is also
needed.
Don't use the macro name assert. It's technically permitted as long as
<assert.h> is not included, but it's fragile, because it means the
code and any header that it includes must not include <assert.h>.
Introduce a new configuration option MBEDTLS_CHECK_PARAMS_ASSERT,
which is disabled by default. When this option is enabled,
MBEDTLS_PARAM_FAILED defaults to assert rather than to a call to
mbedtls_param_failed, and <assert.h> is included.

This fixes Mbed-TLS#2671 (no easy way to make MBEDTLS_PARAM_FAILED assert)
without breaking backward compatibility. With this change,
`config.pl full` runs tests with MBEDTLS_PARAM_FAILED set to assert,
so the tests will fail if a validation check fails, and programs don't
need to provide their own definition of mbedtls_param_failed().
All sample and test programs had a definition of mbedtls_param_failed.
This was necessary because we wanted to be able to build them in a
configuration with MBEDTLS_CHECK_PARAMS set but without a definition
of MBEDTLS_PARAM_FAILED. Now that we activate the sample definition of
MBEDTLS_PARAM_FAILED in config.h when testing with
MBEDTLS_CHECK_PARAMS set, this boilerplate code is no longer needed.
Copy link
Contributor

@Patater Patater left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can update to a crypto repo commit on the development branch now.

@@ -832,9 +832,21 @@ component_test_no_use_psa_crypto_full_cmake_asan() {
if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the commit message of commit "Add all.sh component that exercises invalid_param checks ", this sentence doesn't make sense.

"Add a component to all.sh that enables MBEDTLS_CHECK_PARAMS but disables MBEDTLS_CHECK_PARAMS_ASSERT doesn't define MBEDTLS_PARAM_FAILED so that these tests are exercised."

Should this be like so? (I only added an "and".)

"Add a component to all.sh that enables MBEDTLS_CHECK_PARAMS but disables MBEDTLS_CHECK_PARAMS_ASSERT and doesn't define MBEDTLS_PARAM_FAILED so that these tests are exercised."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this and reworded the commit message to make it easier to read.

@@ -832,9 +832,21 @@ component_test_no_use_psa_crypto_full_cmake_asan() {
if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
}

component_test_check_params_tests () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest a more descriptive name, like component_test_check_mbedtls_param_failed(). It's a bit verbose if you also add "tests" into the name to describe that this only runs the tests. I think it more important to emphasize that it is testing the mbedtls_param_failed() function, more so than that this runs only the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the only component that runs the tests that verify that calls to API functions that pass invalid parameters result in a call to MBEDTLS_PARAM_FAILED. I renamed it to test_check_params_functionality.

With the change to the full config, there were no longer any tests
that exercise invalid-parameter behavior. The test suite exercises
invalid-parameter behavior by calling TEST_INVALID_PARAM and friends,
relying on the test suite's mbedtls_check_param function. This
function is only enabled if MBEDTLS_CHECK_PARAMS is defined but not
MBEDTLS_CHECK_PARAMS_ASSERT.

Add a component to all.sh that enables MBEDTLS_CHECK_PARAMS but
disables MBEDTLS_CHECK_PARAMS_ASSERT and doesn't define
MBEDTLS_PARAM_FAILED. This way, the xxx_invalid_param() tests do run.
Since sample programs don't provide a mbedtls_check_param function,
this component doesn't build the sample programs.
@gilles-peskine-arm gilles-peskine-arm force-pushed the check_params-test_without_function-development branch from 09586b6 to adcde5e Compare June 14, 2019 11:10
@gilles-peskine-arm
Copy link
Contributor Author

I removed the commit with the crypto submodule change. Expect failures on the pr-head job but the pr-merge job should succeed.

I also modified the all.sh commit.

@Patater
Copy link
Contributor

Patater commented Jun 14, 2019

We still need the commit to update the submodule in this PR (or some other one). It doesn't need to point at a development branch, but should point at the current head of crypto/development.

Update to the merge of "Make test suites compatible with #include <assert.h>"
@gilles-peskine-arm
Copy link
Contributor Author

Oh right. Submodule updated.

@Patater Patater removed the needs-preceding-pr Requires another PR to be merged first label Jun 14, 2019
@Patater
Copy link
Contributor

Patater commented Jun 14, 2019

ARMmbed/mbed-crypto#148 has been merged. Removing label "needs: preceding PR".

Copy link
Contributor

@Patater Patater left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gilles-peskine-arm gilles-peskine-arm added needs-backports Backports are missing or are pending review and approval. and removed needs-review Every commit must be reviewed by at least two team members, labels Jun 17, 2019
@RonEld
Copy link
Contributor

RonEld commented Jun 17, 2019

I believe this should also fix ARMmbed/mbed-os#9193

Please check with on target tests as well

@Patater Patater added approved Design and code approved - may be waiting for CI or backports and removed needs-backports Backports are missing or are pending review and approval. labels Jun 18, 2019
@Patater Patater merged commit 3097a71 into Mbed-TLS:development Jun 21, 2019
@Patater Patater mentioned this pull request Jun 21, 2019
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports bug component-platform Portability layer and build scripts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

make rebuilds programs config.pl full or just turning on MBEDTLS_CHECK_PARAMS breaks the build
4 participants