Received: by 10.223.185.116 with SMTP id b49csp1972822wrg; Sat, 24 Feb 2018 08:04:31 -0800 (PST) X-Google-Smtp-Source: AH8x224tftduFCbkIaCZ6XRZLlR85TKNxIb45VYbiTJNvDWpFUxRExXyKeAieKkfTwb3iro8tMtc X-Received: by 2002:a17:902:d203:: with SMTP id t3-v6mr5240487ply.70.1519488271707; Sat, 24 Feb 2018 08:04:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519488271; cv=none; d=google.com; s=arc-20160816; b=a4sJsYtfgFu3syeoR8XyCn+agCQj8eAfT/T8vCA1FtlmSey6Iy2OWQwWtti0cSUIGT drr5s7RqC07B4k9EUPeZDXwa1mRO/Zig//g9TJOvSCL0a2tvD8x8ojfzWwcv2SepC2Hs nohTA0nzL7gy5FUkjr7PevSmsBhVBrH/RJPwQeGWvHAQ+OWDohRXK/L0Gb/2x4u+uFS9 iYdo+KaF3g30DW+fA315U4KqlHh4QSgur1qRUsFY7xWe2VvsdKcGg8dKGyemmjUHgM0c U91eBpftwE0UY0ndkMY8JOmkV/6IjziDCWENZmvY2pz+e1yVOxZv6+aVcYdfun1Py2d+ 1luA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:cc:to :subject:from:arc-authentication-results; bh=c55981PZ3Oj5yXHjnkZSKfTe3vmvBPsyE5rWdmYP4Yw=; b=cdaK8D44SDeKg+06xoCV0KvUJ6UStnmw1ivlv8X4AQrit65D4sLjs5O3slFBFqv60O 4ySngnicmY42n2RV5sIEXCSGYTA3JD240hSmdyl45yVxhDHpPSq5NO1ixsTkpyuNVSJx AASfzhbCURILeM7+8LYBjMfhaXr0SUCQmeiO4DxSwNa0o8FKFYTa9sViZaHnJBc+B4bg zCx4/8I+6rDQvcCb9hxbg8IKGhFz8ocxE6MonUD27Hzrbp6ZWj0UlQCFiEAZemtrTBU6 ufbh9LwHp08oMsR5kGDbwZ2D1wFd9X9WbHzEkhnRzZyZucUFQcKRi5YdPAfi8eJrNqX9 JS5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d186si3090902pgc.600.2018.02.24.08.04.16; Sat, 24 Feb 2018 08:04:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751568AbeBXQD3 (ORCPT + 99 others); Sat, 24 Feb 2018 11:03:29 -0500 Received: from vps-vb.mhejs.net ([37.28.154.113]:41684 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751514AbeBXQD0 (ORCPT ); Sat, 24 Feb 2018 11:03:26 -0500 Received: by vps-vb.mhejs.net with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89) (envelope-from ) id 1epcIE-0003zk-5S; Sat, 24 Feb 2018 17:03:22 +0100 From: "Maciej S. Szmigiero" Subject: [PATCH 2/3] crypto: ccp - return an actual key size from RSA max_size callback To: Herbert Xu , "David S. Miller" Cc: David Howells , Tom Lendacky , Gary Hook , keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <51c265e4-6153-3e5e-316a-ebef059ac36a@maciej.szmigiero.name> Date: Sat, 24 Feb 2018 17:03:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org rsa-pkcs1pad uses a value returned from a RSA implementation max_size callback as a size of an input buffer passed to the RSA implementation for encrypt and sign operations. CCP RSA implementation uses a hardware input buffer which size depends only on the current RSA key length, so it should return this key length in the max_size callback, too. This also matches what the kernel software RSA implementation does. Previously, the value returned from this callback was always the maximum RSA key size the CCP hardware supports. This resulted in this huge buffer being passed by rsa-pkcs1pad to CCP even for smaller key sizes and then in a buffer overflow when ccp_run_rsa_cmd() tried to copy this large input buffer into a RSA key length-sized hardware input buffer. Signed-off-by: Maciej S. Szmigiero Fixes: ceeec0afd684 ("crypto: ccp - Add support for RSA on the CCP") Cc: stable@vger.kernel.org --- drivers/crypto/ccp/ccp-crypto-rsa.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/ccp/ccp-crypto-rsa.c b/drivers/crypto/ccp/ccp-crypto-rsa.c index e6db8672d89c..05850dfd7940 100644 --- a/drivers/crypto/ccp/ccp-crypto-rsa.c +++ b/drivers/crypto/ccp/ccp-crypto-rsa.c @@ -60,10 +60,9 @@ static int ccp_rsa_complete(struct crypto_async_request *async_req, int ret) static unsigned int ccp_rsa_maxsize(struct crypto_akcipher *tfm) { - if (ccp_version() > CCP_VERSION(3, 0)) - return CCP5_RSA_MAXMOD; - else - return CCP_RSA_MAXMOD; + struct ccp_ctx *ctx = akcipher_tfm_ctx(tfm); + + return ctx->u.rsa.n_len; } static int ccp_rsa_crypt(struct akcipher_request *req, bool encrypt)