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

fix(test): fix dangling pointers in cert verify test #4430

Merged
merged 8 commits into from
Feb 20, 2024

Conversation

jmayclin
Copy link
Contributor

@jmayclin jmayclin commented Feb 19, 2024

Description of changes:

This PR switches the config to a smaller scope to prevent the memory abuse that was previously occuring. Currently for each test case a new chain is added to the config and then freed. This means that the cert reference in the config is pointing to freed memory.

Testing:

I confirmed that after merging in the changes from this pr, 4407 no longer fails under ASAN.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

An unincluded compile definition resulted in the RSA_PSS test case never
being enabled.
@github-actions github-actions bot added the s2n-core team label Feb 19, 2024
@jmayclin jmayclin marked this pull request as ready for review February 19, 2024 21:25
- correct inventive usage of memory
@jmayclin jmayclin changed the title test: fix broken cert_verify test test: fix broken cert verify test Feb 19, 2024
@jmayclin jmayclin enabled auto-merge (squash) February 19, 2024 22:18
- fix more of the variable scopes while I'm at it
@jmayclin jmayclin requested a review from maddeleine February 19, 2024 23:45
Copy link
Contributor

@maddeleine maddeleine left a comment

Choose a reason for hiding this comment

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

Thanks for cleaning up this test!

tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
Comment on lines 307 to 309
test_scheme.sig_alg = test_case->sig_scheme->sig_alg;
/* 0xFFFF is an invalid iana value */
test_scheme.iana_value = 0xFFFF;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this what we were trying to test? From my reading, it sounds like we just wanted to make sure that we wouldn't verify a signature that wasn't of the type agreed on in the handshake. So a valid signature scheme, just not the one we agreed on.

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'll readily admit that I had some trouble following this test, but the previous behavior of this test did seem to be using the type that was agreed upon in the handshake?

verifying_conn->handshake_params.our_chain_and_key = cert_chain;
verifying_conn->handshake_params.server_cert_sig_scheme = &sig_scheme;
verifying_conn->handshake_params.client_cert_sig_scheme = &sig_scheme;

All of the handshake params are populated from the the sig_scheme inherited from the test case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure it's initially populating them the same, but this case was labeled "send and receive with mismatched signature algs" and was changing the sig_alg part of the scheme. The previous case was labeled "Send and receive with mismatched hash algs" and changed the hash_alg part of the scheme.

But then this case also sets an invalid iana, and you're now explicitly checking for S2N_ERR_INVALID_SIGNATURE_SCHEME. I don't think you've made the test more wrong, but I'm wondering if it was wrong to begin with.

What happens if you remove the "test_scheme.iana_value = 0xFFFF" line?

Copy link
Contributor

@lrstewart lrstewart Feb 20, 2024

Choose a reason for hiding this comment

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

What happens if you remove the "test_scheme.iana_value = 0xFFFF" line?

Oh, AND set test_scheme.sig_alg to something else. It's supposed to NOT match test_case->sig_scheme->sig_alg, if I'm understanding the test right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, AND set test_scheme.sig_alg to something else. It's supposed to NOT match test_case->sig_scheme-sig_alg, if I'm understanding the test right.

I can definitely do that, but that was the opposite of how the test case was previously written. If you change the sig_alg then the

        EXPECT_SUCCESS(s2n_tls13_cert_verify_send(verifying_conn));

fails.

Copy link
Contributor

Choose a reason for hiding this comment

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

For the "wrong hash" case, the test swaps out the hash_alg after the send, before the recv. Maybe that's what this test should be doing?

I'm just not sure what you're trying to test with your current version.

Copy link
Contributor Author

@jmayclin jmayclin Feb 20, 2024

Choose a reason for hiding this comment

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

I was just trying to explicitly match the current behavior of the test while making sure that the new test case was running, but I went ahead and made the suggested assertion change.

@jmayclin jmayclin requested a review from lrstewart February 20, 2024 00:43
- switch test assertions
This is currently blocking my other PR, so I'm narrowing the scope to
just fixing the dangling pointer references
@jmayclin jmayclin changed the title test: fix broken cert verify test fix(test): fix dangling pointers in cert verify test Feb 20, 2024
@jmayclin jmayclin disabled auto-merge February 20, 2024 19:37
- clang-format
@jmayclin jmayclin merged commit cb63493 into aws:main Feb 20, 2024
31 checks passed
@jmayclin jmayclin deleted the fix-cert-verify branch June 15, 2024 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants