]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - crypto/drbg.c
x86/speculation/mds: Add mitigation control for MDS
[mirror_ubuntu-bionic-kernel.git] / crypto / drbg.c
index 70018397e59abf10d125864f5770c41cd13f2021..466a112a4446820ff655c3b72076c86d3c7e4f2d 100644 (file)
@@ -1134,8 +1134,10 @@ static inline void drbg_dealloc_state(struct drbg_state *drbg)
        if (!drbg)
                return;
        kzfree(drbg->Vbuf);
+       drbg->Vbuf = NULL;
        drbg->V = NULL;
        kzfree(drbg->Cbuf);
+       drbg->Cbuf = NULL;
        drbg->C = NULL;
        kzfree(drbg->scratchpadbuf);
        drbg->scratchpadbuf = NULL;
@@ -1651,16 +1653,6 @@ static int drbg_fini_sym_kernel(struct drbg_state *drbg)
        return 0;
 }
 
-static void drbg_skcipher_cb(struct crypto_async_request *req, int error)
-{
-       struct drbg_state *drbg = req->data;
-
-       if (error == -EINPROGRESS)
-               return;
-       drbg->ctr_async_err = error;
-       complete(&drbg->ctr_completion);
-}
-
 static int drbg_init_sym_kernel(struct drbg_state *drbg)
 {
        struct crypto_cipher *tfm;
@@ -1691,7 +1683,7 @@ static int drbg_init_sym_kernel(struct drbg_state *drbg)
                return PTR_ERR(sk_tfm);
        }
        drbg->ctr_handle = sk_tfm;
-       init_completion(&drbg->ctr_completion);
+       crypto_init_wait(&drbg->ctr_wait);
 
        req = skcipher_request_alloc(sk_tfm, GFP_KERNEL);
        if (!req) {
@@ -1700,8 +1692,9 @@ static int drbg_init_sym_kernel(struct drbg_state *drbg)
                return -ENOMEM;
        }
        drbg->ctr_req = req;
-       skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
-                                       drbg_skcipher_cb, drbg);
+       skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG |
+                                               CRYPTO_TFM_REQ_MAY_SLEEP,
+                                       crypto_req_done, &drbg->ctr_wait);
 
        alignmask = crypto_skcipher_alignmask(sk_tfm);
        drbg->ctr_null_value_buf = kzalloc(DRBG_CTR_NULL_LEN + alignmask,
@@ -1762,21 +1755,12 @@ static int drbg_kcapi_sym_ctr(struct drbg_state *drbg,
                /* Output buffer may not be valid for SGL, use scratchpad */
                skcipher_request_set_crypt(drbg->ctr_req, &sg_in, &sg_out,
                                           cryptlen, drbg->V);
-               ret = crypto_skcipher_encrypt(drbg->ctr_req);
-               switch (ret) {
-               case 0:
-                       break;
-               case -EINPROGRESS:
-               case -EBUSY:
-                       wait_for_completion(&drbg->ctr_completion);
-                       if (!drbg->ctr_async_err) {
-                               reinit_completion(&drbg->ctr_completion);
-                               break;
-                       }
-               default:
+               ret = crypto_wait_req(crypto_skcipher_encrypt(drbg->ctr_req),
+                                       &drbg->ctr_wait);
+               if (ret)
                        goto out;
-               }
-               init_completion(&drbg->ctr_completion);
+
+               crypto_init_wait(&drbg->ctr_wait);
 
                memcpy(outbuf, drbg->outscratchpad, cryptlen);