Re: [PATCH v3] crypto: qat - fix missing DH public key validation
From: Herbert Xu
Date: Fri Dec 04 2026 - 00:07:19 EST
On Wed, Nov 25, 2026 at 11:19:18PM +0000, Ryan Prinz wrote:
> 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@xxxxxxxxxxxxxx>
> ---
> v3:
> - Giovanni pointed out that this range check was about to exist
> twice, byte-for-byte identical, once here and once in the
> HiSilicon HPRE fix for the same bug. Moved the comparison itself
> into crypto_dh_pubkey_in_range() in crypto/dh_helper.c, exported
> via dh.h, so this and the HPRE fix (and the generic software path,
> if that's wired up too) share one implementation instead of each
> carrying a private copy. This driver's own zero-padding and (p - 1)
> computation are unchanged; only the final comparison call moved.
> Depends on the separate "crypto: dh - add shared DH public key
> range check" patch.
This needs to go into a patch series. Otherwise it's impossible
for Sashiko to review this.
Thanks,
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt