[CRYPTO] cryptomgr: Fix parsing of nested templates
This patch allows the use of nested templates by allowing the use of brackets inside a template parameter. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
@@ -14,17 +14,17 @@
|
|||||||
#include <linux/ctype.h>
|
#include <linux/ctype.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
|
#include <linux/kthread.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/notifier.h>
|
#include <linux/notifier.h>
|
||||||
#include <linux/rtnetlink.h>
|
#include <linux/rtnetlink.h>
|
||||||
#include <linux/sched.h>
|
#include <linux/sched.h>
|
||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
#include <linux/workqueue.h>
|
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
struct cryptomgr_param {
|
struct cryptomgr_param {
|
||||||
struct work_struct work;
|
struct task_struct *thread;
|
||||||
|
|
||||||
struct rtattr *tb[CRYPTOA_MAX];
|
struct rtattr *tb[CRYPTOA_MAX];
|
||||||
|
|
||||||
@@ -45,10 +45,9 @@ struct cryptomgr_param {
|
|||||||
char template[CRYPTO_MAX_ALG_NAME];
|
char template[CRYPTO_MAX_ALG_NAME];
|
||||||
};
|
};
|
||||||
|
|
||||||
static void cryptomgr_probe(struct work_struct *work)
|
static int cryptomgr_probe(void *data)
|
||||||
{
|
{
|
||||||
struct cryptomgr_param *param =
|
struct cryptomgr_param *param = data;
|
||||||
container_of(work, struct cryptomgr_param, work);
|
|
||||||
struct crypto_template *tmpl;
|
struct crypto_template *tmpl;
|
||||||
struct crypto_instance *inst;
|
struct crypto_instance *inst;
|
||||||
int err;
|
int err;
|
||||||
@@ -72,7 +71,7 @@ static void cryptomgr_probe(struct work_struct *work)
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
kfree(param);
|
kfree(param);
|
||||||
return;
|
module_put_and_exit(0);
|
||||||
|
|
||||||
err:
|
err:
|
||||||
crypto_larval_error(param->larval.name, param->type.data.type,
|
crypto_larval_error(param->larval.name, param->type.data.type,
|
||||||
@@ -87,9 +86,12 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval)
|
|||||||
const char *p;
|
const char *p;
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
|
|
||||||
|
if (!try_module_get(THIS_MODULE))
|
||||||
|
goto err;
|
||||||
|
|
||||||
param = kzalloc(sizeof(*param), GFP_KERNEL);
|
param = kzalloc(sizeof(*param), GFP_KERNEL);
|
||||||
if (!param)
|
if (!param)
|
||||||
goto err;
|
goto err_put_module;
|
||||||
|
|
||||||
for (p = name; isalnum(*p) || *p == '-' || *p == '_'; p++)
|
for (p = name; isalnum(*p) || *p == '-' || *p == '_'; p++)
|
||||||
;
|
;
|
||||||
@@ -101,11 +103,18 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval)
|
|||||||
memcpy(param->template, name, len);
|
memcpy(param->template, name, len);
|
||||||
|
|
||||||
name = p + 1;
|
name = p + 1;
|
||||||
for (p = name; isalnum(*p) || *p == '-' || *p == '_'; p++)
|
len = 0;
|
||||||
;
|
for (p = name; *p; p++) {
|
||||||
|
for (; isalnum(*p) || *p == '-' || *p == '_' || *p == '('; p++)
|
||||||
|
;
|
||||||
|
|
||||||
len = p - name;
|
if (*p != ')')
|
||||||
if (!len || *p != ')' || p[1])
|
goto err_free_param;
|
||||||
|
|
||||||
|
len = p - name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!len || name[len + 1])
|
||||||
goto err_free_param;
|
goto err_free_param;
|
||||||
|
|
||||||
param->type.attr.rta_len = sizeof(param->type);
|
param->type.attr.rta_len = sizeof(param->type);
|
||||||
@@ -121,13 +130,16 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval)
|
|||||||
|
|
||||||
memcpy(param->larval.name, larval->alg.cra_name, CRYPTO_MAX_ALG_NAME);
|
memcpy(param->larval.name, larval->alg.cra_name, CRYPTO_MAX_ALG_NAME);
|
||||||
|
|
||||||
INIT_WORK(¶m->work, cryptomgr_probe);
|
param->thread = kthread_run(cryptomgr_probe, param, "cryptomgr");
|
||||||
schedule_work(¶m->work);
|
if (IS_ERR(param->thread))
|
||||||
|
goto err_free_param;
|
||||||
|
|
||||||
return NOTIFY_STOP;
|
return NOTIFY_STOP;
|
||||||
|
|
||||||
err_free_param:
|
err_free_param:
|
||||||
kfree(param);
|
kfree(param);
|
||||||
|
err_put_module:
|
||||||
|
module_put(THIS_MODULE);
|
||||||
err:
|
err:
|
||||||
return NOTIFY_OK;
|
return NOTIFY_OK;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user