From: Ryan Prinz <rc4d5a@protonmail.com>
To: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
"David S . Miller" <davem@davemloft.net>,
qat-linux@intel.com, linux-crypto@vger.kernel.org,
linux-kernel@vger.kernel.org, Ryan Prinz <rc4d5a@protonmail.com>
Subject: [PATCH v2] crypto: qat - fix missing DH public key validation
Date: Tue, 24 Nov 2026 14:12:54 +0000 [thread overview]
Message-ID: <20261124141238.1743680-1-rc4d5a@protonmail.com> (raw)
qat_dh_compute_value() passes the peer's DH public value into the
hardware queue without checking it. The only checks on req->src are
on length (req->src_len > ctx->p_size); never on the value itself.
crypto/dh.c's dh_is_pubkey_valid() is the generic software check for
this: it rejects a value outside [2, p-2], but only when FIPS mode
is enabled, and only for callers using the software implementation.
QAT's hardware path has no equivalent check in either mode.
QAT registers "dh" at cra_priority 1000, versus the generic software
implementation's 100, so any caller requesting "dh" gets this
unvalidated path whenever a QAT device is present and the requested
modulus size (1536/2048/3072/4096 bits) is one QAT supports;
qat_dh_set_secret() only falls back to software for sizes outside
that set.
drivers/nvme/common/auth.c requests "ffdheNNNN(dh)" for NVMe-oF's
in-band DH-HMAC-CHAP authentication. Three of its five supported
group sizes, 2048, 3072 and 4096 bits, match QAT's hardware sizes.
Forcing the derived session key Ks to a known value lets an
attacker who holds a handshake transcript perform an offline
brute-force attack against the pre-shared key, which is what the DH
exchange is documented to protect against on top of plain CHAP.
Fixed by validating the peer-supplied value before it reaches the
hardware queue, rejecting any value outside [2, p-2].
Fixes: c9839143ebbf ("crypto: qat - Add DH support")
Signed-off-by: Ryan Prinz <rc4d5a@protonmail.com>
---
v2:
- Corrected the Fixes: tag, found by Sashiko's automated review:
2acbb8771f6a only added the req->src_len > ctx->p_size length
check, to fix an unrelated integer underflow; it's unrelated to
the missing value check this patch adds. That's been missing
since DH support was first added, in c9839143ebbf, which is now
the correct tag.
No Intel QuickAssist hardware was available to reproduce this.
Verified by building the modified driver (along with crypto/dh.c and
crypto/kpp.c) against an unmodified kernel tree on x86_64, confirming
the module compiles and links cleanly with no new warnings; and
verifying the range-check arithmetic in a standalone test
exercising the boundary values 0, 1, 2, p-2, p-1, p and a value
larger than p, which all produced the expected accept/reject result.
AI Disclosure: An AI assistant was used to assist with the
analysis and testing. I have verified the vulnerability, the fix, and
the test results myself and take responsibility for this contribution,
per Documentation/process/coding-assistants.rst.
drivers/crypto/intel/qat/qat_common/qat_asym_algs.c | 63 ++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/drivers/crypto/intel/qat/qat_common/qat_asym_algs.c b/drivers/crypto/intel/qat/qat_common/qat_asym_algs.c
index 77d59e977472..78f1b949614b 100644
--- a/drivers/crypto/intel/qat/qat_common/qat_asym_algs.c
+++ b/drivers/crypto/intel/qat/qat_common/qat_asym_algs.c
@@ -216,6 +216,63 @@ static unsigned long qat_dh_fn_id(unsigned int len, bool g2)
}
}
+/* Returns true iff 2 <= y <= p - 2, given big-endian buffers of p_size bytes. */
+static bool qat_dh_pubkey_in_range(const u8 *y, const u8 *p_minus_1,
+ unsigned int p_size)
+{
+ bool is_zero_or_one = true;
+ unsigned int i;
+
+ for (i = 0; i < p_size - 1; i++) {
+ if (y[i]) {
+ is_zero_or_one = false;
+ break;
+ }
+ }
+
+ if (is_zero_or_one && y[p_size - 1] <= 1)
+ return false;
+
+ return memcmp(y, p_minus_1, p_size) < 0;
+}
+
+static int qat_dh_peer_pubkey_valid(struct qat_dh_ctx *ctx,
+ struct scatterlist *src,
+ unsigned int src_len, gfp_t flags)
+{
+ unsigned int p_size = ctx->p_size;
+ u8 *p_minus_1, *y;
+ int i, ret = 0;
+
+ if (!src_len || src_len > p_size)
+ return -EINVAL;
+
+ y = kzalloc(p_size, flags);
+ if (!y)
+ return -ENOMEM;
+
+ scatterwalk_map_and_copy(y + (p_size - src_len), src, 0, src_len, 0);
+
+ p_minus_1 = kmemdup(ctx->p, p_size, flags);
+ if (!p_minus_1) {
+ ret = -ENOMEM;
+ goto free_y;
+ }
+
+ for (i = p_size - 1; i >= 0; i--) {
+ if (p_minus_1[i]-- != 0)
+ break;
+ }
+
+ if (!qat_dh_pubkey_in_range(y, p_minus_1, p_size))
+ ret = -EINVAL;
+
+ kfree_sensitive(p_minus_1);
+free_y:
+ kfree_sensitive(y);
+ return ret;
+}
+
static int qat_dh_compute_value(struct kpp_request *req)
{
struct crypto_kpp *tfm = crypto_kpp_reqtfm(req);
@@ -241,6 +298,12 @@ static int qat_dh_compute_value(struct kpp_request *req)
if (req->src_len > ctx->p_size)
return -EINVAL;
+ if (req->src) {
+ ret = qat_dh_peer_pubkey_valid(ctx, req->src, req->src_len, flags);
+ if (unlikely(ret))
+ return ret;
+ }
+
memset(msg, '\0', sizeof(*msg));
ICP_QAT_FW_PKE_HDR_VALID_FLAG_SET(msg->pke_hdr,
ICP_QAT_FW_COMN_REQ_FLAG_SET);
--
2.51.2
reply other threads:[~2026-11-24 14:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261124141238.1743680-1-rc4d5a@protonmail.com \
--to=rc4d5a@protonmail.com \
--cc=davem@davemloft.net \
--cc=giovanni.cabiddu@intel.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=qat-linux@intel.com \
/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
all inboxes | Powered by JetHome®