Skip to content

Commit

Permalink
xtest: pkcs11: fix false positive error report on CKR_HOST_MEMORY
Browse files Browse the repository at this point in the history
Fix false positive error case in test pkcs11_1004 and pkcs11_1007.

In the pkcs11_1004 test, the client creates as many PKCS#11 objects
as possible until the system fails on memory allocation error. In the
pkcs11_1007 test, the client prepares as many cipher sessions as
possible until the system fails on memory allocation error. Both
test implementations consider only CKR_DEVICE_MEMORY return code as
the condition for expected resource exhaustion while they should also
consider the host resource exhaustion return code CKR_HOST_MEMORY.

Fixes: 2d6dc93 ("xtest: pkcs11: add symmetric cipher tests")
Signed-off-by: Etienne Carriere <[email protected]>
  • Loading branch information
etienne-lms committed Nov 21, 2023
1 parent 4f91b9a commit 2674ce8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions host/xtest/pkcs11_1000.c
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,8 @@ static void test_create_destroy_session_objects(ADBG_Case_t *c)
ARRAY_SIZE(cktest_session_object),
obj_hdl + n);

if (rv == CKR_DEVICE_MEMORY || !ADBG_EXPECT_CK_OK(c, rv))
if (rv == CKR_DEVICE_MEMORY || rv == CKR_HOST_MEMORY ||
!ADBG_EXPECT_CK_OK(c, rv))
break;
}

Expand Down Expand Up @@ -1654,13 +1655,13 @@ static CK_RV open_cipher_session(ADBG_Case_t *c,
}

rv = C_OpenSession(slot, session_flags, NULL, 0, session);
if (rv == CKR_DEVICE_MEMORY)
if (rv == CKR_DEVICE_MEMORY || rv == CKR_HOST_MEMORY)
return rv;
if (!ADBG_EXPECT_CK_OK(c, rv))
return rv;

rv = C_CreateObject(*session, attr_key, attr_count, &object);
if (rv == CKR_DEVICE_MEMORY)
if (rv == CKR_DEVICE_MEMORY || rv == CKR_HOST_MEMORY)
return rv;
if (!ADBG_EXPECT_CK_OK(c, rv))
return rv;
Expand All @@ -1670,7 +1671,7 @@ static CK_RV open_cipher_session(ADBG_Case_t *c,
if (mode == TEE_MODE_DECRYPT)
rv = C_DecryptInit(*session, mechanism, object);

if (rv == CKR_DEVICE_MEMORY)
if (rv == CKR_DEVICE_MEMORY || rv == CKR_HOST_MEMORY)
return rv;
if (!ADBG_EXPECT_CK_OK(c, rv))
return CKR_GENERAL_ERROR;
Expand Down Expand Up @@ -1701,7 +1702,7 @@ static void xtest_pkcs11_test_1007(ADBG_Case_t *c)
TEE_MODE_ENCRYPT);

/* Failure due to memory allocation is not a error case */
if (rv == CKR_DEVICE_MEMORY)
if (rv == CKR_DEVICE_MEMORY || rv == CKR_HOST_MEMORY)
break;

if (!ADBG_EXPECT_CK_OK(c, rv))
Expand Down

0 comments on commit 2674ce8

Please sign in to comment.