* [PATCH] crypto: atmel-ecc - fix missing ECDH public key validation
@ 2026-11-25 23:18 Ryan Prinz
2026-11-28 1:28 ` Thorsten Blum
0 siblings, 1 reply; 2+ messages in thread
From: Ryan Prinz @ 2026-11-25 23:18 UTC (permalink / raw)
To: Thorsten Blum
Cc: Herbert Xu, David S . Miller, linux-crypto, linux-kernel,
Ryan Prinz
atmel_ecdh_compute_shared_secret() passes the peer's ECDH public point
into the ATECC508A/608A/608B secure element over I2C without checking
it first. The only check on req->src is on length
(req->src_len != ATMEL_ECC_PUBKEY_SIZE); the coordinates themselves are
never validated before atmel_i2c_init_ecdh_cmd() hands them to the
device.
crypto/ecc.c's ecc_is_pubkey_valid_partial() is the generic software
check for this operation: it rejects a point that is zero, out of
range, or not on the curve. crypto/ecdh.c's compute_shared_secret()
calls it before computing the shared secret. This driver's hardware
path has no equivalent check.
Both the generic implementation and this driver register under the
same crypto_kpp name, "ecdh-nist-p256". This driver registers at
cra_priority 300 (ATMEL_ECC_PRIORITY) versus the generic
implementation's 100, so any caller requesting "ecdh-nist-p256" gets
this unvalidated path whenever an Atmel/Microchip ECC device is bound.
net/bluetooth/smp.c allocates "ecdh-nist-p256" for LE Secure
Connections pairing and performs no validation of the remote device's
public key itself; it relies on the crypto_kpp backend
(net/bluetooth/ecdh_helper.c's compute_ecdh_secret() converts the
wire-format coordinates to the big-endian layout this backend expects,
but does not check their validity). Unlike this driver's HPRE
counterpart, nothing else in that path currently blocks the call from
reaching the unvalidated code: on a device with an Atmel/Microchip
secure element bound as its ECDH backend, a BLE peer can send an
invalid public key during pairing and force the resulting DHKey to
one of a small number of predictable values in a single pairing
attempt.
I don't have access to this hardware, so I checked whether the device
itself might reject an invalid point instead. The ATECC608A-TFLXTLS
datasheet (Microchip DS40002138A) documents the ECDH command (opcode
0x43) as combining the stored private key with the input X and Y
coordinates directly; its description includes no on-curve or range
check. The datasheet also lists "Public Key Validation Support" as a
device feature, but that refers to the Verify command's Validate and
ValidateExternal modes (see application note AN8932, "ATECC508A
Public Key Validation"), which validate a public key already written
to a device slot against a certificate chain before trusting it for
future signature verification. That is a provisioning-time operation
on a persistently stored key, unrelated to the ephemeral peer public
key passed as live input data to the ECDH command.
Fixed by validating the peer-supplied point before it reaches the I2C
command, reusing ecc_is_pubkey_valid_partial() the same way the
already-submitted HPRE fix does.
Fixes: 11105693fa05 ("crypto: atmel-ecc - introduce Microchip / Atmel ECC driver")
Signed-off-by: Ryan Prinz <rc4d5a@protonmail.com>
---
No Atmel/Microchip ECC hardware was available to reproduce this.
Verified by applying this patch to an unmodified kernel tree and
building drivers/crypto/atmel-ecc.o directly (make drivers/crypto/
atmel-ecc.o), confirming it compiles cleanly with no new warnings or
errors. The point validation reuses ecc_is_pubkey_valid_partial()
unmodified. I traced net/bluetooth/ecdh_helper.c's
compute_ecdh_secret() to confirm the src buffer it submits is
big-endian X (32 bytes) || big-endian Y (32 bytes) -- the same layout
crypto/ecc.c's own generic compute_shared_secret() expects and the
same layout atmel_i2c_init_ecdh_cmd() already consumes directly -- so
this driver's new validation step reads the same bytes the same way.
I could not test against the actual secure element; the datasheet
citation above is the basis for believing the device does not perform
this check itself.
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/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>
#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;
+
+ if (src_len != ATMEL_ECC_PUBKEY_SIZE)
+ return -EINVAL;
+
+ copied = sg_copy_to_buffer(src, sg_nents_for_len(src, src_len),
+ pubkey_buf, src_len);
+ if (copied != src_len)
+ return -EINVAL;
+
+ ecc_swap_digits(pubkey_buf, x, ECC_CURVE_NIST_P256_DIGITS);
+ ecc_swap_digits(pubkey_buf + ATMEL_ECC_NIST_P256_N_SIZE, y,
+ ECC_CURVE_NIST_P256_DIGITS);
+ pk = ECC_POINT_INIT(x, y, ECC_CURVE_NIST_P256_DIGITS);
+
+ return ecc_is_pubkey_valid_partial(curve, &pk);
+}
+
static int atmel_ecdh_compute_shared_secret(struct kpp_request *req)
{
struct crypto_kpp *tfm = crypto_kpp_reqtfm(req);
@@ -166,6 +196,10 @@ static int atmel_ecdh_compute_shared_secret(struct kpp_request *req)
if (req->src_len != ATMEL_ECC_PUBKEY_SIZE)
return -EINVAL;
+ ret = atmel_ecdh_peer_pubkey_valid(req->src, req->src_len);
+ if (ret)
+ return ret;
+
gfp = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? GFP_KERNEL :
GFP_ATOMIC;
--
2.51.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] crypto: atmel-ecc - fix missing ECDH public key validation
2026-11-25 23:18 [PATCH] crypto: atmel-ecc - fix missing ECDH public key validation Ryan Prinz
@ 2026-11-28 1:28 ` Thorsten Blum
0 siblings, 0 replies; 2+ messages in thread
From: Thorsten Blum @ 2026-11-28 1:28 UTC (permalink / raw)
To: Ryan Prinz; +Cc: Herbert Xu, David S . Miller, linux-crypto, linux-kernel
Hi Ryan,
Thanks for the patch.
Please shorten the commit message substantially and focus on the missing
software validation and how this patch adds it.
On Wed, Nov 25, 2026 at 11:18:08PM +0000, Ryan Prinz wrote:
> atmel_ecdh_compute_shared_secret() passes the peer's ECDH public point
> into the ATECC508A/608A/608B secure element over I2C without checking
> it first. The only check on req->src is on length
> (req->src_len != ATMEL_ECC_PUBKEY_SIZE); the coordinates themselves are
> never validated before atmel_i2c_init_ecdh_cmd() hands them to the
> device.
>
> crypto/ecc.c's ecc_is_pubkey_valid_partial() is the generic software
> check for this operation: it rejects a point that is zero, out of
> range, or not on the curve. crypto/ecdh.c's compute_shared_secret()
> calls it before computing the shared secret. This driver's hardware
> path has no equivalent check.
The function is ecdh_compute_value(). Validation then happens in
crypto_ecdh_shared_secret().
> Both the generic implementation and this driver register under the
> same crypto_kpp name, "ecdh-nist-p256". This driver registers at
> cra_priority 300 (ATMEL_ECC_PRIORITY) versus the generic
> implementation's 100, so any caller requesting "ecdh-nist-p256" gets
> this unvalidated path whenever an Atmel/Microchip ECC device is bound.
>
> net/bluetooth/smp.c allocates "ecdh-nist-p256" for LE Secure
> Connections pairing and performs no validation of the remote device's
> public key itself; it relies on the crypto_kpp backend
> (net/bluetooth/ecdh_helper.c's compute_ecdh_secret() converts the
> wire-format coordinates to the big-endian layout this backend expects,
> but does not check their validity). Unlike this driver's HPRE
> counterpart, nothing else in that path currently blocks the call from
> reaching the unvalidated code: on a device with an Atmel/Microchip
> secure element bound as its ECDH backend, a BLE peer can send an
> invalid public key during pairing and force the resulting DHKey to
> one of a small number of predictable values in a single pairing
> attempt.
Please drop this claim unless supported by testing or documentation.
Also, wolfSSL's public-key validation code [1] assumes that the devices
validate keys internally:
/* consider key check success on HW crypto
* ex: ATECC508/608A, CryptoCell and Silabs which validate the key
* internally
*/
Thanks,
Thorsten
[1] https://github.com/wolfSSL/wolfssl/blob/master/wolfcrypt/src/ecc.c#L12012-L12015
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-28 1:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 23:18 [PATCH] crypto: atmel-ecc - fix missing ECDH public key validation Ryan Prinz
2026-11-28 1:28 ` Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox