From: Patrick McHardy <kaber@trash.net>
To: linux-crypto@vger.kernel.org
Cc: Evgeniy Polyakov <johnpol@2ka.mipt.ru>,
Herbert Xu <herbert@gondor.apana.org.au>
Subject: [HIFN 06/n]: Properly handle requests for less than the full scatterlist
Date: Wed, 07 May 2008 14:30:28 +0200 [thread overview]
Message-ID: <4821A0E4.8070904@trash.net> (raw)
In-Reply-To: <48219D24.1040702@trash.net>
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: 06.diff --]
[-- Type: text/x-diff, Size: 2797 bytes --]
commit 4f3353b225b7123cf9c04cb9ae3b987f0671ee26
Author: Patrick McHardy <kaber@trash.net>
Date: Wed May 7 12:52:53 2008 +0200
[HIFN]: Properly handle requests for less than the full scatterlist
The scatterlist may contain more data than the crypto request, causing
an underflow of the remaining byte count while walking the list.
Use the minimum of the scatterlist element size and the remaining byte
count specified in the crypto request to avoid this.
Signed-off-by: Patrick McHardy <kaber@trash.net>
diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
index 7706461..650523c 100644
--- a/drivers/crypto/hifn_795x.c
+++ b/drivers/crypto/hifn_795x.c
@@ -1433,7 +1433,7 @@ static int ablkcipher_add(void *daddr, unsigned int *drestp, struct scatterlist
return -EINVAL;
while (size) {
- copy = min(drest, src->length);
+ copy = min(drest, min(size, src->length));
saddr = kmap_atomic(sg_page(src), KM_SOFTIRQ1);
memcpy(daddr, saddr + src->offset, copy);
@@ -1482,7 +1482,7 @@ static int ablkcipher_walk(struct ablkcipher_request *req,
if (!IS_ALIGNED(dst->offset, HIFN_D_DST_DALIGN) ||
!IS_ALIGNED(dst->length, HIFN_D_DST_DALIGN) ||
offset) {
- unsigned slen = src->length - offset;
+ unsigned slen = min(src->length - offset, nbytes);
unsigned dlen = PAGE_SIZE;
t = &w->cache[idx];
@@ -1540,7 +1540,7 @@ static int ablkcipher_walk(struct ablkcipher_request *req,
kunmap_atomic(daddr, KM_SOFTIRQ0);
} else {
- nbytes -= src->length;
+ nbytes -= min(src->length, nbytes);
idx++;
}
@@ -1559,7 +1559,7 @@ static int hifn_setup_session(struct ablkcipher_request *req)
struct hifn_context *ctx = crypto_tfm_ctx(req->base.tfm);
struct hifn_device *dev = ctx->dev;
struct page *spage, *dpage;
- unsigned long soff, doff, flags;
+ unsigned long soff, doff, dlen, flags;
unsigned int nbytes = req->nbytes, idx = 0, len;
int err = -EINVAL, sg_num;
struct scatterlist *src, *dst, *t;
@@ -1571,12 +1571,13 @@ static int hifn_setup_session(struct ablkcipher_request *req)
while (nbytes) {
dst = &req->dst[idx];
+ dlen = min(dst->length, nbytes);
if (!IS_ALIGNED(dst->offset, HIFN_D_DST_DALIGN) ||
- !IS_ALIGNED(dst->length, HIFN_D_DST_DALIGN))
+ !IS_ALIGNED(dlen, HIFN_D_DST_DALIGN))
ctx->walk.flags |= ASYNC_FLAGS_MISALIGNED;
- nbytes -= dst->length;
+ nbytes -= dlen;
idx++;
}
@@ -1631,7 +1632,7 @@ static int hifn_setup_session(struct ablkcipher_request *req)
if (err)
goto err_out;
- nbytes -= len;
+ nbytes -= min(len, nbytes);
}
dev->active = HIFN_DEFAULT_ACTIVE_NUM;
@@ -1736,8 +1737,7 @@ static int ablkcipher_get(void *saddr, unsigned int *srestp, unsigned int offset
return -EINVAL;
while (size) {
next prev parent reply other threads:[~2008-05-07 12:31 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-07 12:14 [HIFN 01/n]: Endianess fixes Patrick McHardy
2008-05-07 12:15 ` [HIFN 02/n]: Remove printk_ratelimit() for debugging printk Patrick McHardy
2008-05-07 12:23 ` Evgeniy Polyakov
2008-05-07 12:19 ` [HIFN 03/n]: Indicate asynchronous processing to crypto API Patrick McHardy
2008-05-07 12:23 ` Evgeniy Polyakov
2008-05-07 12:29 ` Patrick McHardy
2008-05-07 12:20 ` [HIFN 04/n]: Handle ablkcipher_walk errors Patrick McHardy
2008-05-07 12:44 ` Evgeniy Polyakov
2008-05-07 12:26 ` [HIFN 05/n]: Fix data alignment checks Patrick McHardy
2008-05-07 12:42 ` Evgeniy Polyakov
2008-05-07 12:45 ` Patrick McHardy
2008-05-07 13:04 ` Evgeniy Polyakov
2008-05-07 13:05 ` Patrick McHardy
2008-05-07 13:22 ` Evgeniy Polyakov
2008-05-07 12:48 ` Herbert Xu
2008-05-07 12:51 ` Patrick McHardy
2008-05-07 12:30 ` Patrick McHardy [this message]
2008-05-07 13:01 ` [HIFN 06/n]: Properly handle requests for less than the full scatterlist Evgeniy Polyakov
2008-05-07 12:32 ` [HIFN 07/n]: Use unique driver names for different algos Patrick McHardy
2008-05-07 13:07 ` Evgeniy Polyakov
2008-05-07 12:36 ` [HIFN 08/n]: Properly initialize ivsize for CBC modes Patrick McHardy
2008-05-07 12:38 ` [HIFN 09/n]: Fix max queue length value Patrick McHardy
2008-05-07 12:46 ` Evgeniy Polyakov
2008-05-07 12:50 ` [HIFN 10/n]: Move command descriptor setup to seperate function Patrick McHardy
2008-05-07 13:11 ` Evgeniy Polyakov
2008-05-07 12:53 ` [HIFN 11/n]: Have HW invalidate src and dest descriptors after processing Patrick McHardy
2008-05-07 13:14 ` Evgeniy Polyakov
2008-05-07 13:18 ` Patrick McHardy
2008-05-07 13:00 ` [HIFN 01/n]: Endianess fixes Evgeniy Polyakov
2008-05-07 13:01 ` Patrick McHardy
2008-05-07 13:23 ` Evgeniy Polyakov
2008-05-07 13:46 ` Patrick McHardy
2008-05-07 14:04 ` Evgeniy Polyakov
2008-05-07 14:38 ` Herbert Xu
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=4821A0E4.8070904@trash.net \
--to=kaber@trash.net \
--cc=herbert@gondor.apana.org.au \
--cc=johnpol@2ka.mipt.ru \
--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