Skip to content

Commit

Permalink
crypto: shash - Fix zero-length shash ahash digest crash
Browse files Browse the repository at this point in the history
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.

Cc: <[email protected]>
Reported-by: Stephan Müller<[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
Tested-by: Stephan Müller <[email protected]>
  • Loading branch information
herbertx committed Oct 10, 2017
1 parent 0cabf2a commit b61907b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions crypto/shash.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,14 @@ static int shash_async_finup(struct ahash_request *req)

int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc)
{
struct scatterlist *sg = req->src;
unsigned int offset = sg->offset;
unsigned int nbytes = req->nbytes;
struct scatterlist *sg;
unsigned int offset;
int err;

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

data = kmap_atomic(sg_page(sg));
Expand Down

0 comments on commit b61907b

Please sign in to comment.