Ensure our buffer allocation allows for the Explicit IV (1.1.1)#20087
Ensure our buffer allocation allows for the Explicit IV (1.1.1)#20087mattcaswell wants to merge 4 commits intoopenssl:OpenSSL_1_1_1-stablefrom
Conversation
Test that sending large app data records works correctly.
Some ciphers/protocol versions have an explicit IV. We need to make sure we have sufficient room for it in the underlying buffer.
|
How does this relate to #19710 ? |
|
The CI failures here are quite strange and apparently unrelated - but there are a lot of them. |
Unclear |
|
#19930 would fix the CI failures. |
But #19585 does not address the similar issue with DTLS, Lines 560 to 579 in d90907d so at least as for the 1.1.1 version is concerned, that is RC4-HMAC-MD5, AES-128-CBC-HMAC-SHA1, AES-256-CBC-HMAC-SHA1, AES-128-CBC-HMAC-SHA256, and AES-256-CBC-HMAC-SHA256, So I think there was no real issue, at all, at least for 1.1.1 as you can see that #19710 passes even with your new test case and with #19585 reverted. On the other hand #19710 addresses TLS and DTLS, So to me this looks like first the reservation size is made larger by #19585, and Well additionally, #19585 has quite some history: It was first merged to master as 830eae6 Sorry, but how much more do you guys need to consider a revert? |
|
#19585 and #19710 have different objectives to each other. One is not a replacement for the other. #19585 is about addressing a bug in the WPACKET accounting logic. The #19585 addresses a bug where insufficient bytes are reserved and the allocate call uses more than was reserved. #19710 does not address this WPACKET accounting error. Instead it adds checks in the encryption code to ensure that it does not overflow the underlying buffer before it writes out those bytes. Adding overflow checks before writing out the bytes is not a bad idea IMO, but it should do so using the mechanism that we have implemented for this: i.e. WPACKET. By checking the underlying buffer directly you are just avoiding the mechanism we have put in place for this task and so doesn't seem like the right solution to me. If you checked in tls1_enc that the number of bytes didn't exceed the amount reserved in the WPACKET then that would be a much better solution - but then you would immediately find that you would still need #19585 in place to fix the reservation bug. #19710 does not fix a bug, whereas #19585 does. #19710 does add some useful additional hardening (but in the wrong way IMO). I'm not sure that #19710 can be justified in a stable release (and less so in 1.1.1).
The DTLS code does not have the WPACKET accounting error bug that the TLS code has because it does not use WPACKET. This is a bad thing IMO, but not something to be addressed in 1.1.1. It has been addressed in master where the TLS and DTLS code has been harmonised and WPACKET is used for both. Since the DTLS code does not have the bug that #19585 fixes, it is not relevant there. The additional hardening introduced by #19710 could still be useful (but see my comments above) - but it does not address a bug. The hardening in #19710 does not cover TLSv1.3 or SSLv3.
This PR actually addresses a slightly different problem to #19585. I consider it to be fixing a latent bug that the changes in #19585 highlighted. The underlying buffer is sized based on certain assumptions, i.e. the buffer includes an allowance for:
The last factor includes an allowance for:
The bug here is that there is no allowance made for an explicit IV. We've been lucky enough to get away with it by virtue of the fact that the allowance for the MAC/tag is sized at 64 bytes. However the biggest MAC that we ever actually use is SHA-384 - which requires 48 bytes. That gives us 16 spare, which just happens to be the size of an explicit IV. But this is an accident and works by luck. An alternative fix to that proposed in this PR is to adjust the assumptions that we make and redefine IMO just adding an additional 16 bytes to the underlying buffer is much simpler and the better solution - even though they are strictly speaking redundant. Having an extra 16 bytes in case of "accidents" is probably not a bad thing anyway. #19710 does not address this problem at all. It works by virtue of the fact that the underlying buffer just happens to be big enough by chance due to the reasons explained above.
This is a good point. It wouldn't be a bad idea to extend the test to DTLS as well.
This is not correct. Explicit IV is relevant to TLS 1.1, TLS 1.2 and DTLS, but not TLSv1.3. It was introduced in TLS 1.1 due to a known vulnerability in TLSv1.0/SSLv3 where the IV for each record is the last block of the preceding record (meaning it is predictable). This later gave rise to the BEAST attack. Explicit IV is only applicable to CBC ciphersuites. Since TLSv1.3 doesn't have any of those it is not relevant there. However, the buffers (in 1.1.1) are allocated early in the handshake before we know what protocol version/ciphersuites we are going to be using. So allocating a 16 byte allowance for the explicit IV in case we subsequently negotiate something that requires it seems sensible. |
I've added a commit to do that. |
Thanks, I've added your test to #19710 and it works there too. |
No, that is a complete misunderstanding. So yes, the memory reservation currently reilies heavily on the fact that CBC ciphers |
|
This pull request is ready to merge |
|
Merged to 1.1.1. Thank you. |
Test that sending large app data records works correctly. Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Hugo Landau <[email protected]> (Merged from #20087)
Some ciphers/protocol versions have an explicit IV. We need to make sure we have sufficient room for it in the underlying buffer. Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Hugo Landau <[email protected]> (Merged from #20087)
Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Hugo Landau <[email protected]> (Merged from #20087)
Test that sending large app data records works correctly. Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Hugo Landau <[email protected]> (Merged from openssl#20087)
Some ciphers/protocol versions have an explicit IV. We need to make sure we have sufficient room for it in the underlying buffer. Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Hugo Landau <[email protected]> (Merged from openssl#20087)
Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Hugo Landau <[email protected]> (Merged from openssl#20087)
Some ciphers/protocol versions have an explicit IV. We need to make sure we
have sufficient room for it in the underlying buffer.
This is a backport of #20085.
This fixes a regression introduced by #19585 and should be merged before any 1.1.1t is released.