From: Ciara Power Date: Fri, 30 Oct 2020 13:11:26 +0000 (+0000) Subject: test/crypto: fix null dereference of crypto op X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=3231a72a1ddfc19c38aa5909a0ac6c619ca77fbe;p=dpdk.git test/crypto: fix null dereference of crypto op In two test cases, the op value is set by the return of the process_crypto_request function, which may be NULL. The op->status value was checked afterwards, which was causing a dereference issue. To fix this, a temporary op variable is used to hold the return from the process_crypto_request function, so the original op->status can be checked after the possible NULL return value. The original op value is then set to hold the temporary op value. Coverity issue: 363452, 363465 Fixes: 4868f6591c6f ("test/crypto: add cases for raw datapath API") Signed-off-by: Ciara Power Acked-by: Akhil Goyal --- diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c index 514d485860..d7d7ab5c68 100644 --- a/app/test/test_cryptodev.c +++ b/app/test/test_cryptodev.c @@ -6754,6 +6754,7 @@ test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, unsigned int ciphertext_len; struct rte_cryptodev_info dev_info; + struct rte_crypto_op *op; /* Check if device supports particular algorithms separately */ if (test_mixed_check_if_unsupported(tdata)) @@ -6849,17 +6850,17 @@ test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, if (retval < 0) return retval; - ut_params->op = process_crypto_request(ts_params->valid_devs[0], - ut_params->op); + op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); /* Check if the op failed because the device doesn't */ /* support this particular combination of algorithms */ - if (ut_params->op == NULL && ut_params->op->status == + if (op == NULL && ut_params->op->status == RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { printf("Device doesn't support this mixed combination. " "Test Skipped.\n"); return -ENOTSUP; } + ut_params->op = op; TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); @@ -6950,6 +6951,7 @@ test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, uint8_t digest_buffer[10000]; struct rte_cryptodev_info dev_info; + struct rte_crypto_op *op; /* Check if device supports particular algorithms */ if (test_mixed_check_if_unsupported(tdata)) @@ -7054,17 +7056,17 @@ test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, if (retval < 0) return retval; - ut_params->op = process_crypto_request(ts_params->valid_devs[0], - ut_params->op); + op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); /* Check if the op failed because the device doesn't */ /* support this particular combination of algorithms */ - if (ut_params->op == NULL && ut_params->op->status == + if (op == NULL && ut_params->op->status == RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { printf("Device doesn't support this mixed combination. " "Test Skipped.\n"); return -ENOTSUP; } + ut_params->op = op; TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");