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

mbedtls::x509::certificate::Certificate::verify() segfaults when passing in an empty certificate chain to verify #307

Closed
3 tasks done
Taowyoo opened this issue Aug 21, 2023 · 0 comments · Fixed by #308, #309 or #310
Closed
3 tasks done
Assignees
Labels

Comments

@Taowyoo
Copy link
Collaborator

Taowyoo commented Aug 21, 2023

The first argument to the x509_crt_verify() call is chain.inner_ffi_mut(). If this chain is an empty MbedtlsList (e.g., one created using MbedtlsList::new()), then the inner_ffi_mut() call will return a null pointer. This null pointer will be dereferenced inside the x509_crt_verify() call, causing a segmentation fault.

Although the documentation of mbedtls_x509_crt_verify() doesn’t state it explicitly, it looks like passing a null pointer for its first argument is not allowed. Hence this appears to be a rust-mbedtls bug, not an mbedtls bug.

Proposed solution: modify the verify_ex() function in rust-mbedtls to return a X509BadInputData error if the input chain is empty.

The fix PR need to back-port to 0.9 and 0.8:

  • master
  • v0.9
  • v0.8
@Taowyoo Taowyoo added the bug label Aug 21, 2023
@Taowyoo Taowyoo self-assigned this Aug 21, 2023
@Taowyoo Taowyoo linked a pull request Aug 21, 2023 that will close this issue
bors bot added a commit that referenced this issue Aug 22, 2023
308: fix: return error when verify empty cert chain r=raoulstrackx a=Taowyoo

For #307 on master.

Several back-port PRs needed for older versions.

Co-authored-by: Yuxiang Cao <[email protected]>
bors bot added a commit that referenced this issue Aug 22, 2023
308: fix: return error when verify empty cert chain r=[raoulstrackx] a=Taowyoo

For #307 on master.

Several back-port PRs needed for older versions.

Co-authored-by: Yuxiang Cao <[email protected]>
bors bot added a commit that referenced this issue Aug 22, 2023
308: fix: return error when verify empty cert chain r=Taowyoo a=Taowyoo

For #307 on master.

Several back-port PRs needed for older versions.

Co-authored-by: Yuxiang Cao <[email protected]>
bors bot added a commit that referenced this issue Aug 30, 2023
308: fix: return error when verify empty cert chain r=Taowyoo a=Taowyoo

For #307 on master.

Several back-port PRs needed for older versions.

Only return X509BadInputData error when candidate certificate chain is empty because:
- underlying `mbedtls` does not have null pointer check on it.
- underlying `mbedtls` has null pointer check on `trust_ca` chain during the process of finding parent certificate in the chain.

Co-authored-by: Yuxiang Cao <[email protected]>
bors bot added a commit that referenced this issue Aug 30, 2023
308: fix: return error when verify empty cert chain r=Taowyoo a=Taowyoo

For #307 on master.

Several back-port PRs needed for older versions.

Only return X509BadInputData error when candidate certificate chain is empty because:
- underlying `mbedtls` does not have null pointer check on it.
- underlying `mbedtls` has null pointer check on `trust_ca` chain during the process of finding parent certificate in the chain.

312: Update CI r=Taowyoo a=Taowyoo

Refactor is prime test
Fix bors status problem

Co-authored-by: Yuxiang Cao <[email protected]>
@bors bors bot closed this as completed in #308 Aug 30, 2023
@Taowyoo Taowyoo reopened this Aug 30, 2023
@Taowyoo Taowyoo closed this as completed Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment