Skip to content

Conversation

@davidhorstmann-arm
Copy link
Contributor

@davidhorstmann-arm davidhorstmann-arm commented Oct 8, 2025

Guard against a potential API misuse. Currently, when mbedtls_ssl_get_verify_result() is called before attempting a handshake, it returns 0 indicating success.

Change this so that we initialize the result to 0xFFFFFFFF (indicating failure) when we first initialize the session object.

Fixes #10373

PR checklist

Please remove the segment/s on either side of the | symbol as appropriate, and add any relevant link/s to the end of the line.
If the provided content is part of the present PR remove the # symbol.

At initialization, set the verify_result field of the ssl session to
0xFFFFFFFF, indicating failure of the handshake. This prevents
mbedtls_ssl_get_verify_result() from indicating that certificate
verification has passed if it is called prior to the handshake
happening.

Signed-off-by: David Horstmann <[email protected]>
Write a testcase to get verify_result before we have performed a
handshake and make sure that it is initialised to a failure value.

Signed-off-by: David Horstmann <[email protected]>
@davidhorstmann-arm davidhorstmann-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 needs-ci Needs to pass CI tests size-s Estimated task size: small (~2d) labels Oct 8, 2025
@davidhorstmann-arm davidhorstmann-arm moved this from In Development to In Review in Non-roadmap pull requests Oct 8, 2025
@irwir
Copy link
Contributor

irwir commented Oct 19, 2025

Change this so that we initialize the result to 0xFFFFFFFF (indicating failure) when we first initialize the session object.

This solution could have been cleaner.
First, it uses magic value without a name.
Second, and more important, verify_result is essentially a collection of bit fields, but checks for individuls bits do not take into account possibility of having all bits set.

There are unused bits in 32-bit integer, it would be more appropriate to take one bit and give it a good name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci Needs to pass CI tests 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 size-s Estimated task size: small (~2d)

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

verify_result should default to failure

2 participants