Skip to content

Commit 03bd90f

Browse files
herbertxgregkh
authored andcommitted
crypto: shash - Fix zero-length shash ahash digest crash
commit b61907bb42409adf9b3120f741af7c57dd7e3db2 upstream. The shash ahash digest adaptor function may crash if given a zero-length input together with a null SG list. This is because it tries to read the SG list before looking at the length. This patch fixes it by checking the length first. Reported-by: Stephan Müller<smueller@chronox.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Tested-by: Stephan Müller <smueller@chronox.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2929cb9 commit 03bd90f

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

crypto/shash.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,14 @@ static int shash_async_finup(struct ahash_request *req)
274274

275275
int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc)
276276
{
277-
struct scatterlist *sg = req->src;
278-
unsigned int offset = sg->offset;
279277
unsigned int nbytes = req->nbytes;
278+
struct scatterlist *sg;
279+
unsigned int offset;
280280
int err;
281281

282-
if (nbytes < min(sg->length, ((unsigned int)(PAGE_SIZE)) - offset)) {
282+
if (nbytes &&
283+
(sg = req->src, offset = sg->offset,
284+
nbytes < min(sg->length, ((unsigned int)(PAGE_SIZE)) - offset))) {
283285
void *data;
284286

285287
data = kmap_atomic(sg_page(sg));

0 commit comments

Comments
 (0)