]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - arch/s390/crypto/ghash_s390.c
s390/crypto: Don't panic after crypto instruction failures
[mirror_ubuntu-artful-kernel.git] / arch / s390 / crypto / ghash_s390.c
index 1ebd3a15cca47d499e3d3855b3f3b1e5bad0082a..d43485d142e911623d30d5abb5bd80d957f752d4 100644 (file)
@@ -72,14 +72,16 @@ static int ghash_update(struct shash_desc *desc,
                if (!dctx->bytes) {
                        ret = crypt_s390_kimd(KIMD_GHASH, ctx, buf,
                                              GHASH_BLOCK_SIZE);
-                       BUG_ON(ret != GHASH_BLOCK_SIZE);
+                       if (ret != GHASH_BLOCK_SIZE)
+                               return -EIO;
                }
        }
 
        n = srclen & ~(GHASH_BLOCK_SIZE - 1);
        if (n) {
                ret = crypt_s390_kimd(KIMD_GHASH, ctx, src, n);
-               BUG_ON(ret != n);
+               if (ret != n)
+                       return -EIO;
                src += n;
                srclen -= n;
        }
@@ -92,7 +94,7 @@ static int ghash_update(struct shash_desc *desc,
        return 0;
 }
 
-static void ghash_flush(struct ghash_ctx *ctx, struct ghash_desc_ctx *dctx)
+static int ghash_flush(struct ghash_ctx *ctx, struct ghash_desc_ctx *dctx)
 {
        u8 *buf = dctx->buffer;
        int ret;
@@ -103,21 +105,24 @@ static void ghash_flush(struct ghash_ctx *ctx, struct ghash_desc_ctx *dctx)
                memset(pos, 0, dctx->bytes);
 
                ret = crypt_s390_kimd(KIMD_GHASH, ctx, buf, GHASH_BLOCK_SIZE);
-               BUG_ON(ret != GHASH_BLOCK_SIZE);
+               if (ret != GHASH_BLOCK_SIZE)
+                       return -EIO;
        }
 
        dctx->bytes = 0;
+       return 0;
 }
 
 static int ghash_final(struct shash_desc *desc, u8 *dst)
 {
        struct ghash_desc_ctx *dctx = shash_desc_ctx(desc);
        struct ghash_ctx *ctx = crypto_shash_ctx(desc->tfm);
+       int ret;
 
-       ghash_flush(ctx, dctx);
-       memcpy(dst, ctx->icv, GHASH_BLOCK_SIZE);
-
-       return 0;
+       ret = ghash_flush(ctx, dctx);
+       if (!ret)
+               memcpy(dst, ctx->icv, GHASH_BLOCK_SIZE);
+       return ret;
 }
 
 static struct shash_alg ghash_alg = {