Skip to content

Correctly initialize values - #1428

Merged
willco007 merged 4 commits into
masterfrom
willco007-patch-1
Jul 22, 2024
Merged

willco007 merged 4 commits into
masterfrom
willco007-patch-1

Conversation

@willco007

Copy link
Copy Markdown
Member

Fix regression with commit from #1421

willco007 referenced this pull request Jul 22, 2024
While it's moved to pk_internal, it won't removed in mbedTLS 3.6 LTS
so it's safe to redeclare it on our side to find it.

This is implementing emergency fix suggested from
2e4c5ec#commitcomment-141379351

Follow-up to e973493 #1393
Follow-up to 2e4c5ec #1349
Closes #1421
@willco007
willco007 merged commit 1701d5c into master Jul 22, 2024
@willco007
willco007 deleted the willco007-patch-1 branch July 22, 2024 16:57
@vszakats

vszakats commented Jul 23, 2024 •

Copy link
Copy Markdown
Member

@willco007: It just dawned on me that these initializations were pretty much always missing from the code. The crashes you've seen might have a different reason. Unless mbedTLS changed how the mbedtls_pk_load_file API behaves and now leaves these values uninitialized on failure.

This PR is fine either way.

Ref: 2e4c5ec

@willco007

Copy link
Copy Markdown
Member Author

The crash I saw was reported by the fuzzer but marked as not reproducible, however it first appeared from the commit for #1421. It seems it just happened to hit the uninitialized variables on that run??

@vszakats

vszakats commented Jul 23, 2024 •

Copy link
Copy Markdown
Member

#1421 basically reverted the earlier 2e4c5ec, with the manual declaration added for the most recent mbedTLS version.

It gets more interesting because this was indeed wrong, but it was wrong all along before these commits: mbedTLS does indeed leave these variables unitialized on failure, by looking at 3.5.0:
https://github.com/Mbed-TLS/mbedtls/blob/1ec69067fa1351427f904362c1221b31538c8b57/library/pkparse.c#L77-L94

One explanantion is that the manual declaration triggered the fuzzer to extend into this mbedTLS function.

Makes me think how many more of these may exist out of view of the fuzzer.

edit: it's probably a good idea to always initialize variables passed by address.

@vszakats vszakats added the bug label Jul 23, 2024
@willco007

willco007 commented Jul 23, 2024 •

Copy link
Copy Markdown
Member Author

I quickly scrubbed mbedtls.c and didn't see any more uninitialized variables, but I did find this error case #1430.

@vszakats

Copy link
Copy Markdown
Member

Nice!

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.

2 participants