From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.70.43.22 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796042644; b=cPgOOQdRjHwaNBqtl7RzvdYNqLxb+Th/A66Jr1KFeQHjlp3TFYAOOXRydwgSLTGgxOKW D+eFNMJxW+rL5ovy1iesyz8RDgKkFhqOpzKdldK0w2kg1qzqrckIe4lw+KhXsLMRLvVO9 NxaCqZD5JsBLLg5MXBuhJtxmwCUfPWYg4fwYk4GAsAUCtME3X6HHhihymsvSPmC6c0hzE kPe1A5BwhudQ1REFDWAiWPE9fjD2+djQfqXZ/+hHxniGhejQq1Wfnc24AeOlWe2A2NrqG 2DjZ3w/A5cfON43sGWoS93mkoB0l44eKBPerNDiWzbHHDogQb3ig797RYaI6tPLKCTA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796042644; h=DMARC-Filter:DKIM-Signature:Date:To:From:Cc:Subject:Message-ID: Feedback-ID:X-Pm-Message-ID:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=IvNG0IVdh6a3p63fNsNNH7rvPStbJ9CnmHoEOkvfQG0=; b=M0tOOTKJYNzT3DYMfrthPbxUmRrYtb9HQco/QKBsxbqSkgX1BRuvJHBAXNYJQNc4/7FV y6Lk3WyOVkrsFCJ8tstR8UeZPX/nWGz0XjaYJhiNaYNeiwCFKJAVqFieFrytzdkkzLSGT kwGThblTq0FM1+HMJLgzfCBtE9/0zs7x4vat3N2MdqRrgmHsjNWm4JRywIR0SE99u2Fuo 23ssTtFVyZv1r8ZzQMfXkC90lvXjKZmK+rUIAye3kKpuWFZhq4n1hJTJyOXzXSDpmfNx0 fQzg/fk0E8u8dQOmDjE/MfTgVD9OQm6LbIl06MyTM1H7j1laCrlPI22BnlivB8dGq+A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=protonmail.com; spf=pass smtp.mailfrom=protonmail.com; dkim=pass header.d=protonmail.com header.i=@protonmail.com header.a=rsa-sha256 header.s=protonmail3 header.b=rjYqgAii; arc=none smtp.remote-ip=185.70.43.22 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F360B606A31C for ; Mon, 30 Nov 2026 12:44:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F360B606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=protonmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=protonmail.com header.i=@protonmail.com header.a=rsa-sha256 header.s=protonmail3 header.b=rjYqgAii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1796042639; x=1796301839; bh=IvNG0IVdh6a3p63fNsNNH7rvPStbJ9CnmHoEOkvfQG0=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=rjYqgAiiur3iy7jxP5qZZkeGpeiRUCQ9YqNfZrnZRchHw+Kv1xjzPtNHLqZrFfFHI BXjc6326vvMAz1OjLbrmvvykJn3jjiLXG6FE9vm6mKq/K5zGnH71hCyCOPNGSrgVq6 UEbZR2uDGD2pbT/8ewixXdrVY36ARBNHsYMZVGwvkAfFSoZboW29h7WreW8UCkxAzg f3fAJ/vbJjao9ZJNNPnoNRdlt/me/VVGaqvNaVIs14UMkurw4OKVeE0LUhc0BfDjEi BEeRaDw5pSYDj1wZzHxUJzhan14hYwwBjoXHBOnWakuqhuhh3WquGWEmnZhI2FqRvJ evtQrc3x0eapg== Date: Mon, 30 Nov 2026 12:43:51 +0000 To: Thorsten Blum From: Ryan Prinz Cc: Herbert Xu , "David S . Miller" , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Ryan Prinz Subject: [PATCH v5] crypto: atmel-ecc - fix missing ECDH public key validation Message-ID: <20261130124327.200984-1-rc4d5a@protonmail.com> Feedback-ID: 190731814:user:proton X-Pm-Message-ID: 2cfc62e4326fb716bc122e61aabc4fbc56ec9d33 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable atmel_ecdh_compute_shared_secret() passes the peer's ECDH public point to the ATECC508A/608A/608B secure element without software validation; only req->src_len is checked. Validate the point in software before it reaches the I2C command, the same check crypto_ecdh_shared_secret() performs for the generic "ecdh-nist-p256" implementation: call ecc_is_pubkey_valid_partial() and reject the request if it fails. Fixes: 11105693fa05 ("crypto: atmel-ecc - introduce Microchip / Atmel ECC d= river") Signed-off-by: Ryan Prinz --- v5: Regenerated the diff and verified. Renamed atmel_ecdh_peer_pubkey_valid() to atmel_ecdh_validate_peer_pubkey(), since it isn't a predicate. Grouped the crypto/internal/* includes together before the other crypto/* includes, each group alphabetized. Removed personal validation claim that could be confused with the vulnerability having been verified on hardware. (Thorsten Blum) v4: Clarified that the missing check is software validation, since the device may still validate internally in hardware. Reordered the crypto/ includes alphabetically. Dropped the curve-NULL check (ecc_get_curve(ECC_CURVE_NIST_P256) never returns NULL) and the length check (the caller already validates req->src_len). Validate directly from the already-populated ECDH command buffer (work_data->cmd.data) instead of a second sg_copy_to_buffer() from the scatterlist, avoiding the extra copy. (Thorsten Blum) 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, reading X and Y directly out of work_data->cmd.data, which atmel_i2c_init_ecdh_cmd() already documents and populates as big-endian X (32 bytes) || big-endian Y (32 bytes) -- the same layout crypto_ecdh_shared_secret() expects from req->src before this driver ever sees it. AI Disclosure: An AI assistant was used to assist with the analysis and testing. I take responsibility for this contribution, per Documentation/process/coding-assistants.rst. drivers/crypto/atmel-ecc.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index b538e818a26f..c0883ef5bf5a 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -18,7 +18,9 @@ #include #include #include +#include #include +#include #include #include #include "atmel-i2c.h" @@ -146,6 +148,20 @@ static int atmel_ecdh_generate_public_key(struct kpp_r= equest *req) =09return 0; } =20 +static int atmel_ecdh_validate_peer_pubkey(const u8 *pubkey_buf) +{ +=09const struct ecc_curve *curve =3D ecc_get_curve(ECC_CURVE_NIST_P256); +=09u64 x[ECC_CURVE_NIST_P256_DIGITS], y[ECC_CURVE_NIST_P256_DIGITS]; +=09struct ecc_point pk; + +=09ecc_swap_digits(pubkey_buf, x, ECC_CURVE_NIST_P256_DIGITS); +=09ecc_swap_digits(pubkey_buf + ATMEL_ECC_NIST_P256_N_SIZE, y, +=09=09=09ECC_CURVE_NIST_P256_DIGITS); +=09pk =3D ECC_POINT_INIT(x, y, ECC_CURVE_NIST_P256_DIGITS); + +=09return ecc_is_pubkey_valid_partial(curve, &pk); +} + static int atmel_ecdh_compute_shared_secret(struct kpp_request *req) { =09struct crypto_kpp *tfm =3D crypto_kpp_reqtfm(req); @@ -182,6 +198,12 @@ static int atmel_ecdh_compute_shared_secret(struct kpp= _request *req) =09=09return ret; =09} =20 +=09ret =3D atmel_ecdh_validate_peer_pubkey(work_data->cmd.data); +=09if (ret) { +=09=09kfree(work_data); +=09=09return ret; +=09} + =09atmel_i2c_enqueue(work_data, atmel_ecdh_done, req); =20 =09return -EINPROGRESS; --=20 2.51.2