Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3532571pxb; Mon, 1 Mar 2021 12:30:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNJxx3tpsBKpqdp5/3wsXNJSDBU8KYOoFeENPk92dB6B00T2kiJbSof5PJ+qCd528u36Zb X-Received: by 2002:a05:6402:1c1b:: with SMTP id ck27mr16278730edb.223.1614630637688; Mon, 01 Mar 2021 12:30:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614630637; cv=none; d=google.com; s=arc-20160816; b=X+3tmjqox/YuZOjypw9un+8K9NAZcHb/ZZ7/jHc+IFZzQUqZpIbNsh1BZRrnFJrKCa 763Vb3wMygEIjt1sjqQDeV4PS34KTZtpIqpiqE15TJ7htQdPyzF9bz+7wyOcszVBglNw dubwYpj+wVuoaiZlSU5SUcWhyeuP2L9dfjw1JJzkll53YU+Rov/fyZ/Rh6q8thHLD36S PYoEVLLE2zCldYSPI/hEDa9F7kZq44nkgLbk0XCQrRJeDhf0F/ES+o05gV11n+kYbAll kcWiSutotUAVN0F7VLnZ8XUGUspjO21pGn80yHSzMutRBGj+aB4+QTaQ3JBjaSy86HGW j/Vg== 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=qNRfOGzbGvmN+HfrF6AXKG4VF3ntTZ1M1HAiRdKmhfs=; b=H3zkUCjIZeS0ZJ386JpwM4f9DUCJcHvxYZZMJcsWWzeL03Vjzpix7GF5BflusQ0fSh ELks3fxL4v/0VDHni4UM2FyvvRFQxeyfupps+wTXmDp5hjYvYNAtc1ILoLseLOHf5qBC mNbXidy9SMbCqDYx/uBnJD5NmoDdLY53T16c7QujrZetat3YzVnk8YcxjamBsbwdTXbG 2+Bn+rkBwl1C+4qZF9Ja8Jfy30PHllTkAlfP1V47AAc+/q1tVun/Gu6eY5T9KA8NCUy8 IIIDTDTnrO5+kphLnMg2o/LfiTmC7wEZGhg81+cH4v5+pN45TqBcz83Ox39up2iTAM8M D3dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UMaDK01c; 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 g23si4682530ejx.623.2021.03.01.12.30.14; Mon, 01 Mar 2021 12:30:37 -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=UMaDK01c; 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 S243355AbhCAU2K (ORCPT + 99 others); Mon, 1 Mar 2021 15:28:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:37784 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237036AbhCARGj (ORCPT ); Mon, 1 Mar 2021 12:06:39 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E249964FFF; Mon, 1 Mar 2021 16:40:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614616804; bh=gEwa+3ufdeE1cgHbyYT7OOyBi4lHyDbSWa9ThJ/Is5M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UMaDK01c+xu89QGMXk4QZbzbcX0/bUbP6sfG3lfPOcjO6PZdfO+jOBFSrD3n3k+s6 XiJ/unSJpOaPGz3MkS2Myqd1M09Cv6OQfRrT9MLeyEp4yk80wStb0j0SS8xkEjejKW TV8bg3nMUG+fVj1OKXfqsRr4PxxzvkHCMv8VXO+I= 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 4.19 102/247] crypto: ecdh_helper - Ensure len >= secret.len in decode_key() Date: Mon, 1 Mar 2021 17:12:02 +0100 Message-Id: <20210301161036.673785950@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@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 d3af8e8b0b5e4..25711de445848 100644 --- a/crypto/ecdh_helper.c +++ b/crypto/ecdh_helper.c @@ -71,6 +71,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