Skip to content

Fix union initialization in PSA operations for GCC 15: new test helpers #136

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

Conversation

gilles-peskine-arm
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm commented Feb 6, 2025

New test helpers that will be used for the fix of Mbed-TLS/mbedtls#9814.

This just adds new functions that can be consumed by new test code (Mbed-TLS/mbedtls#9955 — I'm planning some history rewrite, but no code changes except to handle CI and review feedback). There will be a follow-up in the framework that adds new checks (bd33fb4) that will only pass once the library is fixed. (At the moment, the new checks fail after abort() for some operations, because in abort functions, we consistently clean up core metadata and sensitive data in operation objects, but we sometimes leave driver-specific metadata behind, which makes the setup-time is-all-zero check fail when an operation object is reused after abort/finish.)

PR checklist

  • TF-PSA-Crypto PR TODO (just to update the submodule)
  • development PR TODO (just to update the submodule)
  • 3.6 PR TODO (just to update the submodule)

@gilles-peskine-arm gilles-peskine-arm added needs-ci Needs to pass CI tests priority-high High priority - will be reviewed soon size-xs Estimated task size: extra small (a few hours at most) labels Feb 6, 2025
For each multipart or interruptible operation, define an initializer
function that simulates the minimum that `my_op_t op = {0}` guarantees in C.
That is, initialize most fields to 0, but set the fields that are unions to
a nonzero value. This simulates platforms where initializing a union to
`{0}` only initializes the first member, and thus reading from another
member can yield a nonzero value. In our operation structures, the union's
first member is an unused `dummy`, and the other members are
driver-specific, so we just make the whole union nonzero and this has to be
good enough for the setup functions in the core to cope.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This fixes -Wmissing-field-initializers complaints from Clang <=3.x.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Fix the build against development.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
@gilles-peskine-arm gilles-peskine-arm force-pushed the union-initialization-gcc15-framework-preliminaries branch from 3ca1d6a to 92f2203 Compare February 6, 2025 17:29
@gilles-peskine-arm gilles-peskine-arm added needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review and removed needs-ci Needs to pass CI tests labels Feb 6, 2025
@mpg mpg self-requested a review February 18, 2025 10:47
Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

#ifndef PSA_CRYPTO_TEST_DRIVERS_TEST_DRIVER_COMMON_H
#define PSA_CRYPTO_TEST_DRIVERS_TEST_DRIVER_COMMON_H

#include "mbedtls/build_info.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: currently this is already included by all users before deciding whether to include this file. But it doesn't hurt now and might be helpful later, so no objection.

@@ -145,6 +145,35 @@ const char *mbedtls_test_helper_is_psa_leaking(void);
while (0)


/** Initializer that doesn't set the embedded union to zero.
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: I grepped include/psa' for union {, found 15 occurrences, and verify that all of them chain to a structure that's in the list below - which has 3 extras entries that don't have a union yet. Some structures have more than one union, directly or indirectly, here the larger number of matches for union {` then structures below.

@github-project-automation github-project-automation bot moved this from In Development to Has Approval in Roadmap pull requests (new board) Apr 15, 2025
@mpg mpg added approved Design and code approved - may be waiting for CI or backports needs-ci Needs to pass CI tests and removed needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review labels Apr 23, 2025
@mpg
Copy link
Contributor

mpg commented Apr 23, 2025

@gilles-peskine-arm This is fully approved and has a green CI (Open), so I'm inclined to merge it. I see the description has "TODO" for the crypto/TLS/3.6 PRs but I don't think we need to wait for that in order to merge this one, considering it has a green CI already?

@gilles-peskine-arm
Copy link
Contributor Author

This just needs submodule updates in the consuming branches, then it can start being consumed. Merging it would be good (and thanks for the reviews). The CI result is three months old though, so I'll just merge main and rerun the CI to make sure this hasn't bitrotted.

@gilles-peskine-arm gilles-peskine-arm merged commit 4a3be27 into Mbed-TLS:main Apr 23, 2025
2 of 3 checks passed
@github-project-automation github-project-automation bot moved this from Has Approval to Done in Roadmap pull requests (new board) Apr 23, 2025
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 needs-ci Needs to pass CI tests priority-high High priority - will be reviewed soon size-xs Estimated task size: extra small (a few hours at most)
Development

Successfully merging this pull request may close these issues.

3 participants