Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6

Pull crypto fix from Herbert Xu:
 "This fixes a crash in the crypto layer exposed by an SCTP test tool"

* git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6:
  crypto: algboss - Hold ref count on larval
This commit is contained in:
Linus Torvalds 2013-06-29 11:34:18 -07:00
commit 133841cab7
3 changed files with 14 additions and 13 deletions

View File

@ -45,10 +45,9 @@ struct cryptomgr_param {
} nu32; } nu32;
} attrs[CRYPTO_MAX_ATTRS]; } attrs[CRYPTO_MAX_ATTRS];
char larval[CRYPTO_MAX_ALG_NAME];
char template[CRYPTO_MAX_ALG_NAME]; char template[CRYPTO_MAX_ALG_NAME];
struct completion *completion; struct crypto_larval *larval;
u32 otype; u32 otype;
u32 omask; u32 omask;
@ -87,7 +86,8 @@ static int cryptomgr_probe(void *data)
crypto_tmpl_put(tmpl); crypto_tmpl_put(tmpl);
out: out:
complete_all(param->completion); complete_all(&param->larval->completion);
crypto_alg_put(&param->larval->alg);
kfree(param); kfree(param);
module_put_and_exit(0); module_put_and_exit(0);
} }
@ -187,18 +187,19 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval)
param->otype = larval->alg.cra_flags; param->otype = larval->alg.cra_flags;
param->omask = larval->mask; param->omask = larval->mask;
memcpy(param->larval, larval->alg.cra_name, CRYPTO_MAX_ALG_NAME); crypto_alg_get(&larval->alg);
param->larval = larval;
param->completion = &larval->completion;
thread = kthread_run(cryptomgr_probe, param, "cryptomgr_probe"); thread = kthread_run(cryptomgr_probe, param, "cryptomgr_probe");
if (IS_ERR(thread)) if (IS_ERR(thread))
goto err_free_param; goto err_put_larval;
wait_for_completion_interruptible(&larval->completion); wait_for_completion_interruptible(&larval->completion);
return NOTIFY_STOP; return NOTIFY_STOP;
err_put_larval:
crypto_alg_put(&larval->alg);
err_free_param: err_free_param:
kfree(param); kfree(param);
err_put_module: err_put_module:

View File

@ -34,12 +34,6 @@ EXPORT_SYMBOL_GPL(crypto_alg_sem);
BLOCKING_NOTIFIER_HEAD(crypto_chain); BLOCKING_NOTIFIER_HEAD(crypto_chain);
EXPORT_SYMBOL_GPL(crypto_chain); EXPORT_SYMBOL_GPL(crypto_chain);
static inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg)
{
atomic_inc(&alg->cra_refcnt);
return alg;
}
struct crypto_alg *crypto_mod_get(struct crypto_alg *alg) struct crypto_alg *crypto_mod_get(struct crypto_alg *alg)
{ {
return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL; return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL;

View File

@ -103,6 +103,12 @@ int crypto_register_notifier(struct notifier_block *nb);
int crypto_unregister_notifier(struct notifier_block *nb); int crypto_unregister_notifier(struct notifier_block *nb);
int crypto_probing_notify(unsigned long val, void *v); int crypto_probing_notify(unsigned long val, void *v);
static inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg)
{
atomic_inc(&alg->cra_refcnt);
return alg;
}
static inline void crypto_alg_put(struct crypto_alg *alg) static inline void crypto_alg_put(struct crypto_alg *alg)
{ {
if (atomic_dec_and_test(&alg->cra_refcnt) && alg->cra_destroy) if (atomic_dec_and_test(&alg->cra_refcnt) && alg->cra_destroy)