crypto: marvell - check return value of sg_nents_for_len
authorLABBE Corentin <clabbe.montjoie@gmail.com>
Wed, 4 Nov 2015 20:13:33 +0000 (21:13 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Tue, 17 Nov 2015 14:00:35 +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/marvell/cipher.c
drivers/crypto/marvell/hash.c

index 6edae64bb3873e9a5dac2a0ca9e5f96555bc2695..dcf1fceb93364f4010de17985e1866a10d6ba27e 100644 (file)
@@ -401,7 +401,15 @@ static int mv_cesa_ablkcipher_req_init(struct ablkcipher_request *req,
                return -EINVAL;
 
        creq->src_nents = sg_nents_for_len(req->src, req->nbytes);
+       if (creq->src_nents < 0) {
+               dev_err(cesa_dev->dev, "Invalid number of src SG");
+               return creq->src_nents;
+       }
        creq->dst_nents = sg_nents_for_len(req->dst, req->nbytes);
+       if (creq->dst_nents < 0) {
+               dev_err(cesa_dev->dev, "Invalid number of dst SG");
+               return creq->dst_nents;
+       }
 
        mv_cesa_update_op_cfg(tmpl, CESA_SA_DESC_CFG_OP_CRYPT_ONLY,
                              CESA_SA_DESC_CFG_OP_MSK);
index 6ec55b4a087bf740d80d3fa441d1b25c7a78ec77..683cca9ac3c46bbf8625042f2c4b5c91e7eec51f 100644 (file)
@@ -712,6 +712,10 @@ static int mv_cesa_ahash_req_init(struct ahash_request *req, bool *cached)
                creq->req.base.type = CESA_STD_REQ;
 
        creq->src_nents = sg_nents_for_len(req->src, req->nbytes);
+       if (creq->src_nents < 0) {
+               dev_err(cesa_dev->dev, "Invalid number of src SG");
+               return creq->src_nents;
+       }
 
        ret = mv_cesa_ahash_cache_req(req, cached);
        if (ret)