Skip to content

Fix dlts_get_max_record_overhead()#19516

Closed
mattcaswell wants to merge 3 commits intoopenssl:masterfrom
mattcaswell:fix-encryption-growth
Closed

Fix dlts_get_max_record_overhead()#19516
mattcaswell wants to merge 3 commits intoopenssl:masterfrom
mattcaswell:fix-encryption-growth

Conversation

@mattcaswell
Copy link
Member

The calculation of the maximum DTLS record overhead was incorrect which means that we could exceed the MTU in some situations. We fix the calculation to take account of more sources of record overhead. We ignore potential overheads due to expansion after compression. At the time we make the calculation we don't know how long the record will be yet. However we can't accurately calculate the expansion without knowing that length. Just using a fallback expansion value for the worst case scenario doesn't help because that value is too high and is bigger than our fallback MTU size.

Testing this was tricky. The best solution I've come up with is to add an assert into statem_dtls.c to verify that we never exceed the MTU. Without the fix in dtls_get_max_record_overhead() this causes the existing test suite to fail. With the fix the test suite still passes.

While investigating this problem I spotted and fixed a different but related problem in tls_common.c. We calculates the maximum amount of growth we might expect to see during an encryption operation and reserve that many bytes in the WPACKET. Unfortunately the calculation was wrong which means that the encryption can overflow the amount of bytes reserved for it. In practice this isn't really an issue because the underlying buffer is still sufficiently large.

Stitched ciphersuites can grow by more during encryption than the code
allowed for. We fix the calculation and add an assert to check we go it
right.
We fix dtls_get_max_record_overhead() to give a better value for the max
record overhead. We can't realistically handle the compression case so we
just ignore that.
@mattcaswell mattcaswell added branch: master Applies to master branch approval: review pending This pull request needs review by a committer approval: otc review pending labels Oct 27, 2022
@github-actions github-actions bot added the severity: fips change The pull request changes FIPS provider sources label Oct 27, 2022
@t8m t8m added the triaged: bug The issue/pr is/fixes a bug label Oct 27, 2022
@mattcaswell
Copy link
Member Author

Ping for second review?

Copy link
Contributor

@paulidale paulidale left a comment

Choose a reason for hiding this comment

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

I'm sure I'd already reviewed this 😕

@paulidale paulidale added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Nov 3, 2022
@openssl-machine openssl-machine added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Nov 4, 2022
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

openssl-machine pushed a commit that referenced this pull request Nov 7, 2022
Stitched ciphersuites can grow by more during encryption than the code
allowed for. We fix the calculation and add an assert to check we go it
right.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Hugo Landau <[email protected]>
(Merged from #19516)
openssl-machine pushed a commit that referenced this pull request Nov 7, 2022
We fix dtls_get_max_record_overhead() to give a better value for the max
record overhead. We can't realistically handle the compression case so we
just ignore that.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Hugo Landau <[email protected]>
(Merged from #19516)
openssl-machine pushed a commit that referenced this pull request Nov 7, 2022
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Hugo Landau <[email protected]>
(Merged from #19516)
@mattcaswell
Copy link
Member Author

Oops. I might have prematurely merged this. CI failure looks potentially relevant. Investigating...

@mattcaswell mattcaswell closed this Nov 7, 2022
@mattcaswell
Copy link
Member Author

Why did openssl-machine add "ready to merge" when there was a CI failure??

@t8m
Copy link
Member

t8m commented Nov 7, 2022

Why did openssl-machine add "ready to merge" when there was a CI failure??

That's interesting. I've never seen such occurrence before.

@mattcaswell
Copy link
Member Author

Fix in #19622

beldmit pushed a commit to beldmit/openssl that referenced this pull request Dec 26, 2022
Stitched ciphersuites can grow by more during encryption than the code
allowed for. We fix the calculation and add an assert to check we go it
right.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Hugo Landau <[email protected]>
(Merged from openssl#19516)
beldmit pushed a commit to beldmit/openssl that referenced this pull request Dec 26, 2022
We fix dtls_get_max_record_overhead() to give a better value for the max
record overhead. We can't realistically handle the compression case so we
just ignore that.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Hugo Landau <[email protected]>
(Merged from openssl#19516)
beldmit pushed a commit to beldmit/openssl that referenced this pull request Dec 26, 2022
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Hugo Landau <[email protected]>
(Merged from openssl#19516)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Applies to master branch severity: fips change The pull request changes FIPS provider sources triaged: bug The issue/pr is/fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants