]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - crypto/lrw.c
crypto: xts,lrw - fix out-of-bounds write after kmalloc failure
[karo-tx-linux.git] / crypto / lrw.c
index ecd8474018e3bde6d16d44c66da6844b6c78ad26..3ea095adafd9af0067f695c4c70e2af702f70923 100644 (file)
@@ -286,8 +286,11 @@ static int init_crypt(struct skcipher_request *req, crypto_completion_t done)
 
        subreq->cryptlen = LRW_BUFFER_SIZE;
        if (req->cryptlen > LRW_BUFFER_SIZE) {
-               subreq->cryptlen = min(req->cryptlen, (unsigned)PAGE_SIZE);
-               rctx->ext = kmalloc(subreq->cryptlen, gfp);
+               unsigned int n = min(req->cryptlen, (unsigned int)PAGE_SIZE);
+
+               rctx->ext = kmalloc(n, gfp);
+               if (rctx->ext)
+                       subreq->cryptlen = n;
        }
 
        rctx->src = req->src;