^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Create default crypto algorithm instances.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <crypto/internal/aead.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct cryptomgr_param {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct rtattr *tb[CRYPTO_MAX_ATTRS + 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct rtattr attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct crypto_attr_type data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) } type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct rtattr attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct rtattr attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct crypto_attr_alg data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) } alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct rtattr attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct crypto_attr_u32 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) } nu32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) } attrs[CRYPTO_MAX_ATTRS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) char template[CRYPTO_MAX_ALG_NAME];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct crypto_larval *larval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) u32 otype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) u32 omask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct crypto_test_param {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) char driver[CRYPTO_MAX_ALG_NAME];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) char alg[CRYPTO_MAX_ALG_NAME];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u32 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static int cryptomgr_probe(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct cryptomgr_param *param = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct crypto_template *tmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) tmpl = crypto_lookup_template(param->template);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (!tmpl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) err = tmpl->create(tmpl, param->tb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) } while (err == -EAGAIN && !signal_pending(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) crypto_tmpl_put(tmpl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) complete_all(¶m->larval->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) crypto_alg_put(¶m->larval->alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) kfree(param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) module_put_and_exit(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static int cryptomgr_schedule_probe(struct crypto_larval *larval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct task_struct *thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct cryptomgr_param *param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) const char *name = larval->alg.cra_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) const char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (!try_module_get(THIS_MODULE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) param = kzalloc(sizeof(*param), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (!param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) goto err_put_module;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) for (p = name; isalnum(*p) || *p == '-' || *p == '_'; p++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) len = p - name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (!len || *p != '(')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) goto err_free_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) memcpy(param->template, name, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) int notnum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) name = ++p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) for (; isalnum(*p) || *p == '-' || *p == '_'; p++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) notnum |= !isdigit(*p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (*p == '(') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int recursion = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (!*++p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) goto err_free_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (*p == '(')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) recursion++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) else if (*p == ')' && !recursion--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) notnum = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) len = p - name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (!len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) goto err_free_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (notnum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) param->attrs[i].alg.attr.rta_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) sizeof(param->attrs[i].alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) param->attrs[i].alg.attr.rta_type = CRYPTOA_ALG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) memcpy(param->attrs[i].alg.data.name, name, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) param->attrs[i].nu32.attr.rta_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) sizeof(param->attrs[i].nu32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) param->attrs[i].nu32.attr.rta_type = CRYPTOA_U32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) param->attrs[i].nu32.data.num =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) simple_strtol(name, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) param->tb[i + 1] = ¶m->attrs[i].attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (i >= CRYPTO_MAX_ATTRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) goto err_free_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (*p == ')')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (*p != ',')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) goto err_free_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (!i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) goto err_free_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) param->tb[i + 1] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) param->type.attr.rta_len = sizeof(param->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) param->type.attr.rta_type = CRYPTOA_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) param->type.data.type = larval->alg.cra_flags & ~CRYPTO_ALG_TESTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) param->type.data.mask = larval->mask & ~CRYPTO_ALG_TESTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) param->tb[0] = ¶m->type.attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) param->otype = larval->alg.cra_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) param->omask = larval->mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) crypto_alg_get(&larval->alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) param->larval = larval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) thread = kthread_run(cryptomgr_probe, param, "cryptomgr_probe");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (IS_ERR(thread))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) goto err_put_larval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return NOTIFY_STOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) err_put_larval:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) crypto_alg_put(&larval->alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) err_free_param:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) kfree(param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) err_put_module:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static int cryptomgr_test(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct crypto_test_param *param = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) u32 type = param->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) goto skiptest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (type & CRYPTO_ALG_TESTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) goto skiptest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) err = alg_test(param->driver, param->alg, type, CRYPTO_ALG_TESTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) skiptest:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) crypto_alg_tested(param->driver, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) kfree(param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) module_put_and_exit(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static int cryptomgr_schedule_test(struct crypto_alg *alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct task_struct *thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct crypto_test_param *param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) u32 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (!try_module_get(THIS_MODULE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) param = kzalloc(sizeof(*param), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (!param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) goto err_put_module;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) memcpy(param->driver, alg->cra_driver_name, sizeof(param->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) memcpy(param->alg, alg->cra_name, sizeof(param->alg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) type = alg->cra_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /* Do not test internal algorithms. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (type & CRYPTO_ALG_INTERNAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) type |= CRYPTO_ALG_TESTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) param->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) thread = kthread_run(cryptomgr_test, param, "cryptomgr_test");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (IS_ERR(thread))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) goto err_free_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return NOTIFY_STOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) err_free_param:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) kfree(param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) err_put_module:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static int cryptomgr_notify(struct notifier_block *this, unsigned long msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) switch (msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) case CRYPTO_MSG_ALG_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return cryptomgr_schedule_probe(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) case CRYPTO_MSG_ALG_REGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return cryptomgr_schedule_test(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) case CRYPTO_MSG_ALG_LOADED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static struct notifier_block cryptomgr_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) .notifier_call = cryptomgr_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static int __init cryptomgr_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return crypto_register_notifier(&cryptomgr_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static void __exit cryptomgr_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) int err = crypto_unregister_notifier(&cryptomgr_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) BUG_ON(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * This is arch_initcall() so that the crypto self-tests are run on algorithms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * registered early by subsys_initcall(). subsys_initcall() is needed for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * generic implementations so that they're available for comparison tests when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * other implementations are registered later by module_init().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) arch_initcall(cryptomgr_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) module_exit(cryptomgr_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) MODULE_DESCRIPTION("Crypto Algorithm Manager");