From: Tadeusz Struk <tadeusz.struk@intel.com>
To: herbert@gondor.apana.org.au
Cc: linux-crypto@vger.kernel.org, davem@davemloft.net
Subject: [PATCH] crypto: algif - Mark sgl end at the end of data
Date: Fri, 28 Nov 2014 10:40:36 -0800 [thread overview]
Message-ID: <20141128184036.11421.36028.stgit@tstruk-mobl1> (raw)
Hi,
algif_skcipher sends 127 sgl buffers for encryption regardless of how
many buffers acctually have data to process, where the few first with
valid len and the rest with zero len. This is not very eficient and may cause
problems when algs do something like this without checking the buff
lenght:
for_each_sg(sgl, sg, sg_nents, i)
sg_virt(sg)
This patch marks the last one with data as the last one to process.
Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>
---
crypto/algif_skcipher.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
index f80e652..46a0758 100644
--- a/crypto/algif_skcipher.c
+++ b/crypto/algif_skcipher.c
@@ -441,6 +441,8 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,
char __user *from = iov->iov_base;
while (seglen) {
+ int nents;
+
sgl = list_first_entry(&ctx->tsgl,
struct skcipher_sg_list, list);
sg = sgl->sg;
@@ -468,6 +470,9 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,
if (!used)
goto free;
+ nents = sg_nents(ctx->rsgl.sg);
+ sg_mark_end(&sg[nents - 1]);
+
ablkcipher_request_set_crypt(&ctx->req, sg,
ctx->rsgl.sg, used,
ctx->iv);
@@ -477,6 +482,7 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,
crypto_ablkcipher_encrypt(&ctx->req) :
crypto_ablkcipher_decrypt(&ctx->req),
&ctx->completion);
+ sg_unmark_end(&sg[nents - 1]);
free:
af_alg_free_sg(&ctx->rsgl);
next reply other threads:[~2014-11-28 18:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-28 18:40 Tadeusz Struk [this message]
2014-12-01 14:40 ` [PATCH] crypto: algif - Mark sgl end at the end of data Herbert Xu
2014-12-01 14:53 ` Tadeusz Struk
2014-12-01 15:00 ` Herbert Xu
2014-12-01 15:03 ` Tadeusz Struk
2014-12-02 14:33 ` Herbert Xu
2014-12-02 15:06 ` Tadeusz Struk
-- strict thread matches above, loose matches on Subject: below --
2014-11-21 17:14 Tadeusz Struk
2014-11-25 14:42 ` Herbert Xu
2014-11-25 15:53 ` Tadeusz Struk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141128184036.11421.36028.stgit@tstruk-mobl1 \
--to=tadeusz.struk@intel.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox