浏览代码

[CRYPTO] api: Fix potential race in crypto_remove_spawn

As it is crypto_remove_spawn may try to unregister an instance which is
yet to be registered.  This patch fixes this by checking whether the
instance has been registered before attempting to remove it.

It also removes a bogus cra_destroy check in crypto_register_instance as
1) it's outside the mutex;
2) we have a check in __crypto_register_alg already.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Herbert Xu 17 年之前
父节点
当前提交
38cb2419f5
共有 1 个文件被更改,包括 3 次插入3 次删除
  1. 3 3
      crypto/algapi.c

+ 3 - 3
crypto/algapi.c

@@ -95,6 +95,9 @@ static void crypto_remove_spawn(struct crypto_spawn *spawn,
 		return;
 		return;
 
 
 	inst->alg.cra_flags |= CRYPTO_ALG_DEAD;
 	inst->alg.cra_flags |= CRYPTO_ALG_DEAD;
+	if (hlist_unhashed(&inst->list))
+		return;
+
 	if (!tmpl || !crypto_tmpl_get(tmpl))
 	if (!tmpl || !crypto_tmpl_get(tmpl))
 		return;
 		return;
 
 
@@ -335,9 +338,6 @@ int crypto_register_instance(struct crypto_template *tmpl,
 	LIST_HEAD(list);
 	LIST_HEAD(list);
 	int err = -EINVAL;
 	int err = -EINVAL;
 
 
-	if (inst->alg.cra_destroy)
-		goto err;
-
 	err = crypto_check_alg(&inst->alg);
 	err = crypto_check_alg(&inst->alg);
 	if (err)
 	if (err)
 		goto err;
 		goto err;