crypto: qce - check return value of sg_nents_for_len
authorLABBE Corentin <clabbe.montjoie@gmail.com>
Wed, 4 Nov 2015 20:13:36 +0000 (21:13 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Tue, 17 Nov 2015 14:00:36 +0000 (22:00 +0800)
The sg_nents_for_len() function could fail, this patch add a check for
its return value.

Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/qce/ablkcipher.c
drivers/crypto/qce/sha.c

index 2c0d63d48747dcc6fdd9d44a5182144032c2db4f..dbcbbe242bd671c347e3d89842fc5baf2eab6414 100644 (file)
@@ -83,6 +83,14 @@ qce_ablkcipher_async_req_handle(struct crypto_async_request *async_req)
                rctx->dst_nents = sg_nents_for_len(req->dst, req->nbytes);
        else
                rctx->dst_nents = rctx->src_nents;
+       if (rctx->src_nents < 0) {
+               dev_err(qce->dev, "Invalid numbers of src SG.\n");
+               return rctx->src_nents;
+       }
+       if (rctx->dst_nents < 0) {
+               dev_err(qce->dev, "Invalid numbers of dst SG.\n");
+               return -rctx->dst_nents;
+       }
 
        rctx->dst_nents += 1;
 
index 0c9973ec80ebde80513152b7f16af5d50da8daae..47e114ac09d01f2527d9199c7ece0c99c78a1754 100644 (file)
@@ -92,6 +92,11 @@ static int qce_ahash_async_req_handle(struct crypto_async_request *async_req)
        }
 
        rctx->src_nents = sg_nents_for_len(req->src, req->nbytes);
+       if (rctx->src_nents < 0) {
+               dev_err(qce->dev, "Invalid numbers of src SG.\n");
+               return rctx->src_nents;
+       }
+
        ret = dma_map_sg(qce->dev, req->src, rctx->src_nents, DMA_TO_DEVICE);
        if (ret < 0)
                return ret;