Received: by 10.213.65.68 with SMTP id h4csp650349imn; Fri, 6 Apr 2018 06:46:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx48Sm8J5rTYrUhMZFtVKg0/qUolc38+glr0i4gkHNc4ESkdzPgM2C1BcWb2D8OLtDeta3z81 X-Received: by 10.98.220.86 with SMTP id t83mr20488841pfg.60.1523022400220; Fri, 06 Apr 2018 06:46:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523022400; cv=none; d=google.com; s=arc-20160816; b=RYs6Vqjf5xMUghpGC89Vr0UYhh8Fwb4lped4hu0g23JheSiQQaajT9gMdtXmQS40ZN XIGITmLMVcdIixBlZTxipzD1vwJqOeFRcgw8f5f55VgQX53N8f5LBa+lSNYvL6fx2hLz QNGG4UavTeqmed9+HtWxWYWYlTODUVtBTkfSM8T2pxwQxA6cl6BPpML4LrZlaQQ9ZcGp Eregv/baZuwk5FY2xlb1ktIn3XNfUGA7MYHmm5dK0QbPK7Bcb/+tc4FBdBBn61StAOTu ztjhxHnbU6u+NtnFRfyrAX0d85Tvwh2Def3qAmIvFJeysdd8yErY6p46yw0yphsD7glA AYRg== 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=xt21BsbpyXeY6XFv68ChrN/x87LGf3yqH5RDfy8frAU=; b=FwoZlhzuTuBxmc8t0McOPWWw/dvvi1JD10x/X4YRZ/XgVOzir5Gg+eu+Bn9kJLO+oP P9mNZLoUUFd7eC1SLGllMzJjwq+3Bi5jsm78qmi/klf1Y4E5Xa0BoubCem9lhzvroUP4 vLCU0yVATx7oV164gTYEgesND5pH+NVVSu1z7BDzVRDbxqTswb51pcAKbxjzeIXoE2qn MnFUgaZMca5jyvNXNrCYqyBjrVCioHZIyjQGr7dP+lh9EzCgLwK33wQc8HLwBPpRhoav Ky3XWuD+UGdtvVtq94NGRdukrJjDubwIW9frCf3IJhXEkZ4jsgE9nDyrXjf5Gl+CylEP Nusg== 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 c76si7253400pga.156.2018.04.06.06.46.26; Fri, 06 Apr 2018 06:46:40 -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 S932957AbeDFNon (ORCPT + 99 others); Fri, 6 Apr 2018 09:44:43 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37810 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756931AbeDFNoj (ORCPT ); Fri, 6 Apr 2018 09:44:39 -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 B2B76E10; Fri, 6 Apr 2018 13:44:38 +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.16 18/31] crypto: ccp - return an actual key size from RSA max_size callback Date: Fri, 6 Apr 2018 15:24:43 +0200 Message-Id: <20180406084343.491606651@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084340.999820380@linuxfoundation.org> References: <20180406084340.999820380@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.16-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)