Repository navigation
Support cocoon-tpm's OpenSSL backend - #1210
osteffenrh wants to merge 13 commits into
Conversation
|
cc: @nicstange |
a46ac80 to
7bc6315
Compare
|
cocoon-tpm-ossl-bare-sys-target-integration: Change |
7bc6315 to
f5bdfc4
Compare
f5bdfc4 to
88edb71
Compare
|
luigix25
left a comment
There was a problem hiding this comment.
make test is failing on my machine
several errors all similar to each other:
error[E0080]: evaluation of constant value failed
--> /home/lleonard/repos/svsm/target/debug/build/cocoon-tpm-ossl-bare-sys-a17970f9705b7cdb/out/wrapper.rs:12761:30
|
12761 | ["Size of err_state_st"][::core::mem::size_of::<err_state_st>() - 904usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `1_usize - 904_usize`, which would overflow
88edb71 to
3d81c40
Compare
|
Updated the cocoon-tpm revs to match the cocoon-tpm PR. |
Hm. Fedora 44 issue. Investigating. |
8f2d202 to
9b46477
Compare
|
v3:
|
9b46477 to
8843058
Compare
|
@osteffenrh what about moving the bindgen bump to the first commit? so bisectability is fine. |
8843058 to
e73a699
Compare
|
NOTE: There is an issue with conflicting dependencies right now: bindgen seems to pull in 2 versions of syn (2 and 3). I am working around that in the last commit by pinning. |
e44afc1 to
6cfc814
Compare
Add a simple object pool implementation usable for static pools. Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Refactor the random number generator pool using the new object pool implementation from "utils". Move the DRBG generator implementation to its own submodule to further abstract it. We will gain another RNG implementation in a following commit. Signed-off-by: Oliver Steffen <osteffen@redhat.com>
6cfc814 to
2e84834
Compare
|
Cocoon-tpm PR adding the OpenSSL backend was merged. v4:
|
|
@osteffenrh I think last commit should we dropped |
It is still needed. I need to figure out how to fix properly. |
Use the same version of bindgen as we do in cocoon-tpm (where 0.73.2 is needed). Pin prettyplease to 0.2.29 in Cargo.lock. bindgen 0.73.2 accepts prettyplease >=0.2.7, <0.4 but uses syn 2.x internally. If Cargo resolves prettyplease to 0.3.0 (which depends on syn 3.x), the build fails due to conflicting syn versions. Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Use the latest releases of the cocoon-tpm crates from crates.io. This includes the new OpenSSL backend for cocoon-tpm-crypto, which we will use in a following commit. Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Print the name of the compile-time selected backend of cocoon-tpm-crypto to the log. Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Copy the libcrt C library used to integrate OpenSSL from the libtcgtpm crate to its own. It will gain an additional consumer in the future and thus should live in a common place. The new libcrt crate has no Rust code. It just builds libcrt and provides it at link time. libtcgtpm will depend on the new crate and drop its copy of the C code in a following commit. The C code is only compiled for bare-metal targets, to allow regular host-side tests to compile against system libc. Signed-off-by: Oliver Steffen <osteffen@redhat.com>
libcrt.h opens with `#pragma GCC visibility push(hidden)` when __pie__ is defined, but never pops it. This leaks hidden visibility into every translation unit that transitively includes any libcrt header (stddef.h, stdio.h, stdlib.h, etc. all include libcrt.h). For the SVSM kernel built with gcc -nostdinc this is harmless because gcc does not default to PIE and the SVSM link step uses explicit symbol visibility anyway. However, when a host-side tool such as bindgen uses libclang to parse OpenSSL headers that pull in libcrt's stdio.h, the missing pop causes all subsequent function declarations (BN_*, EC_*, EVP_*, ...) to inherit hidden visibility. On hosts where clang defaults to PIE (Ubuntu, Debian), __pie__ is defined and the pragma fires — bindgen's enable_function_attribute_detection() then silently drops the hidden functions, producing only 15 out of ~1873 expected bindings. Hosts without PIE defaults (Fedora, RHEL) are unaffected, hiding the bug. Add the matching `#pragma GCC visibility pop` before the include guard close. Signed-off-by: Oliver Steffen <osteffen@redhat.com>
The Makefile used gcc as the compiler (hard-coded). For cross-builds, this needs to be prefixed with the target architecture. Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Use the libcrt crate instead of building libcrt locally. The libcrt crate provides include and lib paths via cargo metadata (DEP_CRT_*), and handles linking at build time. Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Add an implementation of cocoon-tpm's OpenSSL backend integration package. It provides an OpenSSL build config (based on the libtcgtpm one), matching compiler flags to the cocoon-tpm OpenSSL backend. It depends on our libcrt crate providing a C runtime for OpenSSL. A cargo feature called "openssl" is added to select OpenSSL as the backend in cocoon-tpm. Note: After this commit the openssl and vtpm cargo feature conflict, due to duplicate libcrypto symbols at link time. This will be resolved in a later commit. Configuration options specific to the target environment are passed to the OpenSSL backend of cocoon-tpm; this includes flags for cross-compilation. The set of enabled/disabled algorithms is selected on the cocoon-tpm side and satisfies our needs. Note: The new openssl feature does not build yet, we need to implement a matching RNG in kernel/crypto. This will happen in the following commit. Signed-off-by: Oliver Steffen <osteffen@redhat.com>
The DRBG generator from cocoon-tpm crypto are not available when the OpenSSL backend is selected. Add a new RNG implementation which uses OsslRandBytes() next to the DRBG one and switch between them at build time depending on the "openssl" cargo feature. Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Stop building OpenSSL locally in the libtcgtpm Makefile. Instead, depend on cocoon-tpm-ossl-bare-sys which provides libcrypto.a and exports include/lib paths via cargo metadata (DEP_OSSL_*). The Makefile now expects OPENSSL_INCLUDE_DIR and OPENSSL_SRC_INCLUDE_DIR from the caller and only builds the tcgtpm libraries. Remove the OpenSSL submodule and build config. After this commit libtcgtpm can be used again. It now depends on OpenSSL via cocoon-tpm-crypto. The vtpm cargo feature enables the openssl feature automatically. The vtpm can not be built without OpenSSL. Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Move cross-compile detection to build.rs and use cargo's HOST settings instead of handling it in the makefile (calls uname). Signed-off-by: Oliver Steffen <osteffen@redhat.com>
2e84834 to
79c1cd0
Compare
|
v5:
|
Add support for cocoon-tpm's OpenSSL backend (cocoon-tpm PR: coconut-svsm/cocoon-tpm#30).
cocoon-tpm-crypto is the designated crypto library for SVSM. It supports
multiple backends: pure Rust, BoringSSL, and — with the above PR — OpenSSL.
This PR integrates the new OpenSSL backend on the SVSM side.
Previously, the vTPM code (libtcgtpm) maintained its own OpenSSL build —
including a git submodule, build config, and a bundled copy of libcrt (a
minimal C runtime). With cocoon-tpm now providing an OpenSSL backend, this
duplication is eliminated: a single libcrypto.a is built by cocoon-tpm's
ossl-bare-sys crate and shared by both cocoon-tpm-crypto and libtcgtpm.
The OpenSSL submodule and build infrastructure are removed from libtcgtpm.
The OpenSSL backend is selected via the cargo feature openssl. The vtpm
feature now implies openssl, since the TCG TPM reference code requires
OpenSSL at the C level. Without vtpm, the pure-Rust backend remains the
default.
To build OpenSSL for the freestanding SVSM environment, cocoon-tpm's
ossl-bare-sys uses a target-integration pattern: the upstream crate depends
on a stub crate (cocoon-tpm-ossl-bare-sys-target-integration) that is
overridden via [patch.crates-io] in each target environment. The SVSM
implementation of this crate provides the OpenSSL build configuration
(Configure flags and target config file) and depends on our libcrt crate for
the C runtime headers needed during the OpenSSL build.
libcrt itself is extracted from libtcgtpm into a standalone crate
(libcrt). It has no Rust code — it just builds the C runtime and provides
it at link time. Both the target-integration crate and libtcgtpm depend on
it. Include paths and library locations are communicated between crates via
cargo metadata (
DEP_CRT_*,DEP_OSSL_*environment variables).This PR does not consolidate all of SVSM's crypto usage under
cocoon-tpm-crypto; that is left as follow-up work.
The vtpm and openssl features do not work for host-side targets like tests
and doc tests, since they pull in the target-integration crate for OpenSSL
which is specific to the bare-metal environment of SVSM.
Commit Outline
The first two commits refactor the random number generator pool in the crypto crate,
making it more generic and easier to add other RNG implementations later.
The following commit is only temporary and shall be dropped before this PR is merged,
which requires that the cocoon-tpm PR is merged and a new release is published on crates.io first.
Debug improvement, possible with the cocoon-tpm PR.
libcrt refactoring: Pull the C runtime out from libtcgtpm into its own
top-level crate, allowing multiple consumers. It does not contain any Rust code,
just builds the C code and provides a static library to the linker. Include path
and library location are communicated between build.rs scripts via environment variables.
The center piece of this PR: Add the target integration library for cocoon-tpm OpenSSL backend.
Provides OpenSSL build config and libcrt (by depending on the libcrt crate).
Bisect-ability between these three commits is broken: The RNG implementation is needed to build with
the openssl feature enabled (fixed by the second one) and the openssl feature conflicts with the vtpm
feature due to duplicate linkage against libcrypto.a instances. This is resolved by the last commit that
drops the openssl copy from libtcgtpm and uses the cocoon-tpm provided one instead.