All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] crypto: rsa-padding - don't allocate buffer on stack
@ 2015-12-12  5:03 Andrew Zaborowski
  2015-12-22 13:21 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Zaborowski @ 2015-12-12  5:03 UTC (permalink / raw)
  To: linux-crypto

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 <andrew.zaborowski@intel.com>
---
 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;
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] crypto: rsa-padding - don't allocate buffer on stack
  2015-12-12  5:03 [PATCH] crypto: rsa-padding - don't allocate buffer on stack Andrew Zaborowski
@ 2015-12-22 13:21 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2015-12-22 13:21 UTC (permalink / raw)
  To: Andrew Zaborowski; +Cc: linux-crypto

Andrew Zaborowski <andrew.zaborowski@intel.com> wrote:
> 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 <andrew.zaborowski@intel.com>

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-12-22 13:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-12  5:03 [PATCH] crypto: rsa-padding - don't allocate buffer on stack Andrew Zaborowski
2015-12-22 13:21 ` Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.