Linux cryptographic layer development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ryan Prinz" <rc4d5a@protonmail.com>,
	"Zhiqi Song" <songzhiqi1@huawei.com>,
	"Longfang Liu" <liulongfang@huawei.com>
Cc: "Giovanni Cabiddu" <giovanni.cabiddu@intel.com>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"David S . Miller" <davem@davemloft.net>,
	linux-crypto@vger.kernel.org
Subject: Re: [PATCH v4] crypto: hisilicon/hpre - fix missing DH/ECDH public key validation
Date: Wed, 25 Nov 2026 23:29:29 +0000	[thread overview]
Message-ID: <sashiko-outbox-234403@kernel.org> (raw)
In-Reply-To: <20261125231929.1857637-1-rc4d5a@protonmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] crypto: hisilicon/hpre - call to undeclared
  crypto_dh_pubkey_in_range()
--

commit 68d806f8478204295fe2a1e07880933e7ec78e7e
Author: Ryan Prinz <rc4d5a@protonmail.com>

crypto: hisilicon/hpre - fix missing DH/ECDH public key validation

This commit validates peer-supplied DH and ECDH public keys in
hpre_dh_compute_value() and hpre_ecdh_compute_value() before submitting
them to the hardware queue.

> diff --git a/drivers/crypto/hisilicon/hpre/hpre_crypto.c b/drivers/crypto/hisilicon/hpre/hpre_crypto.c
> index 66a276786a7d0..7355e5bd94cef 100644
> --- a/drivers/crypto/hisilicon/hpre/hpre_crypto.c
> +++ b/drivers/crypto/hisilicon/hpre/hpre_crypto.c
> @@ -4,6 +4,7 @@
>  #include <crypto/dh.h>
>  #include <crypto/ecc_curve.h>
>  #include <crypto/ecdh.h>
> +#include <crypto/internal/ecc.h>
>  #include <crypto/rng.h>
>  #include <crypto/internal/akcipher.h>
>  #include <crypto/internal/kpp.h>
> @@ -471,6 +472,49 @@ static int hpre_send(struct hpre_ctx *ctx, struct hpre_sqe *msg)
>  	return ret;
>  }
>  
> +static int hpre_dh_peer_pubkey_valid(struct hpre_ctx *ctx,
> +				     struct scatterlist *src,
> +				     unsigned int src_len, gfp_t gfp)
> +{
> +	unsigned int key_sz = ctx->key_sz;
> +	u8 *p_minus_1, *y;
> +	size_t copied;
> +	int i, ret = 0;
> +
> +	if (!src_len || src_len > key_sz)
> +		return -EINVAL;
> +
> +	y = kzalloc(key_sz, gfp);
> +	if (!y)
> +		return -ENOMEM;
> +
> +	copied = sg_copy_to_buffer(src, sg_nents_for_len(src, src_len),
> +				   y + (key_sz - src_len), src_len);
> +	if (copied != src_len) {
> +		ret = -EINVAL;
> +		goto free_y;
> +	}
> +
> +	p_minus_1 = kmemdup(ctx->dh.xa_p + key_sz, key_sz, gfp);
> +	if (!p_minus_1) {
> +		ret = -ENOMEM;
> +		goto free_y;
> +	}
> +
> +	for (i = key_sz - 1; i >= 0; i--) {
> +		if (p_minus_1[i]-- != 0)
> +			break;
> +	}
> +
> +	if (!crypto_dh_pubkey_in_range(y, p_minus_1, key_sz))
> +		ret = -EINVAL;

[Severity: High]
Does this break the build when CONFIG_CRYPTO_DEV_HISI_HPRE is enabled?
crypto_dh_pubkey_in_range() is neither declared in include/crypto/dh.h nor
defined anywhere in the tree, causing hpre_crypto.c to fail to compile due
to an implicit function declaration.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125231929.1857637-1-rc4d5a@protonmail.com?part=1

  reply	other threads:[~2026-11-25 23:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 23:19 [PATCH v4] crypto: hisilicon/hpre - fix missing DH/ECDH public key validation Ryan Prinz
2026-11-25 23:29 ` sashiko-bot [this message]
2026-11-25 23:43 ` Ryan Prinz

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=sashiko-outbox-234403@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=davem@davemloft.net \
    --cc=giovanni.cabiddu@intel.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=liulongfang@huawei.com \
    --cc=rc4d5a@protonmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=songzhiqi1@huawei.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