From: Kai Ji <kai.ji@intel.com>
To: dev@dpdk.org
Cc: gakhil@marvell.com, chiluka@marvell.com,
Kai Ji <kai.ji@intel.com>,
stable@dpdk.org
Subject: [dpdk-dev v1] crypto/qat: fix EC session segfault on missing pkey/pub key
Date: Wed, 25 Mar 2026 15:50:40 +0000 [thread overview]
Message-ID: <20260325155040.2922854-1-kai.ji@intel.com> (raw)
session_set_ec() checked qat_session->xform.ec.pkey.length for
the NULL-allocation guards, but that field is zero (from the
preceding memset) at that point, so the guards never fired.
When test_ecpm() created a session the xform had no pkey or
public-key fields set (ECPM only needs curve_id), so the
unchecked memcpy calls received a NULL destination and a
garbage-length source, causing a segfault.
Fix session_set_ec() to check xform->ec.*.length, the caller-
supplied value, before allocating and copying each optional
field (pkey, q.x, q.y), skipping the allocation entirely when
the length is zero.
Fix test_ecpm() to zero-initialise the xform with memset so
that uninitialised pkey/q fields are never passed to the driver.
Also add a QAT_LOG(ERR) in pick_curve() default case so that
unsupported curve IDs are surfaced immediately rather than
producing the misleading 'Unsupported xform type' message
from qat_asym_session_configure().
Fixes: 064ef1b098d1 (\"test/crypto: remove PMD-specific asym test suites\")
Cc: stable@dpdk.org
Signed-off-by: Kai Ji <kai.ji@intel.com>
---
app/test/test_cryptodev_asym.c | 2 +-
drivers/crypto/qat/qat_asym.c | 58 ++++++++++++++++++----------------
drivers/crypto/qat/qat_ec.h | 1 +
3 files changed, 32 insertions(+), 29 deletions(-)
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 07e5eb5842..bf1a1fc417 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -1816,7 +1816,7 @@ test_ecpm(enum curve curve_id)
asym_op = op->asym;
/* Setup asym xform */
- xform.next = NULL;
+ memset(&xform, 0, sizeof(xform));
xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
xform.ec.curve_id = input_params.curve;
diff --git a/drivers/crypto/qat/qat_asym.c b/drivers/crypto/qat/qat_asym.c
index 7a296cad6c..9276b86c0e 100644
--- a/drivers/crypto/qat/qat_asym.c
+++ b/drivers/crypto/qat/qat_asym.c
@@ -1492,36 +1492,38 @@ session_set_ec(struct qat_asym_session *qat_session,
uint8_t *q_x = xform->ec.q.x.data;
uint8_t *q_y = xform->ec.q.y.data;
- qat_session->xform.ec.pkey.data =
- rte_malloc(NULL, xform->ec.pkey.length, 0);
- if (qat_session->xform.ec.pkey.length &&
- qat_session->xform.ec.pkey.data == NULL)
- return -ENOMEM;
- qat_session->xform.ec.q.x.data = rte_malloc(NULL,
- xform->ec.q.x.length, 0);
- if (qat_session->xform.ec.q.x.length &&
- qat_session->xform.ec.q.x.data == NULL) {
- rte_free(qat_session->xform.ec.pkey.data);
- return -ENOMEM;
+ if (xform->ec.pkey.length) {
+ qat_session->xform.ec.pkey.data =
+ rte_malloc(NULL, xform->ec.pkey.length, 0);
+ if (qat_session->xform.ec.pkey.data == NULL)
+ return -ENOMEM;
+ memcpy(qat_session->xform.ec.pkey.data, pkey,
+ xform->ec.pkey.length);
+ qat_session->xform.ec.pkey.length = xform->ec.pkey.length;
}
- qat_session->xform.ec.q.y.data = rte_malloc(NULL,
- xform->ec.q.y.length, 0);
- if (qat_session->xform.ec.q.y.length &&
- qat_session->xform.ec.q.y.data == NULL) {
- rte_free(qat_session->xform.ec.pkey.data);
- rte_free(qat_session->xform.ec.q.x.data);
- return -ENOMEM;
+ if (xform->ec.q.x.length) {
+ qat_session->xform.ec.q.x.data = rte_malloc(NULL,
+ xform->ec.q.x.length, 0);
+ if (qat_session->xform.ec.q.x.data == NULL) {
+ rte_free(qat_session->xform.ec.pkey.data);
+ return -ENOMEM;
+ }
+ memcpy(qat_session->xform.ec.q.x.data, q_x,
+ xform->ec.q.x.length);
+ qat_session->xform.ec.q.x.length = xform->ec.q.x.length;
+ }
+ if (xform->ec.q.y.length) {
+ qat_session->xform.ec.q.y.data = rte_malloc(NULL,
+ xform->ec.q.y.length, 0);
+ if (qat_session->xform.ec.q.y.data == NULL) {
+ rte_free(qat_session->xform.ec.pkey.data);
+ rte_free(qat_session->xform.ec.q.x.data);
+ return -ENOMEM;
+ }
+ memcpy(qat_session->xform.ec.q.y.data, q_y,
+ xform->ec.q.y.length);
+ qat_session->xform.ec.q.y.length = xform->ec.q.y.length;
}
-
- memcpy(qat_session->xform.ec.pkey.data, pkey,
- xform->ec.pkey.length);
- qat_session->xform.ec.pkey.length = xform->ec.pkey.length;
- memcpy(qat_session->xform.ec.q.x.data, q_x,
- xform->ec.q.x.length);
- qat_session->xform.ec.q.x.length = xform->ec.q.x.length;
- memcpy(qat_session->xform.ec.q.y.data, q_y,
- xform->ec.q.y.length);
- qat_session->xform.ec.q.y.length = xform->ec.q.y.length;
qat_session->xform.ec.curve_id = xform->ec.curve_id;
return 0;
diff --git a/drivers/crypto/qat/qat_ec.h b/drivers/crypto/qat/qat_ec.h
index 0e02722c18..653854abc4 100644
--- a/drivers/crypto/qat/qat_ec.h
+++ b/drivers/crypto/qat/qat_ec.h
@@ -274,6 +274,7 @@ pick_curve(const struct rte_crypto_asym_xform *xform)
case RTE_CRYPTO_EC_GROUP_SECP521R1:
return SECP521R1;
default:
+ QAT_LOG(ERR, "Unsupported curve id %d", xform->ec.curve_id);
return -1;
}
}
--
2.43.0
next reply other threads:[~2026-03-25 15:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-25 15:50 Kai Ji [this message]
2026-03-31 1:48 ` [dpdk-dev v1] crypto/qat: fix EC session segfault on missing pkey/pub key Jiang, YuX
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260325155040.2922854-1-kai.ji@intel.com \
--to=kai.ji@intel.com \
--cc=chiluka@marvell.com \
--cc=dev@dpdk.org \
--cc=gakhil@marvell.com \
--cc=stable@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox