git.iko.soy/typeable/nixpkgs
on master help sign in
tpm-tss2: do not rely on a dynamic load path for tcti modules

Signed-off-by: Arthur Gautier <baloo@superbaloo.net>

commiteea5575bd364d6327f46e02d0301e62a68d3ca5a authorArthur Gautier <baloo@superbaloo.net> dateTue 23 Feb 2021, 07:42 (6 years ago) parentfc4fa28
2 files changed+62−1
pkgs/development/libraries/tpm2-tss/default.nix+23−1 pkgs/development/libraries/tpm2-tss/no-dynamic-loader-path.patch+39
pkgs/development/libraries/tpm2-tss/default.nix+23−1
@@ -27,7 +27,21 @@ stdenv.mkDerivation rec {
2727
2828 enableParallelBuilding = true;
2929
30− postPatch = "patchShebangs script";
30+ patches = [
31+ # Do not rely on dynamic loader path
32+ # TCTI loader relies on dlopen(), this patch prefixes all calls with the output directory
33+ ./no-dynamic-loader-path.patch
34+ ];
35+
36+ postPatch = ''
37+ patchShebangs script
38+ substituteInPlace src/tss2-tcti/tctildr-dl.c \
39+ --replace '@PREFIX@' $out/lib/
40+ substituteInPlace ./test/unit/tctildr-dl.c \
41+ --replace ', "libtss2' ", \"$out/lib/libtss2" \
42+ --replace ', "foo' ", \"$out/lib/foo" \
43+ --replace ', TEST_TCTI_NAME' ", \"$out/lib/\"TEST_TCTI_NAME"
44+ '';
3145
3246 configureFlags = [
3347 "--enable-unit"
@@ -35,6 +49,14 @@ stdenv.mkDerivation rec {
3549 ];
3650
3751 doCheck = true;
52+ preCheck = ''
53+ # Since we rewrote the load path in the dynamic loader for the TCTI
54+ # The various tcti implementation should be placed in their target directory
55+ # before we could run tests
56+ installPhase
57+ # install already done, dont need another one
58+ dontInstall=1
59+ '';
3860
3961 postInstall = ''
4062 # Do not install the upstream udev rules, they rely on specific
pkgs/development/libraries/tpm2-tss/no-dynamic-loader-path.patchnew file+39
@@ -0,0 +1,39 @@
1+diff --git a/src/tss2-tcti/tctildr-dl.c b/src/tss2-tcti/tctildr-dl.c
2+index b364695c..b13be3ef 100644
3+--- a/src/tss2-tcti/tctildr-dl.c
4++++ b/src/tss2-tcti/tctildr-dl.c
5+@@ -85,7 +85,15 @@ handle_from_name(const char *file,
6+ if (handle == NULL) {
7+ return TSS2_TCTI_RC_BAD_REFERENCE;
8+ }
9+- *handle = dlopen(file, RTLD_NOW);
10++ size = snprintf(file_xfrm,
11++ sizeof (file_xfrm),
12++ "@PREFIX@%s",
13++ file);
14++ if (size >= sizeof (file_xfrm)) {
15++ LOG_ERROR("TCTI name truncated in transform.");
16++ return TSS2_TCTI_RC_BAD_VALUE;
17++ }
18++ *handle = dlopen(file_xfrm, RTLD_NOW);
19+ if (*handle != NULL) {
20+ return TSS2_RC_SUCCESS;
21+ } else {
22+@@ -94,7 +102,7 @@ handle_from_name(const char *file,
23+ /* 'name' alone didn't work, try libtss2-tcti-<name>.so.0 */
24+ size = snprintf(file_xfrm,
25+ sizeof (file_xfrm),
26+- TCTI_NAME_TEMPLATE_0,
27++ "@PREFIX@" TCTI_NAME_TEMPLATE_0,
28+ file);
29+ if (size >= sizeof (file_xfrm)) {
30+ LOG_ERROR("TCTI name truncated in transform.");
31+@@ -109,7 +117,7 @@ handle_from_name(const char *file,
32+ /* libtss2-tcti-<name>.so.0 didn't work, try libtss2-tcti-<name>.so */
33+ size = snprintf(file_xfrm,
34+ sizeof (file_xfrm),
35+- TCTI_NAME_TEMPLATE,
36++ "@PREFIX@" TCTI_NAME_TEMPLATE,
37+ file);
38+ if (size >= sizeof (file_xfrm)) {
39+ LOG_ERROR("TCTI name truncated in transform.");