Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp495236pxb; Wed, 3 Mar 2021 08:14:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwHhOYKXu7ddfC2SQYpg49CP4+XJ3oWmtRHPxnDVuWegoRs5erEj8/3b68v5skt4XDG51go X-Received: by 2002:a05:6402:51cd:: with SMTP id r13mr18629edd.214.1614788060200; Wed, 03 Mar 2021 08:14:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614788060; cv=none; d=google.com; s=arc-20160816; b=xWbA0vqlyHTVd18OdHLAqo0rCO/AiPh3BUXPN0FnwZAW+DpGQroyalGcdTjtF8OorE osBsmYyyfb/2eUx8hUfPBe0QFAndnbeE1Ux+gek1yq/6vOR/i4GRUin0GzIgjWlZOnqy QSsnbay9/V1mdIUfLsflwUWsLrKzXID4WUHPTbgWhDbzpuJh07oWHol8zUuw1uSbzs2C CrRkxwmTRBdCr9vwyr4W3HTefIwQsgc8rb7R3R81B/DZRgsNMLz68li+KqR315IBklts 3m7MXFT2p/woHJ5pwEefUN7Y5CObxCzgpOVEY5/EWw1Mjz9kvHGPBSNnd7iU7nYTz5YD dIzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Jax3QQ5zqluGHUkSRYvX5CcHwb14N3fYz7oPPlUavi0=; b=FxHfjhT6tBP7GJHldvJOf4Ji+pUmNFztSmzzGc2PDSLz89o2hMV/wjDnkyCBGw5U0V QMGFuCKq30TuDbPhZbQUHQ2y2vrDWXlTB2ZHnwWfJc+8TsSuOWe9LZYvhF1qUIErplPr ZuoNyOupSh/U99ihplO8eQ3bKIutuwfI2iKOUEOthO2jWVkfSTJYrWTMoVfB4DT3arxY tBkxnTpA6/Q7jwlVVfXmyHoJYwJK6ReT0YIGwQJWaMnVyxz/LC2r1xLsuKwvH/yv6pec qfpknK5s/guWlbUOrdvgFR4iu1GomRJC/7CWnHUMpxCLCcDc5RFn6skeIsMxpqtpqxVu rA4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K7PB5Po2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m9si15522547edl.120.2021.03.03.08.13.10; Wed, 03 Mar 2021 08:14:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K7PB5Po2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235251AbhCAXlV (ORCPT + 99 others); Mon, 1 Mar 2021 18:41:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:57184 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239377AbhCASIg (ORCPT ); Mon, 1 Mar 2021 13:08:36 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6747164EE9; Mon, 1 Mar 2021 17:14:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614618843; bh=qA2TRLyly4mfWKsGE8VnSuu01WrBUCQNqc7S0NQ+JhI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K7PB5Po2XfJa4/20XofU836DOavw/fqLsTluY2uskWtH7aem2od1a4v4Ytg/15jI3 ieD1Nu7WZBDIKlHEdEFQO5odvD+aSP2vQlVgs6e09DTM9WkrEIZnbbV5snXCSZjbAD ZKzBD9enIY27TX0wmVwFiFaGC170pjwriiSgjjIU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniele Alessandrelli , Herbert Xu , Sasha Levin Subject: [PATCH 5.10 238/663] crypto: ecdh_helper - Ensure len >= secret.len in decode_key() Date: Mon, 1 Mar 2021 17:08:06 +0100 Message-Id: <20210301161153.596865667@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniele Alessandrelli [ Upstream commit a53ab94eb6850c3657392e2d2ce9b38c387a2633 ] The length ('len' parameter) passed to crypto_ecdh_decode_key() is never checked against the length encoded in the passed buffer ('buf' parameter). This could lead to an out-of-bounds access when the passed length is less than the encoded length. Add a check to prevent that. Fixes: 3c4b23901a0c7 ("crypto: ecdh - Add ECDH software support") Signed-off-by: Daniele Alessandrelli Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- crypto/ecdh_helper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crypto/ecdh_helper.c b/crypto/ecdh_helper.c index 66fcb2ea81544..fca63b559f655 100644 --- a/crypto/ecdh_helper.c +++ b/crypto/ecdh_helper.c @@ -67,6 +67,9 @@ int crypto_ecdh_decode_key(const char *buf, unsigned int len, if (secret.type != CRYPTO_KPP_SECRET_TYPE_ECDH) return -EINVAL; + if (unlikely(len < secret.len)) + return -EINVAL; + ptr = ecdh_unpack_data(¶ms->curve_id, ptr, sizeof(params->curve_id)); ptr = ecdh_unpack_data(¶ms->key_size, ptr, sizeof(params->key_size)); if (secret.len != crypto_ecdh_key_len(params)) -- 2.27.0