aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJanne Peltonen <janne.peltonen@nokia.com>2023-05-22 16:08:28 +0300
committerMatias Elo <matias.elo@nokia.com>2023-05-25 10:05:23 +0300
commitfd7685fa4688d456dda568bae0af7a5c2e831ede (patch)
treee5457e58342cdfea170b2265712f05c36d84d9ad
parentbb1c38cdfab8b8e36310e87397f1d713f20eec1f (diff)
validation: crypto: fix packet freeing after failed crypto ops
Fix the following problems in the current code. The problems occur only when the ODP implementation under test is misbehaving. - When crypto_op() fails for an out-of-place session, the caller-allocated output packet is not freed. - alg_packet_op() returns success to caller when odp_crypto_op() or odp_crypto_op_enq() fails to consume the input packet, which may result in bad output packet handles being used in the caller. - When odp_crypto_result() fails, the input packet, that may have already been consumed by ODP, is freed and the output packet is not freed. - Creation of hash/combined test reference continues without a valid packet handle after crypto_op() fails. Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com> Reviewed-by: Tuomas Taipale <tuomas.taipale@nokia.com>
-rw-r--r--test/validation/api/crypto/odp_crypto_test_inp.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c
index 6252f9143..25be50f6d 100644
--- a/test/validation/api/crypto/odp_crypto_test_inp.c
+++ b/test/validation/api/crypto/odp_crypto_test_inp.c
@@ -201,7 +201,7 @@ static int alg_packet_op(odp_packet_t pkt_in,
rc = odp_crypto_op(&pkt_in, pkt_out, &op_params, 1);
if (rc <= 0) {
CU_FAIL("Failed odp_crypto_packet_op()");
- return rc;
+ return -1;
}
} else {
odp_packet_t *out_param = pkt_out;
@@ -212,7 +212,7 @@ static int alg_packet_op(odp_packet_t pkt_in,
rc = odp_crypto_op_enq(&pkt_in, out_param, &op_params, 1);
if (rc <= 0) {
CU_FAIL("Failed odp_crypto_op_enq()");
- return rc;
+ return -1;
}
/* Get crypto completion event from compl_queue. */
@@ -241,10 +241,8 @@ static int alg_packet_op(odp_packet_t pkt_in,
CU_ASSERT(odp_packet_subtype(*pkt_out) == ODP_EVENT_PACKET_CRYPTO);
rc = odp_crypto_result(&result, *pkt_out);
- if (rc < -1) {
- CU_FAIL("Failed odp_crypto_packet_result()");
- return rc;
- }
+ if (rc < -1)
+ CU_FAIL("Failed odp_crypto_result()");
CU_ASSERT(rc == 0 || rc == -1);
if (op_type == ODP_CRYPTO_OP_TYPE_OOP &&
@@ -281,9 +279,11 @@ static int crypto_op(odp_packet_t pkt_in,
cipher_range, auth_range,
aad, hash_result_offset);
- if (rc < 0)
+ if (rc) {
odp_packet_free(pkt_in);
-
+ if (op_type == ODP_CRYPTO_OP_TYPE_OOP)
+ odp_packet_free(*pkt_out);
+ }
return rc;
}
@@ -1529,6 +1529,10 @@ static int create_hash_test_reference(odp_auth_alg_t auth,
ref->cipher_iv, ref->auth_iv,
&cipher_range, &auth_range, ref->aad, enc_digest_offset);
CU_ASSERT(rc == 0);
+ if (rc) {
+ (void)odp_crypto_session_destroy(session);
+ return -1;
+ }
CU_ASSERT(ok);
rc = odp_crypto_session_destroy(session);
@@ -1740,6 +1744,10 @@ static int crypto_encode_ref(crypto_test_reference_t *ref,
&cipher_range, &auth_range,
ref->aad, hash_result_offset);
CU_ASSERT(rc == 0);
+ if (rc) {
+ (void)odp_crypto_session_destroy(session);
+ return -1;
+ }
CU_ASSERT(ok);
rc = odp_crypto_session_destroy(session);