Skip to content

Commit fe2d529

Browse files
herbertxdavem330
authored andcommitted
[CRYPTO] Fix boundary check in standard multi-block cipher processors
The boundary check in the standard multi-block cipher processors are broken when nbytes is not a multiple of bsize. In those cases it will always process an extra block. This patch corrects the check so that it processes at most nbytes of data. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b69aee0 commit fe2d529

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎crypto/cipher.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,16 @@ static unsigned int cbc_process_encrypt(const struct cipher_desc *desc,
191191
u8 *iv = desc->info;
192192
unsigned int done = 0;
193193

194+
nbytes -= bsize;
195+
194196
do {
195197
xor(iv, src);
196198
fn(crypto_tfm_ctx(tfm), dst, iv);
197199
memcpy(iv, dst, bsize);
198200

199201
src += bsize;
200202
dst += bsize;
201-
} while ((done += bsize) < nbytes);
203+
} while ((done += bsize) <= nbytes);
202204

203205
return done;
204206
}
@@ -219,6 +221,8 @@ static unsigned int cbc_process_decrypt(const struct cipher_desc *desc,
219221
u8 *iv = desc->info;
220222
unsigned int done = 0;
221223

224+
nbytes -= bsize;
225+
222226
do {
223227
u8 *tmp_dst = *dst_p;
224228

@@ -230,7 +234,7 @@ static unsigned int cbc_process_decrypt(const struct cipher_desc *desc,
230234

231235
src += bsize;
232236
dst += bsize;
233-
} while ((done += bsize) < nbytes);
237+
} while ((done += bsize) <= nbytes);
234238

235239
return done;
236240
}
@@ -243,12 +247,14 @@ static unsigned int ecb_process(const struct cipher_desc *desc, u8 *dst,
243247
void (*fn)(void *, u8 *, const u8 *) = desc->crfn;
244248
unsigned int done = 0;
245249

250+
nbytes -= bsize;
251+
246252
do {
247253
fn(crypto_tfm_ctx(tfm), dst, src);
248254

249255
src += bsize;
250256
dst += bsize;
251-
} while ((done += bsize) < nbytes);
257+
} while ((done += bsize) <= nbytes);
252258

253259
return done;
254260
}

0 commit comments

Comments
 (0)