Received: by 10.213.65.68 with SMTP id h4csp659039imn; Fri, 6 Apr 2018 06:55:27 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/nV6aoRE3Vxcc/oYfPCK/2dEYsBmQIVov3Yksumq0ekebaKZyttCUMa7hDeZJM3oI/yBxQ X-Received: by 2002:a17:902:9a86:: with SMTP id w6-v6mr27211009plp.168.1523022927573; Fri, 06 Apr 2018 06:55:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523022927; cv=none; d=google.com; s=arc-20160816; b=ojP+q4IfQM40co4lUx71fevO0glBp9Idm+wd356CKz5IksGfV2JOu4W1rlfnXesxVH puEhNdhihdQ9p0HmB7QCzPPfX5mPCdnGQhZ+l7VKU9NfO584Vlp1qFatJSI1beHZ8hhx ayzgCCQ+DHs/llqWsXKVR/lOuyXBO+EMs6YGATFTSIpVg57SS6oWh/2d0gC+Rb614MVS o2Tl6Sj/9qmF7q0YQVOTTEjaqaP5OGBK6spvKCb/6jJVyRIgg1tODqCsVqfh5N0FGEgv tE0XE+92jAdbsLSG0rIT1uSiRB4R9gbUsS6O0tJ7QYzZh/3L7PTQeRYoCkN1UeKixo+G p6jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=H26ZFI7/ZqoZBtWZ7mvV0gvxONhBRteOW90j5NE5w+U=; b=TY8rWJVCkbAujMlDBpLSV/N5EpUkWuIv0ik+XKGnliKRq1Ot/jZIAvVz2NsNHmvck5 XAh8X7PgU8nPDxWFcwMnh1eE2ih8PSBAFnY8k6uO/vww7eYFuMPYKbIlcluGNs/Oxtkt 687+e55lp7r2azqgsN6FiS2rbgyAzYIEAZguv1x9plsf8HAgG6B01G9k/Mlb5fPOme81 yu7956eykPP+N6P64eKVmP5dNoMR60Kq+ec628HPMccAlI0uKzBzuSsTObMgBb2JLq/L 9brtncSe8J0AgU6CJU1Nti4LIgPXOTQNEPGzzcLj8DtOqxsYmgnSn05rvbwpmeh2V2sx ELIA== 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 x8-v6si7876644plv.420.2018.04.06.06.55.13; Fri, 06 Apr 2018 06:55:27 -0700 (PDT) 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 S1756854AbeDFNoG (ORCPT + 99 others); Fri, 6 Apr 2018 09:44:06 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37520 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752846AbeDFNoC (ORCPT ); Fri, 6 Apr 2018 09:44:02 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 19C72E04; Fri, 6 Apr 2018 13:44:00 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Maciej S. Szmigiero" , Gary R Hook , Herbert Xu Subject: [PATCH 4.15 56/72] crypto: ccp - return an actual key size from RSA max_size callback Date: Fri, 6 Apr 2018 15:24:31 +0200 Message-Id: <20180406084353.247534053@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084349.367583460@linuxfoundation.org> References: <20180406084349.367583460@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Maciej S. Szmigiero commit 0a9eb80e643064266868bd2fb2cd608e669309b0 upstream. 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 Acked-by: Gary R Hook Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/ccp/ccp-crypto-rsa.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- 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 crypt 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)