From patchwork Sat Dec 12 05:03:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 7834161 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 75CEB9F1C2 for ; Sat, 12 Dec 2015 05:04:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7C743203F4 for ; Sat, 12 Dec 2015 05:04:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7AA29203F3 for ; Sat, 12 Dec 2015 05:04:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750784AbbLLFED (ORCPT ); Sat, 12 Dec 2015 00:04:03 -0500 Received: from mail-qk0-f180.google.com ([209.85.220.180]:34704 "EHLO mail-qk0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750800AbbLLFEC (ORCPT ); Sat, 12 Dec 2015 00:04:02 -0500 Received: by qkdp187 with SMTP id p187so69260430qkd.1 for ; Fri, 11 Dec 2015 21:04:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id; bh=wFnw0Ap2B6kiuhcWl70xDPGGvcyqGMEiRrxIFmCwmMo=; b=mBbfGsb+evCUks0SIKWME66OCgdpPqApkZodh3qj2xmDpYoP1nDcgxLayYtc7oPik0 7UlT3mW4KWEWv61L1ppfU2AAQqconQ4UKSLwFUR6ZXWgEN0p8AanuybaI9YpJPrW2mXz xiDL+j+aJ7WZzKmRmV1nAEsTZBKH4MI/GZoGQsCG/uXaqSq2x9o4ZZeEvQK3aJzJfneK 47sde25YMlfqufgejsOyzmfIhra6Pxv8kWB5pCeCgnOZ4e+M03C1CyoZbOfV2+Hvzzwc aGGSefYsSXRXYBAYU+xCv7PWTv59kUhsvRqbUnnSP+0kpPRFt5Qes1F1GLhddmEfmuXh NaTw== X-Received: by 10.13.201.131 with SMTP id l125mr11476185ywd.150.1449896641830; Fri, 11 Dec 2015 21:04:01 -0800 (PST) Received: from localhost.localdomain ([190.234.106.52]) by smtp.gmail.com with ESMTPSA id b126sm15208402ywd.3.2015.12.11.21.04.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Dec 2015 21:04:00 -0800 (PST) From: Andrew Zaborowski To: linux-crypto@vger.kernel.org Subject: [PATCH] crypto: rsa-padding - don't allocate buffer on stack Date: Sat, 12 Dec 2015 00:03:51 -0500 Message-Id: <1449896631-20472-1-git-send-email-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.1.4 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RCVD_IN_SBL_CSS,RCVD_IN_SORBS_WEB,T_DKIM_INVALID, T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Avoid the s390 compile "warning: 'pkcs1pad_encrypt_sign_complete' uses dynamic stack allocation" reported by kbuild test robot. Don't use a flat zero-filled buffer, instead zero the contents of the SGL. Signed-off-by: Andrew Zaborowski --- crypto/rsa-pkcs1pad.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c index accc67d..50f5c97 100644 --- a/crypto/rsa-pkcs1pad.c +++ b/crypto/rsa-pkcs1pad.c @@ -110,21 +110,32 @@ static int pkcs1pad_encrypt_sign_complete(struct akcipher_request *req, int err) struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm); struct pkcs1pad_request *req_ctx = akcipher_request_ctx(req); - uint8_t zeros[ctx->key_size - req_ctx->child_req.dst_len]; + size_t pad_len = ctx->key_size - req_ctx->child_req.dst_len; + size_t chunk_len, pad_left; + struct sg_mapping_iter miter; if (!err) { - if (req_ctx->child_req.dst_len < ctx->key_size) { - memset(zeros, 0, sizeof(zeros)); - sg_copy_from_buffer(req->dst, - sg_nents_for_len(req->dst, - sizeof(zeros)), - zeros, sizeof(zeros)); + if (pad_len) { + sg_miter_start(&miter, req->dst, + sg_nents_for_len(req->dst, pad_len), + SG_MITER_ATOMIC | SG_MITER_TO_SG); + + pad_left = pad_len; + while (pad_left) { + sg_miter_next(&miter); + + chunk_len = min(miter.length, pad_left); + memset(miter.addr, 0, chunk_len); + pad_left -= chunk_len; + } + + sg_miter_stop(&miter); } sg_pcopy_from_buffer(req->dst, sg_nents_for_len(req->dst, ctx->key_size), req_ctx->out_buf, req_ctx->child_req.dst_len, - sizeof(zeros)); + pad_len); } req->dst_len = ctx->key_size;