From: Ryan Prinz <rc4d5a@protonmail.com>
To: Thorsten Blum <blum@kernel.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
"David S . Miller" <davem@davemloft.net>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
Ryan Prinz <rc4d5a@protonmail.com>
Subject: [PATCH v3] crypto: atmel-ecc - fix missing ECDH public key validation
Date: Sat, 28 Nov 2026 08:46:06 +0000 [thread overview]
Message-ID: <20261128084418.2057984-1-rc4d5a@protonmail.com> (raw)
In-Reply-To: <awouRON5Mgq6pbhf@kernel.org>
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.
Add the same check to this driver's path, before the point reaches the
I2C command, reusing ecc_is_pubkey_valid_partial().
Fixes: 11105693fa05 ("crypto: atmel-ecc - introduce Microchip / Atmel ECC driver")
Signed-off-by: Ryan Prinz <rc4d5a@protonmail.com>
---
v3: Shortened the commit message, moving supporting detail below
this line. No functional change.
Both implementations register as crypto_kpp "ecdh-nist-p256"; this
driver's higher cra_priority (300 vs. the generic implementation's
100) is why it's selected instead whenever an Atmel/Microchip ECC
device is bound, so the generic validation never runs for this
driver.
v2: Fixed the crypto/ecdh.c function names (ecdh_compute_value() is
the registered callback; validation happens in
crypto_ecdh_shared_secret()) and dropped the unsupported Bluetooth
SMP reachability claim. (Thorsten Blum)
This has not been tested on hardware. The ATECC608A-TFLXTLS datasheet
(Microchip DS40002138A) describes the ECDH command (opcode 0x43)
combining the stored private key with the input coordinates directly,
with no on-curve or range check documented. Its "Public Key
Validation Support" feature is the Verify command's
Validate/ValidateExternal modes (AN8932), which validate a
persistently stored key against a certificate chain at provisioning
time, which is a different operation from validating the ephemeral
peer public key given as live input here.
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
ecdh_compute_value() expects and atmel_i2c_init_ecdh_cmd() already
consumes directly.
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
next prev parent reply other threads:[~2026-11-28 8:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 23:18 [PATCH] " Ryan Prinz
2026-11-28 1:28 ` Thorsten Blum
2026-11-28 8:46 ` Ryan Prinz [this message]
2026-11-28 17:25 ` [PATCH v3] " Thorsten Blum
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=20261128084418.2057984-1-rc4d5a@protonmail.com \
--to=rc4d5a@protonmail.com \
--cc=blum@kernel.org \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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®