[MDEV-25785] Add support for OpenSSL 3.0 Created: 2021-05-26  Updated: 2023-08-07  Resolved: 2022-01-20

Status: Closed
Project: MariaDB Server
Component/s: Compiling
Fix Version/s: 10.8.1

Type: Task Priority: Blocker
Reporter: Honza Horak Assignee: Sergei Golubchik
Resolution: Fixed Votes: 3
Labels: None

Attachments: PNG File screenshot-1.png    
Issue Links:
Blocks
blocks MDEV-25949 Add support for OpenSSL 3.0 in Galera Closed
is blocked by MDEV-27140 Multiple tests started to fail when O... Closed
is blocked by MDEV-31511 MariaDB 10.4 doesn't support OpenSSL 3 Closed
PartOf
includes MDEV-26015 Remove DH param stuff In Review
includes MDEV-26302 Unittest failures with OpenSSL-3: aes... Closed
includes MDEV-26771 crash with OpenSSL 3.0.0 Closed
includes MDEV-26950 mysqld got signal 6 Closed
includes MDEV-27236 mysql_upgrade crashes server process Closed
includes MDEV-27403 Crash in evp_md_ctx_clear_digest/my_m... Closed
is part of MDEV-27373 Q1 2022 release merge Closed
Problem/Incident
causes MCOL-4964 Columnstore doesn't build with OpenSSL 3 Closed
causes MDEV-27531 Compilation errors upon building with... Closed
Relates
relates to MCOL-4962 Columnstore doesn't build with gcc 12... Closed
relates to MDEV-27540 Different OpenSSL versions mix up in ... Closed
relates to MDEV-27542 S3 binaries still link with OpenSSL 1... Closed
relates to MDEV-29000 Backport OpenSSL-3.0 compatibility to... Closed
relates to CONC-503 Add support for OpenSSL 3.0 Closed
relates to MDEV-28133 Backport OpenSSL-3.0 compatibility to... Closed
relates to MDEV-28339 Crashes with OpenSSL 3.0.2 Closed

 Description   

OpenSSL 3.0 is not yet released as GA, but we already experiment with the builds in Fedora (Copr repository available: https://copr.fedorainfracloud.org/coprs/saprasad/openssl-3.0/) or in CentOS Stream 9 (https://kojihub.stream.centos.org/koji/buildinfo?buildID=7571).

There are some documented changes in OpenSSL 3.0: https://wiki.openssl.org/index.php/OpenSSL_3.0 but there are also some changes that should not be visible. However, since other SW depends on some internals, the changes actually affect the compatibility more than documented.

MariaDB 10.5.9 (expecting 10.6.x behaves the same) fails to build with this upcoming OpenSSL 3.0.

The problem is mainly with md5, sha and crypto parts.

A partial fix is proposed here:
https://gitlab.com/redhat/centos-stream/rpms/mariadb/-/merge_requests/4
but some tests (related to encrypting) fail even with this patch, so it is definitely not complete.

MySQL report is https://bugs.mysql.com/bug.php?id=103818



 Comments   
Comment by Honza Horak [ 2021-06-17 ]

OpenSSL 3.0.0 is now released as RC, so the design and functionality should not be changed any more: https://www.openssl.org/blog/blog/2021/06/17/OpenSSL3.0ReleaseCandidate/

Can I kindly ask whether "Fix versions: 10.6" means somebody is looking at this soon or what is the rough ETA?

Comment by Honza Horak [ 2021-06-17 ]

I've asked Sahana to update the copr repository https://copr.fedorainfracloud.org/coprs/saprasad/openssl-3.0/ with this newest release, so at last for fedora users, there would be a simple way to get the openssl 3.0.0 RC soon.

Is there anything else we can help with in order to make mariadb work fine with newer openssl? We can for example provide contacts to Red Hat colleagues from OpenSSL upstream if something needs to be discussed in more detail...

Comment by Sergei Golubchik [ 2021-06-17 ]

No, at the moment nobody is looking into it. But we'll do it, of course, we cannot ignore the new major OpenSSL version.

But it's not a simple task, we'll have to change the way MariaDB uses OpenSSL, it'll be a big refactoring.

The problem is that for a long time, since OpenSSL 0.9, the code heavily relied on various OpenSSL contexts allocated on the stack for one function only. Like create an MD5 context, calculate the hash, destroy the context. With OpenSSL making all objects opaque, we can no longer do it. And we don't want to replace all those stack allocations with malloc(), the server tries rather hard to avoid malloc(). So, we'll need to implement an approach that will work with opaque objects created by OpenSSL and still doesn't call malloc() every time we need to encrypt or hash something.

Comment by Honza Horak [ 2021-06-18 ]

Do you think it makes sense to start with using deprecated functionality first (which is still available) and make it work with 3.0.0 at least somehow before doing it "correctly" without the deprecated functionality?

The patch I mentioned in the description makes the code compile this way, does not replace more than is necessary, and works find with many tests.. But it still does not address some other cases, mostly binlog_encryption suite fails (server crashes). It still seems quite doable without a big rewriting at least as the first step.

Comment by Georg Richter [ 2021-06-24 ]

A simple (and faster) solution would be to reuse contexts. In current implementation every encryption or hashing operation creates a new context on stack and initializes it. Instead an existing context should be resetted (e.g. EVP_MD_CTX_reset) and reused.

Comment by Georg Richter [ 2021-06-24 ]

After some more investigation, here is a short summary:

TLS protocol

  • Remove DH param stuff and use SSL_CTX_set_dh_auto() instead (MDEV-26015)
  • type of options parameter for SSL_CTX_set_options changed from long to uint64_t

Cryptography (Hashing and Encryption)

  • Almost all Crypto API calls generate "deprecation" warnings, they need to be replaced by EVP_ functions.
  • Reuse contexts for hashing and encryption: instead of allocating and freeing context we should reset handle (around 20% faster, maybe more if the same algorithm can be reused). This would also help to reduce memory allocations
  • Preferrable also reduce the number of functions: my_sha(hashing_algorithm, data, len, digest) instead of single functions for each algorithm. Same is valid for encryption and decryption.
  • Function EVP_CIPHER_CTX_buf_noconst (deprecated) needs to be replaced to detect overlapping bytes for non padding encryption.

Concerns/Possible problems

  • WolfSSL doesn't seem to provide compatibility layer for OSSL 3.0
  • We still have to support platforms which ship eoled OSSL versions (1.0.x)
Comment by Vladislav Vaintroub [ 2021-11-08 ]

Not much has to be changed for OpenSSL 3.0.
The "opacity" is of no concern. We already treat contexts as opaque. what's new, is that context have to be 16 bytes aligned, but we had seen it already with Wolfssl before. We have to guess the size of context, or we could see memory overwrites, but it is not really new either, we have been doing it for a while.

The biggest challenge in this version is broken EVP_CIPHER_CTX_buf_noconst, though I never found it to be documented.
The whole functional change (including suppressing the warnings) is some 30 lines of code
plus a little rework of aes-t code.

Comment by Mingli-Yu [ 2021-11-18 ]

I notice the status is changed to "IN REVIEW", is the patch available now? Thanks!

Comment by Jan Lindström (Inactive) [ 2021-11-18 ]

I hope that before anything is pushed to main branches there is done some consideration and testing done that if server uses OpenSSL 3.0 Galera would also work (using OpenSSL x where x might not be same as 3.0 or where x = 3.0). See MDEV-25949 (at the moment I do not know if Galera library even compiles with OpenSSL 3.0). Remember that currently server and Galera library are build separately and there is no restriction to use older Galera library version than latest one i.e. for OpenSSL 3.0 if you can't use different versions we need to restrict also what Galera library version can be used.

Comment by Vladislav Vaintroub [ 2021-11-18 ]

I think this hope is unfounded, jplindst The server builds with OpenSSL, with or without -DWITH_WSREP. This work won't port Galera to OpenSSL 3.0. In case of negative outcome because of Galera, what should server do? Refuse to build does not make any sense, so either Galera works with OpeSSL 3.0, or we'll allow people who do not use Galera to use OpenSSL 3.0

The Server is not even aware Galera uses SSL or OpenSSL. Even if WSREP now spread over the entire codebase, Galera is logically, a plugin, which on whatever reasons, chose to build outside of the server.

Comment by Jan Lindström (Inactive) [ 2021-11-18 ]

Some questions:

  • If server uses OpenSSL 3.0 can for example mysql client use OpenSSL 1.x or 2.x to connect ?
  • If server uses OpenSSL < 3.0 can for example mysql client use OpenSSL 3.x to connect ?
  • If both are true then what OpenSSL Galera uses is not relevant
  • If they are false then we need to have both MDEVs done before feature is released
Comment by Vladislav Vaintroub [ 2021-11-18 ]

SSL is network level protocol, while OpenSSL 3.0 is a library implementing this protocol. Of course, different servers can be connected to different clients, as exemplified by Schannel , or GNUTLS, or OpenSSL, or for example Java clients successfully connecting to either OpenSSL, or to WolfSSL servers.

What OpenSSL Galera uses might be relevant, because it is not known (and Galera team will have to to find it out), whether 2 different OpenSSL libraries can coexist peacefully inside the same mariadbd process.

Comment by Vladislav Vaintroub [ 2021-11-18 ]

Mingli-Yu, on the right side of this page, at least in desktop JIRA variant click under "1 commit" , it will bring show you the commit (in colors!), and give the github link which is currently https://github.com/MariaDB/server/commit/c80991c79f701dac42c630af4bd39593b0c7efb4

Comment by Lukas Javorsky [ 2021-11-19 ]

I would just add one note from our OpenSSL team, which we got when we tried to implement the support ourselves (keep this just as heads-up).

Usage of MD5... How do you ensure that the legacy provider is loaded?

  • OpenSSL 3.0 has a provider architecture and if you use, say, weak cipher algorithms (single DES, RC4) or hash algorithms (RIPEMD160), you need to ensure that the legacy provider is loaded.

If you already knew about this new change, just ignore this comment

Comment by Vladislav Vaintroub [ 2021-11-20 ]

I do not ensure it is loaded. It appears to work, as you can check by applying the patch.

Comment by Mingli-Yu [ 2021-11-22 ]

Thanks Vladislav very much for your info!

Comment by Sergei Golubchik [ 2021-12-06 ]

pushed into preview-10.8-MDEV-25785-openssl3.0

Comment by Elena Stepanova [ 2022-01-19 ]

I think preview-10.8-MDEV-25785-openssl3.0 as of 7cd965af can and should be pushed into the main 10.8 and released with 10.8.1. There are some limitations and can be a lot of unknowns, depending on the variety of environments and systems, which is why we need the community feedback.

Current status:

  • Linux: The server and most plugins build with basic build configurations (RelWithDebInfo, Debug, mysql_release) on a variety of Linux versions. Checked: Ubuntu 18.04/20.04, Debian 9/10/11, SLES 12/15, RHEL 7/8, x86_64/aarch64; Ubuntu 20.04 ppc64le; OpenSSL 3.0.1, in-source build and build + local installation in custom location.
    • Limitations:
      • Columnstore does not build, MCOL-4964 to track;
      • A user should be careful with cmake options to make sure the custom OpenSSL 3 does not mix up with the default OpenSSL installation of a different version, MDEV-27540 to track (not directly related to this task)
  • On Fedora Rawhide, where OpenSSL 3.0.0 is installed by default, the packages can be built and installed with it
    • Limitations:
      • Columnstore has to be disabled, MCOL-4962 (unrelated to this task) and MCOL-4964 to track;
      • If btrfs is in use, which is one of Rawhide's defaults, the server may not run. We are looking into it (unrelated to this task), meanwhile use XFS.
  • On Windows, the server can be built and run with both OpenSSL 3.0.0 installed from slpro and with OpenSSL 3.0.1 built locally
    • Limitations:
      • For a local OpenSSL build, installation must be performed (nmake install). With an in-source build, MariaDB server will compile/link, but will issue runtime errors (probably has always been so, and various README notes also suggest installation).
  • CI: There is a Ubuntu 20.04-based buildbot builder which currently builds the server with a local OpenSSL 3.0.1 installation, and there will soon be a Rawhide-based builder which will run RPM builds with the system-wide OpenSSL 3.

Other notes:

  • There are a few binaries/plugins which still link with OpenSSL 1.x, whether legitimately or not, it is being looked into (MDEV-27542)
  • I didn't manage to build deb packages with OpenSSL 3.0 yet, there are some configuration issues to work around. It shouldn't be important for initial adoption though.
Comment by Jan Lindström (Inactive) [ 2022-01-20 ]

elenst Codership reported earlier that Galera library will build with OpenSSL 3.0 but I have not tested (MDEV-25949 ).

Comment by Elena Stepanova [ 2022-01-20 ]

Galera library is obviously out of this server task, it was also stated in advance in this comment.
I did run .*ssl.* MTR tests as a part of the Linux exercise, including tests in the galera suite with an existing galera-4 library, on a server linked with openssl3, they passed. This is as much as I can say about the current Galera status.

Generated at Thu Feb 08 09:40:21 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.