Repository navigation
Fix for OpenSSL 3.2+. - #11501
Fix for OpenSSL 3.2+.#11501
Conversation
66bdda9 to
a64314e
Compare
Yeah, and it's initialized to something else. This change probably cause a memory leak and frees something that should not be freed by OpenSSL, if TFO is enabled. |
1f5b18a to
a6a7748
Compare
|
How about using |
It looks like it's deprecated in OpenSSL 3: https://www.openssl.org/docs/man3.2/man3/BIO_set_ex_data.html |
|
Ones for BIO are not, right? |
Ah, I see now, it's replaced by CRYPTO_new/set_ex_data in 3.0+. Maybe useable with some ninja #ifdefs. |
72a7400 to
bdda90d
Compare
| }; | ||
|
|
||
| #undef BIO_set_data | ||
| #define BIO_set_data(BIO, PTR) ink_assert(BIO_set_ex_data((BIO), ExData::idx(), (PTR)) == 1) |
There was a problem hiding this comment.
BIO_set_data and BIO_set_ex_data has different features. Overwriting BIO_set_data doesn't seem like a right thing to do at all. Could you tell me the motivation?
There was a problem hiding this comment.
These definitions only apply within this file (BIO_fastopen.cc). Boringssl does not provide BIO_set/get_ex_data. It seemed like the best approach to avoid further #ifdefs for OPENSSL_IS_BORINGSSL in this file.
There was a problem hiding this comment.
There was a problem hiding this comment.
It's only been supported for about 8 months: google/boringssl@2139aba . This commit does not seem to be in the version of BoringSSL we are using in the Rocky CI job. I guess we could add a CMake check for it.
There was a problem hiding this comment.
Bummer. I update BoringSSL once in a while so I didn't think it's unavailable.
I'd rather update the BoringSSL requirement if that's the reason. Oldest commit we currently require is https://boringssl.googlesource.com/boringssl/+/a1843d660b47116207877614af53defa767be46a
but I don't think there's a big reason to stick with the commit.
https://lists.apache.org/thread/d6ymfjhpmjogb5stnz92hwhhps909809
What do you think? Would it make the code simple?
| idx() | ||
| { | ||
| static int idx_ = []() -> int { | ||
| int i = CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, 0, nullptr, _new, _dup, _free); |
There was a problem hiding this comment.
I don't understand the necessity of ExData class in the first place, but even if it's needed, I don't see a reason to use CRYPTO_get_ex_new_index instead of BIO_get_ex_new_index.
There was a problem hiding this comment.
OK I will switch to BIO_get_ex_new_index, apparently it's not deprecated. The ExData class is for scoping and to handle C++ order of initialization fiasco.
|
What would be the issue if we simply use |
Not supported in Boring: |
| BIO_set_data(bio, ptr); | ||
| return 0; | ||
| case BIO_C_SET_FD: | ||
| BIO_set_shutdown(bio, int(larg)); |
There was a problem hiding this comment.
I had to add that code to avoid triggering this assert:
trafficserver/src/iocore/net/BIO_fastopen.cc
Line 100 in 68a5ee5
There was a problem hiding this comment.
There was a problem hiding this comment.
Ok, I misunderstood what "shutdown" means here, and now setting it makes sense. But why only on OpenSSL 3+?
The odd thing is that it looks like BIO_meth_get_ctrl returns the ctrl function for Socket BIO, and it sets the shutdown flag. How does that not happen?
There was a problem hiding this comment.
I need to retest this. Looking at the openssl code, it shouldn't be necessary.
There was a problem hiding this comment.
My testing was bogus, that change isn't necessary.
ef80a97 to
5eafc45
Compare
maskit
left a comment
There was a problem hiding this comment.
Overall looks good, but this does not build with a BoringSSL which has BIO_get_ex_new_index.
/Users/mkitajo/src/github.com/trafficserver/src/iocore/net/BIO_fastopen.cc:48:15: error: no matching function for call to 'BIO_get_ex_new_index'
int i = BIO_get_ex_new_index(0, nullptr, _new, _dup, _free);
^~~~~~~~~~~~~~~~~~~~
/Users/mkitajo/opt/boringssl/include/openssl/bio.h:819:20: note: candidate function not viable: no known conversion from 'void (void *, void *, CRYPTO_EX_DATA *, int, long, void *)' (aka 'void (void *, void *, crypto_ex_data_st *, int, long, void *)') to 'CRYPTO_EX_unused *' (aka 'int *') for 3rd argument
OPENSSL_EXPORT int BIO_get_ex_new_index(long argl, void *argp,
^
/Users/mkitajo/src/github.com/trafficserver/src/iocore/net/BIO_fastopen.cc:59:24: error: use of undeclared identifier 'CRYPTO_set_ex_data'
ink_release_assert(CRYPTO_set_ex_data(ad, idx_, nullptr) == 1);
^
/Users/mkitajo/src/github.com/trafficserver/src/iocore/net/BIO_fastopen.cc:65:24: error: use of undeclared identifier 'CRYPTO_set_ex_data'
ink_release_assert(CRYPTO_set_ex_data(ad, idx_, nullptr) == 1);
^
3 errors generated.
1380ddd to
73a5714
Compare
|
|
||
| #if defined(HAVE_BIO_GET_EX_NEW_INDEX) && defined(HAVE_BIO_GET_EX_DATA) && defined(HAVE_BIO_SET_EX_DATA) | ||
|
|
||
| // Thwart boringssl's thwarting of ex data for custom BIOs. Boring fails to export these functions. |
There was a problem hiding this comment.
I agree that BoringSSL's API is broken, but do we need to use these on code for BoringSSL?
There was a problem hiding this comment.
What alternative do you propose?
There was a problem hiding this comment.
Remove theses exports, and use empty callbacks for BoringSSL.
There was a problem hiding this comment.
I don't quite understand why OpenSSL says this though. BoringSSL doesn't say this.
When setting exdata, the pointer specified with a particular index is saved, and returned on a subsequent "get" call. If the application is going to release the data, it must make sure to set a NULL value at the index, to avoid likely double-free crashes.
There was a problem hiding this comment.
I don't know why either. In our case, the ex data is not a pointer to an allocated resource, so there is no risk of a double deallocation or a leak. I only clear the ex data pointer to know it was free'd when looking at a coredump.
81663e9 to
4017f39
Compare
| private: | ||
| #if BORINGLIKE | ||
| static const CRYPTO_EX_unused _new{}; | ||
| // Hopefully Boring intializes ex data pointers to nullptr by default. |
There was a problem hiding this comment.
How about setting nullptr in fastopen_create by BIO_set_ex_data? I'm not sure if this is really possible. It could be too early to call BIO_set_ex_data.
There was a problem hiding this comment.
Another option is setting nullptr after making the BIO on SSLNetVC side. It'd be a silly requirement if this BIO is publicly available for others though.
There was a problem hiding this comment.
I made a change in SSLNetVConnection.cc to initialize the ex data to either the destination address or nullptr for all BIOs using the fastopen methods.
|
|
||
| private: | ||
| #if BORINGLIKE | ||
| static const CRYPTO_EX_unused _new{}; |
There was a problem hiding this comment.
[ 80%] Building CXX object src/iocore/net/CMakeFiles/inknet.dir/BIO_fastopen.cc.o
/Users/mkitajo/src/github.com/trafficserver/src/iocore/net/BIO_fastopen.cc:56:15: error: no matching function for call to 'BIO_get_ex_new_index'
int i = BIO_get_ex_new_index(0, nullptr, _new, _dup, _free);
^~~~~~~~~~~~~~~~~~~~
/Users/mkitajo/opt/boringssl/include/openssl/bio.h:819:20: note: candidate function not viable: no known conversion from 'const CRYPTO_EX_unused' (aka 'const int') to 'CRYPTO_EX_unused *' (aka 'int *') for 3rd argument
OPENSSL_EXPORT int BIO_get_ex_new_index(long argl, void *argp,
^
1 error generated.
| static const CRYPTO_EX_unused _new{}; | |
| static constexpr CRYPTO_EX_unused *_new{nullptr}; |
It seems BIO user data is no longer set to nullptr.
|
Cherry-picked to v10.0.x |
It seems BIO user data is no longer set to nullptr. (cherry picked from commit 6bf342b)
It seems BIO user data is no longer set to nullptr. (cherry picked from commit 6bf342b) ----- Still needs configure modifications for non-Cmake build
* Fix for OpenSSL 3.2+. (#11501) It seems BIO user data is no longer set to nullptr. (cherry picked from commit 6bf342b) ----- Still needs configure modifications for non-Cmake build * Fix socket def * Chris' make fixes --------- Co-authored-by: Walt Karas <[email protected]>
It seems BIO user data is no longer initialized to nullptr.