Skip to content

Commit b61907b

Browse files
committed
crypto: shash - Fix zero-length shash ahash digest crash
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]>
1 parent 0cabf2a commit b61907b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

crypto/shash.c

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

276276
int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc)
277277
{
278-
struct scatterlist *sg = req->src;
279-
unsigned int offset = sg->offset;
280278
unsigned int nbytes = req->nbytes;
279+
struct scatterlist *sg;
280+
unsigned int offset;
281281
int err;
282282

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

286288
data = kmap_atomic(sg_page(sg));

0 commit comments

Comments
 (0)