Re: [PATCH v3] crypto: atmel-ecc - fix missing ECDH public key validation

From: Thorsten Blum

Date: Sat Nov 28 2026 - 12:25:32 EST


Hi Ryan,

This should probably have been submitted as v2, not v3, but let's
continue with v4.

Please post each revision as a new thread to the list and not as a reply
to a review.

On Sat, Nov 28, 2026 at 08:46:06AM +0000, Ryan Prinz wrote:
> atmel_ecdh_compute_shared_secret() passes the peer's ECDH public point
> to the ATECC508A/608A/608B secure element without validating it; only
> req->src_len is checked.

Please clarify that this refers to software validation, as the device
may perform its own hardware validation.

> Add the same check to this driver's path, before the point reaches the
> I2C command, reusing ecc_is_pubkey_valid_partial().

Which same check? Somebody reading this later in the git history will
have no idea what you're referring to without the context of earlier
revisions.

[...]

> drivers/crypto/atmel-ecc.c | 34 ++++++++++++++++++++++++++++++++++
> 1 file changed, 34 insertions(+)
>
> diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c
> --- a/drivers/crypto/atmel-ecc.c
> +++ b/drivers/crypto/atmel-ecc.c
> @@ -19,7 +19,9 @@
> #include <linux/slab.h>
> #include <linux/workqueue.h>
> #include <crypto/internal/kpp.h>
> +#include <crypto/ecc_curve.h>
> #include <crypto/ecdh.h>
> +#include <crypto/internal/ecc.h>

Please keep the crypto includes in alphabetical order.

> #include <crypto/kpp.h>
> #include "atmel-i2c.h"
>
> @@ -146,6 +148,34 @@ static int atmel_ecdh_generate_public_key(struct kpp_request *req)
> return 0;
> }
>
> +static int atmel_ecdh_peer_pubkey_valid(struct scatterlist *src,
> + unsigned int src_len)
> +{
> + const struct ecc_curve *curve = ecc_get_curve(ECC_CURVE_NIST_P256);
> + u8 pubkey_buf[ATMEL_ECC_PUBKEY_SIZE];
> + u64 x[ECC_CURVE_NIST_P256_DIGITS], y[ECC_CURVE_NIST_P256_DIGITS];
> + struct ecc_point pk;
> + size_t copied;
> +
> + if (!curve)
> + return -EINVAL;

This check can be dropped as ecc_get_curve(ECC_CURVE_NIST_P256) always
returns a valid pointer.

> + if (src_len != ATMEL_ECC_PUBKEY_SIZE)
> + return -EINVAL;

The caller already checks the length, so this check is also redundant.

> + copied = sg_copy_to_buffer(src, sg_nents_for_len(src, src_len),
> + pubkey_buf, src_len);

Could we validate work_data->cmd.data after atmel_i2c_init_ecdh_cmd()
and before enqueueing? That would avoid an extra copy.

Thanks,
Thorsten