Received: by 10.213.65.68 with SMTP id h4csp685155imn; Fri, 6 Apr 2018 07:17:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx49KC0L+pMscFUIQ+pZ6PGrdilMbI/X2QGmGKZ9g05g8wRmVtL5Tk0/1lWM9zuakGAe5lk5K X-Received: by 10.99.99.194 with SMTP id x185mr17754233pgb.4.1523024229829; Fri, 06 Apr 2018 07:17:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523024229; cv=none; d=google.com; s=arc-20160816; b=zbQIwBWcHQV4z+fl8UFQiZOyKq8NC14Tf8kY/uus+rtFblaqx9fdoalxiEpgOOPR9o W1uDCxuJKKEQqLfPhjtNUXg5ln0Tw7oIUs0SnNsN5s7RmL6EywsSLZj95ykIoVxY7/jJ 0vqZfAoJ1f1palCeNbW1FHzu87rgwHASdtZBm9SmB0hqZxuJGGSLdrl+rnaG8y6zNoji 8djbuN9AjSo0f69drmbYrNEPdcADRTXL4Czy4lG3mi/T+RIDMtznJInYovvFw3hu21q8 ZdCAEaQ/y22E4ALZuXdr/YUVNZRUG3PlXU4Waj/C3ibBBuyy+Qrd+jyR6S2fppJK/XLn E2eA== 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=ZV/CNItST6gI1OePc6QV5odH2ItvLFkPpuS5OfeeJjA=; b=pYQk83PbpB3VRKKjVpBPIss7gETUDuXYnq2qHrWIgwZjhtldxHvJ/EgFrRSGGRpaUK 3RtbcV1KBrThlfpqWsVtr4XQGwQRk+RBwE9i9zxsHsvBiBGs7FLhATuFJUOb+HUs4TFU ptIL2DO7HBMGmhEuppwBqiuZ53p2NFzaSLhXHkPYkqu+jU5WswJ1MRGlbXM5dbc4Xw+o QjVnvEwn5whvuhXp4DzRbY8SxUu81LOKH3VUNulEpe8fGIcFgHcCLgjjpXQ/MssnyWex EXwd5WVDXBJrd2Uz7yNvBZ29eokC/CJNXJ3d3SyzPAj4V6CaY96pclhX7g0yoLUF36xD U2jg== 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 r3si7186083pgf.125.2018.04.06.07.16.55; Fri, 06 Apr 2018 07:17:09 -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 S932648AbeDFNj3 (ORCPT + 99 others); Fri, 6 Apr 2018 09:39:29 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34604 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932608AbeDFNj1 (ORCPT ); Fri, 6 Apr 2018 09:39:27 -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 E0A73D17; Fri, 6 Apr 2018 13:39:25 +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.14 51/67] crypto: ccp - return an actual key size from RSA max_size callback Date: Fri, 6 Apr 2018 15:24:21 +0200 Message-Id: <20180406084347.718756197@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084341.225558262@linuxfoundation.org> References: <20180406084341.225558262@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.14-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)