-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segmentation fault in test_fapi.py::TestFapiECC::test_policy_signed #367
Comments
Could you get a backtrace from the coredump? |
The |
Sorry for the late response. diff --git a/src/tpm2_pytss/FAPI.py b/src/tpm2_pytss/FAPI.py
index d4b8c6c..dfe1636 100644
--- a/src/tpm2_pytss/FAPI.py
+++ b/src/tpm2_pytss/FAPI.py
@@ -1309,6 +1309,7 @@ class FAPI:
signature_len,
user_data,
):
+ print("sign callback_wrapper called")
path = ffi.string(path).decode()
description = ffi.string(description).decode()
public_key = ffi.string(public_key).decode()
@@ -1321,6 +1322,7 @@ class FAPI:
ffi.unpack(ffi.cast("uint8_t *", user_data), user_data_len,)
)
try:
+ print("calling wrapped sign callback")
signature_value = callback(
path,
description,
@@ -1330,6 +1332,7 @@ class FAPI:
data_to_sign,
user_data,
)
+ print("called wrapped sign callback")
except Exception:
return lib.TSS2_FAPI_RC_CB_FAILURE
diff --git a/test/test_fapi.py b/test/test_fapi.py
index 11f2d21..d40b998 100644
--- a/test/test_fapi.py
+++ b/test/test_fapi.py
@@ -760,12 +760,14 @@ class Common:
data_to_sign,
user_data,
):
+ print("pre sign_callback assert")
assert key_path.endswith(path)
assert description == "PolicySigned"
assert public_key == sign_key_public_pem
assert public_key_hint == "Test key hint"
assert hash_alg == lib.TPM2_ALG_SHA256
assert user_data == b"123456"
+ print("post sign_callback assert")
# signing authority signs external to TPM (via openssl) to authorize usage of key (policy Signed)
return sign_key.sign(data_to_sign, ec.ECDSA(hashes.SHA256()))
|
Seems that the callback is not called:
I am wondering, this |
The callback is called (pre(post sign_callback assert is from the callback), so now it seems that the signature is broken in some way and when it tries to free the signature it segfaults, could you try with (instead of the other patch): diff --git a/src/tpm2_pytss/FAPI.py b/src/tpm2_pytss/FAPI.py
index d4b8c6c..dc8f7df 100644
--- a/src/tpm2_pytss/FAPI.py
+++ b/src/tpm2_pytss/FAPI.py
@@ -1336,6 +1336,7 @@ class FAPI:
# signature is cleaned up by the FAPI
signature[0] = ffi_malloc("char[]", signature_value)
signature_len[0] = len(signature_value)
+ print("wrapper sig:", signature, signature[0], signature_len, signature_len[0])
return lib.TPM2_RC_SUCCESS
c_callback = self._register_callback(
diff --git a/test/test_fapi.py b/test/test_fapi.py
index 11f2d21..acd261f 100644
--- a/test/test_fapi.py
+++ b/test/test_fapi.py
@@ -3,6 +3,7 @@
import random
import string
import sys
+from binascii import hexlify
import pytest
@@ -768,7 +769,9 @@ class Common:
assert user_data == b"123456"
# signing authority signs external to TPM (via openssl) to authorize usage of key (policy Signed)
- return sign_key.sign(data_to_sign, ec.ECDSA(hashes.SHA256()))
+ sig = sign_key.sign(data_to_sign, ec.ECDSA(hashes.SHA256()))
+ print("callback sig:", hexlify(sig))
+ return sig
# set signing callback, will be called if policy Signed is to be satisfied
self.fapi.set_sign_callback(callback=sign_callback, user_data=b"123456") |
I write prints in the first line of "callback_wrapper" and I do not see them.
|
I'm having a hard time figuring out exactly where it goes wrong, I have one last patch you can try, but if that doesn't tell us anything I'll try to reproduce your environment, which steps do I need to do for a similar environment in for a VM? diff --git a/src/tpm2_pytss/FAPI.py b/src/tpm2_pytss/FAPI.py
index d4b8c6c..02b974e 100644
--- a/src/tpm2_pytss/FAPI.py
+++ b/src/tpm2_pytss/FAPI.py
@@ -1309,18 +1309,19 @@ class FAPI:
signature_len,
user_data,
):
- path = ffi.string(path).decode()
- description = ffi.string(description).decode()
- public_key = ffi.string(public_key).decode()
- public_key_hint = ffi.string(public_key_hint).decode()
- data_to_sign = bytes(ffi.unpack(data_to_sign, data_to_sign_len))
- if user_data == ffi.NULL:
- user_data = None
- else:
- user_data = bytes(
- ffi.unpack(ffi.cast("uint8_t *", user_data), user_data_len,)
- )
try:
+ path = ffi.string(path).decode()
+ description = ffi.string(description).decode()
+ public_key = ffi.string(public_key).decode()
+ public_key_hint = ffi.string(public_key_hint).decode()
+ data_to_sign = bytes(ffi.unpack(data_to_sign, data_to_sign_len))
+ if user_data == ffi.NULL:
+ user_data = None
+ else:
+ user_data = bytes(
+ ffi.unpack(ffi.cast("uint8_t *", user_data), user_data_len,)
+ )
+
signature_value = callback(
path,
description,
@@ -1330,12 +1331,14 @@ class FAPI:
data_to_sign,
user_data,
)
- except Exception:
+ signature[0] = ffi_malloc("char[]", signature_value)
+ signature_len[0] = len(signature_value)
+ except Exception as e:
+ print("sign callback_wrapper: ", e)
return lib.TSS2_FAPI_RC_CB_FAILURE
# signature is cleaned up by the FAPI
- signature[0] = ffi_malloc("char[]", signature_value)
- signature_len[0] = len(signature_value)
+ print(signature[0], signature_len[0])
return lib.TPM2_RC_SUCCESS
c_callback = self._register_callback( |
It is my fault. I am providing wrong data. I realized that I am executing the code from one place and the tests for another, and I was mixing the edits. I am sorry. I added the different patches in a single run, and this is the output now:
|
I'm sadly a bit stuck on this issue, if I want to setup a VM to reproduce which distribution do I need to run and are there any other steps I need to take? |
When running the test
test_policy_signed
I have a segmentation error, when running with tpm2-tss 3.2.0 with and without LTO optimizations:The text was updated successfully, but these errors were encountered: