From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=109.224.244.17 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795902668; b=L+oVTNvueXY4YVziuUq8BqZF8VZoJCjpBiDR55YKQKYmkmNDmjQmjiEzgH3YiTWPdVfH DEPEH9o/bsJQrtkKcSu8a8YyYJMmXnKlCsWIMF1iBkJMNnaE3qh19s039sviIK8HwqSgI PUejNkfW3pZ3RNf7aIhl5uSPudki8GyTScpKz2xm5W4u8mWwd4nKnZ+o9hKMmJ+6Foc+M RoJi/JrDeY1RHkdnhr2BA6iQpW8dPx8p+RfT2JoPtPxJ6APehJrCvYY7vXkUA6EVkhA5N FDvWzu3AngaPlDQZ72TTQvuXsBjhkmiqqe9ROTrq/nyuK9BxWoNpVkVDGnW70C/KSyA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795902668; 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=weD15bfj9hhEnUn2CSsRsaDGjvIYtoCfLaLvtYpJxXc=; b=xTN7pZZXtUiAHRt9jMiXrnUSt5dKKhHZnjZ07swE4//TGVD3t2/Ep84/6z8FfIae3TaO 1PJ2em+vEnSgOGJTb2avUrXyqlQyLLunDQ81E+9jGZLsTtQSZh3sUYzNp3NzmJ99rxovT 12i5/+toaV534VFP4/BPGhS/VGfyiSJG5uADdrbJ2X8R9sD8/OkwQn0FlrZ+5f/BlqziZ d3Jr2KCa+5m2Vrn+1FyzvRApzEbRMzGzbOhvx2AtomQ/gsihbtfGQ8oaS35hjJ8vgcuid PONYqH/BP6IxgVnw2vyrVV0FVo/mzqcQhkCY9OwZw3w1QHe9VvmbxbQsU81PFdd9zVA== 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=ImKdhq7O; arc=none smtp.remote-ip=109.224.244.17 Received: from mail-24417.protonmail.ch (mail-24417.protonmail.ch [109.224.244.17]) (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 590CB606A323 for ; Sat, 28 Nov 2026 21:51:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 590CB606A323 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=ImKdhq7O DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1795902665; x=1796161865; bh=weD15bfj9hhEnUn2CSsRsaDGjvIYtoCfLaLvtYpJxXc=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=ImKdhq7OgCNde94zI+6rVtoqkHJulvrRVjx2uGJ2hOBkpbu81EEgwPtgGE0BFgHEh J8Yc/ZWEz3W4ediWIwU4Y06UeN8q/f6JVJjSlAIv/JD4zbMWTGwXkwAWnUY8GVG0q1 iHvJxn47Bp+empDiiBbdmdGl6rZsbOqG3tjf9svPyQodQjUAyWezqrVAc+BC5Jl4Zm gQwCecype4bCCwakQE7/MBx67BybRti/02UOFc7N5LCsqVs+UH2RnGhJTZ33X38Y8H 3GlqKt3HMiWzS5Zc157bzt+XMod92p9TVT/CImrUYeruD5XjkW1sIg0CGNKcjNF7Ha ZJoHo75uE9F3g== Date: Sat, 28 Nov 2026 21:51:00 +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 v4] crypto: atmel-ecc - fix missing ECDH public key validation Message-ID: <20261128215039.27155-1-rc4d5a@protonmail.com> Feedback-ID: 190731814:user:proton X-Pm-Message-ID: 272553fb771dbd6dc76ca20b8ca321b44c9d1eed 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 --- 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 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 | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) 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 @@ -17,8 +17,10 @@ #include #include #include #include -#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; } +static int atmel_ecdh_peer_pubkey_valid(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); @@ -181,8 +197,14 @@ static int atmel_ecdh_compute_shared_secret(struct kpp= _request *req) =09=09kfree(work_data); =09=09return ret; =09} +=09ret =3D atmel_ecdh_peer_pubkey_valid(work_data->cmd.data); +=09if (ret) { +=09=09kfree(work_data); +=09=09return ret; +=09} + =09atmel_i2c_enqueue(work_data, atmel_ecdh_done, req); =09return -EINPROGRESS; } -- 2.51.2