Repository navigation
Add a test for TLS pipelining - #19456
mattcaswell wants to merge 9 commits into
Conversation
TLS pipelining provides the ability for libssl to read or write multiple records in parallel. It requires special ciphers to do this, and there are currently no built-in ciphers that provide this capability. However, the dasync engine does have such a cipher, so we add a test for this capability using that engine.
|
This went in surprisingly smoothly and easily. Given the length of time this code has been there without a test, and the recent refactor of the record layer - I was expecting problems. |
|
It would be a nice feature to extend the pipelining to TLSv1.3 and to provider based ciphers (DTLS could be done but will require new public API calls). It would also be quite neat to utilise the newly added thread pooling functionality to make our existing ciphers pipeline capable in the default provider. |
|
The address sanitizer disagrees :) |
…lled The pipeline input/output buf arrays must remain accessible to the EVP_CIPHER_CTX until EVP_Cipher is subsequently called. This fixes an asan error discovered by the newly added pipeline test.
Should be fixed now. |
|
Typos fixed. |
|
Ping @openssl/committers for second review? |
tmshort
left a comment
There was a problem hiding this comment.
Mostly just a question on the use of ENGINE in the master branch, and whether this testing is sufficient (given the small data size).
| char buf[80]; | ||
| ENGINE *e; | ||
|
|
||
| if (!TEST_ptr(e = ENGINE_by_id("dasync"))) |
There was a problem hiding this comment.
I still don't get the support level of engines in the master branch. Are they fully deprecated? Should this not be a provider or something else? Feels as though we're taking two steps back to advance one step.
There was a problem hiding this comment.
Are they fully deprecated
Yes
Should this not be a provider or something else?
Yes, really this test should be using a provider. Unfortunately at the moment we are in the slightly strange situation that libssl pipeline support is not deprecated, but in order to use that support you must use a pipeline capable cipher - and we have not added the support for pipeline capable ciphers into providers. So the only way you can possibly use the non-deprecated libssl pipeline support is by using a deprecated ENGINE. I consider this an accidental omission which we should fix. But that goes way beyond what I was planning to do with this PR, i.e. just make sure what we've currently got isn't broken.
|
24 hours has passed since 'approval: done' was set, but this PR has failing CI tests. Once the tests pass it will get moved to 'approval: ready to merge' automatically, alternatively please review and set the label manually. |
During read pipelining we must ensure that the buffer is sufficiently large to read enough data to fill our pipelines. We also remove some code that moved data to the start of the packet if we can. This was unnecessary because of later code which would end up moving it anyway. The earlier move was also incorrect in the case that |clearold| was 0. This would cause the read pipelining code to fail with sufficiently large records.
Document the effect on the internal read buffer when using pipelining.
|
Adding the additional testing to this as suggested by @tmshort was a worthwhile exercise since it highlighted a couple of problems in the read pipelining implementation. I've fixed those issues and also made a tweak to the documentation as a result. I suspect that the issues I fixed predated the record layer refactor so its possible those issues exist in 3.0 and 1.1.1 - but I've not investigated that. |
|
This now needs re-review since there have been some significant changes since the original version. |
|
All feedback addressed. @t8m - please take another look. |
|
Ping for second review @openssl/committers |
| EVP_CIPHER_CTX *ds; | ||
| size_t reclen[SSL_MAX_PIPELINES]; | ||
| unsigned char buf[SSL_MAX_PIPELINES][EVP_AEAD_TLS1_AAD_LEN]; | ||
| unsigned char *data[SSL_MAX_PIPELINES]; |
There was a problem hiding this comment.
Why was this moved to the outer scope? It's the only change in this function.
There was a problem hiding this comment.
This was due to use-after-scope error picked up by asan. The buffers set by EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS must still be valid at the point that we call EVP_CipherUpdate - which was not the case when this was in its original location.
| } else if (align != 0 && left >= SSL3_RT_HEADER_LENGTH) { | ||
| /* | ||
| * check if next packet length is large enough to justify payload | ||
| * alignment... | ||
| */ | ||
| pkt = rb->buf + rb->offset; | ||
| if (pkt[0] == SSL3_RT_APPLICATION_DATA | ||
| && (pkt[3] << 8 | pkt[4]) >= 128) { | ||
| /* | ||
| * Note that even if packet is corrupted and its length field | ||
| * is insane, we can only be led to wrong decision about | ||
| * whether memmove will occur or not. Header values has no | ||
| * effect on memmove arguments and therefore no buffer | ||
| * overrun can be triggered. | ||
| */ | ||
| memmove(rb->buf + align, pkt, left); | ||
| rb->offset = align; | ||
| } | ||
| } |
There was a problem hiding this comment.
Does this special case no longer apply?
There was a problem hiding this comment.
This memmove was originally intended as an optimisation. It ensures that the payload data bytes are properly aligned for maximum assembler performance. There are two cases to consider: one where clearold is 0 and one where clearold is 1.
In the case that clearold is 0 this means "don't invalidate data earlier in the buffer because we're still using it". So this memove is just wrong in that instance. We must not move the data to an earlier position in the buffer because we're still using it. This actually was causing a problem in the pipelining case because we have multiple pipelines of data all using the same buffer - so this memmove was resulting in "bad record mac" error.
In the case that clearold is 1 it would still be a valid optimisation - but is entirely redundant because of the memmove that occurs a few lines later. This always occurs if clearold is 1 and the data is not already aligned.
So, since this code is either wrong or redundant (depending on the value of clearold) it can safely be removed completely.
tmshort
left a comment
There was a problem hiding this comment.
Thanks for the explanations @mattcaswell
|
This pull request is ready to merge |
|
Merged to master branch. Thank you. |
You beat me to it! I was just about to "git push"! |
TLS pipelining provides the ability for libssl to read or write multiple records in parallel. It requires special ciphers to do this, and there are currently no built-in ciphers that provide this capability. However, the dasync engine does have such a cipher, so we add a test for this capability using that engine. Reviewed-by: Hugo Landau <[email protected]> Reviewed-by: Todd Short <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from #19456)
…lled The pipeline input/output buf arrays must remain accessible to the EVP_CIPHER_CTX until EVP_Cipher is subsequently called. This fixes an asan error discovered by the newly added pipeline test. Reviewed-by: Hugo Landau <[email protected]> Reviewed-by: Todd Short <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from #19456)
During read pipelining we must ensure that the buffer is sufficiently large to read enough data to fill our pipelines. We also remove some code that moved data to the start of the packet if we can. This was unnecessary because of later code which would end up moving it anyway. The earlier move was also incorrect in the case that |clearold| was 0. This would cause the read pipelining code to fail with sufficiently large records. Reviewed-by: Hugo Landau <[email protected]> Reviewed-by: Todd Short <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from #19456)
Document the effect on the internal read buffer when using pipelining. Reviewed-by: Hugo Landau <[email protected]> Reviewed-by: Todd Short <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from #19456)
TLS pipelining provides the ability for libssl to read or write multiple records in parallel. It requires special ciphers to do this, and there are currently no built-in ciphers that provide this capability. However, the dasync engine does have such a cipher, so we add a test for this capability using that engine. Reviewed-by: Hugo Landau <[email protected]> Reviewed-by: Todd Short <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#19456)
…lled The pipeline input/output buf arrays must remain accessible to the EVP_CIPHER_CTX until EVP_Cipher is subsequently called. This fixes an asan error discovered by the newly added pipeline test. Reviewed-by: Hugo Landau <[email protected]> Reviewed-by: Todd Short <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#19456)
During read pipelining we must ensure that the buffer is sufficiently large to read enough data to fill our pipelines. We also remove some code that moved data to the start of the packet if we can. This was unnecessary because of later code which would end up moving it anyway. The earlier move was also incorrect in the case that |clearold| was 0. This would cause the read pipelining code to fail with sufficiently large records. Reviewed-by: Hugo Landau <[email protected]> Reviewed-by: Todd Short <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#19456)
Document the effect on the internal read buffer when using pipelining. Reviewed-by: Hugo Landau <[email protected]> Reviewed-by: Todd Short <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#19456)
TLS pipelining provides the ability for libssl to read or write multiple records in parallel. It requires special ciphers to do this, and there are currently no built-in ciphers that provide this capability. However, the dasync engine does have such a cipher, so we add a test for this capability using that engine.
Checklist