fix key update fail in non-blocking#16021
Conversation
|
Could you please submit a CLA? https://www.openssl.org/policies/cla.html |
|
ok,I sent a successfully signed pdf email yesterday. |
|
@t8m the CLA email always send fail, may I send other email address? |
|
@mattcaswell @kaduk Can you help review this PR? |
Yes, I spent some time looking at this yesterday, but need to spend a bit more time on it before I provide comments. |
|
I don't think the fix presented in this PR is the correct solution. There are two problems being addressed.
The root cause of this problem is a bug in the function openssl/ssl/record/rec_layer_s3.c Lines 201 to 227 in 53111a8 This goes wrong when we read a partial record, perform a key update operation (and hence end up calling The reset of the packet pointer in Author: Matt Caswell <[email protected]>
AuthorDate: Tue Jul 13 17:19:12 2021 +0100
Commit: Matt Caswell <[email protected]>
CommitDate: Tue Jul 13 17:19:12 2021 +0100
Don't reset the packet pointer in ssl3_setup_read_buffer
Sometimes this function gets called when the buffers have already been
set up. If there is already a partial packet in the read buffer then the
packet pointer will be set to an incorrect value. The packet pointer already
gets reset to the correct value when we first read a packet anyway, so we
don't also need to do it in ssl3_setup_read_buffer.
diff --git a/ssl/record/ssl3_buffer.c b/ssl/record/ssl3_buffer.c
index 861610a08b..daa175d98c 100644
--- a/ssl/record/ssl3_buffer.c
+++ b/ssl/record/ssl3_buffer.c
@@ -73,7 +73,6 @@ int ssl3_setup_read_buffer(SSL *s)
b->len = len;
}
- RECORD_LAYER_set_packet(&s->rlayer, &(b->buf[0]));
return 1;
}
IMO this is just incorrect API usage. If you get This is what the docs say about it: I think the docs need to be updated to be even more explicit, i.e. if you get It would also be sensible to immediately fail if Author: Matt Caswell <[email protected]>
AuthorDate: Tue Jul 13 17:44:44 2021 +0100
Commit: Matt Caswell <[email protected]>
CommitDate: Tue Jul 13 17:44:44 2021 +0100
Disallow SSL_key_update() if there are writes pending
If an application is halfway through writing application data it should
not be allowed to attempt an SSL_key_update() operation. Instead the
SSL_write() operation should be completed.
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
index c1e8e41f02..892a417d93 100644
--- a/ssl/ssl_lib.c
+++ b/ssl/ssl_lib.c
@@ -2262,6 +2262,11 @@ int SSL_key_update(SSL *s, int updatetype)
return 0;
}
+ if (RECORD_LAYER_write_pending(&s->rlayer)) {
+ ERR_raise(ERR_LIB_SSL, SSL_R_BAD_WRITE_RETRY);
+ return 0;
+ }
+
ossl_statem_set_in_init(s, 1);
s->key_update = updatetype;
return 1;With all of that said I think the tests presented in this PR are very useful and should be retained, with the exception of @yangyangtiantianlonglong - would you be willing to update this PR to incorporate my suggested fixes above, remove yours, and update the tests as I suggest? |
|
@mattcaswell Thank you for having to review it in detail. OK, I agree with the two points you made above, and I'll update the PR and test cases. |
|
@mattcaswell to make things easier, I'd suggest submitting your two fixes as a separate PR, which I'd approve immediately. After it is merged @yangyangtiantianlonglong can rebase this PR and remove the unneeded changes but keep the tests (with the necessary adjustment). |
No, if you call
Yes, ok. I can do that. |
Raised as #16077 |
|
yes, After merge in #16077,I will rebase this PR, commit testcase and doc. |
Fixes #13729 and #12485
SSL_R_BAD_LENGTH. The keyupdate is sending when local or peer is reading, that will get the error codeSSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC. The key update msg interrupted the complete encryption record.