Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Crypto user configuration API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2017-2018 Corentin Labbe <clabbe@baylibre.com>
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/crypto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/cryptouser.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <net/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <crypto/internal/skcipher.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <crypto/internal/rng.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <crypto/akcipher.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <crypto/kpp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <crypto/internal/cryptouser.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define null_terminated(x)	(strnlen(x, sizeof(x)) < sizeof(x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) struct crypto_dump_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct sk_buff *in_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct sk_buff *out_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	u32 nlmsg_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	u16 nlmsg_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static int crypto_report_aead(struct sk_buff *skb, struct crypto_alg *alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct crypto_stat_aead raead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	memset(&raead, 0, sizeof(raead));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	strscpy(raead.type, "aead", sizeof(raead.type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	raead.stat_encrypt_cnt = atomic64_read(&alg->stats.aead.encrypt_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	raead.stat_encrypt_tlen = atomic64_read(&alg->stats.aead.encrypt_tlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	raead.stat_decrypt_cnt = atomic64_read(&alg->stats.aead.decrypt_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	raead.stat_decrypt_tlen = atomic64_read(&alg->stats.aead.decrypt_tlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	raead.stat_err_cnt = atomic64_read(&alg->stats.aead.err_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	return nla_put(skb, CRYPTOCFGA_STAT_AEAD, sizeof(raead), &raead);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct crypto_stat_cipher rcipher;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	memset(&rcipher, 0, sizeof(rcipher));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	strscpy(rcipher.type, "cipher", sizeof(rcipher.type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	rcipher.stat_encrypt_cnt = atomic64_read(&alg->stats.cipher.encrypt_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	rcipher.stat_encrypt_tlen = atomic64_read(&alg->stats.cipher.encrypt_tlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	rcipher.stat_decrypt_cnt =  atomic64_read(&alg->stats.cipher.decrypt_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	rcipher.stat_decrypt_tlen = atomic64_read(&alg->stats.cipher.decrypt_tlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	rcipher.stat_err_cnt =  atomic64_read(&alg->stats.cipher.err_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return nla_put(skb, CRYPTOCFGA_STAT_CIPHER, sizeof(rcipher), &rcipher);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct crypto_stat_compress rcomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	memset(&rcomp, 0, sizeof(rcomp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	strscpy(rcomp.type, "compression", sizeof(rcomp.type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	rcomp.stat_compress_cnt = atomic64_read(&alg->stats.compress.compress_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	rcomp.stat_compress_tlen = atomic64_read(&alg->stats.compress.compress_tlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	rcomp.stat_decompress_cnt = atomic64_read(&alg->stats.compress.decompress_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	rcomp.stat_decompress_tlen = atomic64_read(&alg->stats.compress.decompress_tlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	rcomp.stat_err_cnt = atomic64_read(&alg->stats.compress.err_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return nla_put(skb, CRYPTOCFGA_STAT_COMPRESS, sizeof(rcomp), &rcomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static int crypto_report_acomp(struct sk_buff *skb, struct crypto_alg *alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct crypto_stat_compress racomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	memset(&racomp, 0, sizeof(racomp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	strscpy(racomp.type, "acomp", sizeof(racomp.type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	racomp.stat_compress_cnt = atomic64_read(&alg->stats.compress.compress_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	racomp.stat_compress_tlen = atomic64_read(&alg->stats.compress.compress_tlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	racomp.stat_decompress_cnt =  atomic64_read(&alg->stats.compress.decompress_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	racomp.stat_decompress_tlen = atomic64_read(&alg->stats.compress.decompress_tlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	racomp.stat_err_cnt = atomic64_read(&alg->stats.compress.err_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	return nla_put(skb, CRYPTOCFGA_STAT_ACOMP, sizeof(racomp), &racomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	struct crypto_stat_akcipher rakcipher;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	memset(&rakcipher, 0, sizeof(rakcipher));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	strscpy(rakcipher.type, "akcipher", sizeof(rakcipher.type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	rakcipher.stat_encrypt_cnt = atomic64_read(&alg->stats.akcipher.encrypt_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	rakcipher.stat_encrypt_tlen = atomic64_read(&alg->stats.akcipher.encrypt_tlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	rakcipher.stat_decrypt_cnt = atomic64_read(&alg->stats.akcipher.decrypt_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	rakcipher.stat_decrypt_tlen = atomic64_read(&alg->stats.akcipher.decrypt_tlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	rakcipher.stat_sign_cnt = atomic64_read(&alg->stats.akcipher.sign_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	rakcipher.stat_verify_cnt = atomic64_read(&alg->stats.akcipher.verify_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	rakcipher.stat_err_cnt = atomic64_read(&alg->stats.akcipher.err_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return nla_put(skb, CRYPTOCFGA_STAT_AKCIPHER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		       sizeof(rakcipher), &rakcipher);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static int crypto_report_kpp(struct sk_buff *skb, struct crypto_alg *alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct crypto_stat_kpp rkpp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	memset(&rkpp, 0, sizeof(rkpp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	strscpy(rkpp.type, "kpp", sizeof(rkpp.type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	rkpp.stat_setsecret_cnt = atomic64_read(&alg->stats.kpp.setsecret_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	rkpp.stat_generate_public_key_cnt = atomic64_read(&alg->stats.kpp.generate_public_key_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	rkpp.stat_compute_shared_secret_cnt = atomic64_read(&alg->stats.kpp.compute_shared_secret_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	rkpp.stat_err_cnt = atomic64_read(&alg->stats.kpp.err_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	return nla_put(skb, CRYPTOCFGA_STAT_KPP, sizeof(rkpp), &rkpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static int crypto_report_ahash(struct sk_buff *skb, struct crypto_alg *alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct crypto_stat_hash rhash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	memset(&rhash, 0, sizeof(rhash));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	strscpy(rhash.type, "ahash", sizeof(rhash.type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	rhash.stat_hash_cnt = atomic64_read(&alg->stats.hash.hash_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	rhash.stat_hash_tlen = atomic64_read(&alg->stats.hash.hash_tlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	rhash.stat_err_cnt = atomic64_read(&alg->stats.hash.err_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	return nla_put(skb, CRYPTOCFGA_STAT_HASH, sizeof(rhash), &rhash);
^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) static int crypto_report_shash(struct sk_buff *skb, struct crypto_alg *alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct crypto_stat_hash rhash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	memset(&rhash, 0, sizeof(rhash));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	strscpy(rhash.type, "shash", sizeof(rhash.type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	rhash.stat_hash_cnt =  atomic64_read(&alg->stats.hash.hash_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	rhash.stat_hash_tlen = atomic64_read(&alg->stats.hash.hash_tlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	rhash.stat_err_cnt = atomic64_read(&alg->stats.hash.err_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	return nla_put(skb, CRYPTOCFGA_STAT_HASH, sizeof(rhash), &rhash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static int crypto_report_rng(struct sk_buff *skb, struct crypto_alg *alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	struct crypto_stat_rng rrng;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	memset(&rrng, 0, sizeof(rrng));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	strscpy(rrng.type, "rng", sizeof(rrng.type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	rrng.stat_generate_cnt = atomic64_read(&alg->stats.rng.generate_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	rrng.stat_generate_tlen = atomic64_read(&alg->stats.rng.generate_tlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	rrng.stat_seed_cnt = atomic64_read(&alg->stats.rng.seed_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	rrng.stat_err_cnt = atomic64_read(&alg->stats.rng.err_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return nla_put(skb, CRYPTOCFGA_STAT_RNG, sizeof(rrng), &rrng);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static int crypto_reportstat_one(struct crypto_alg *alg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 				 struct crypto_user_alg *ualg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 				 struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	memset(ualg, 0, sizeof(*ualg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	strscpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	strscpy(ualg->cru_driver_name, alg->cra_driver_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		sizeof(ualg->cru_driver_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	strscpy(ualg->cru_module_name, module_name(alg->cra_module),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		sizeof(ualg->cru_module_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	ualg->cru_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	ualg->cru_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	ualg->cru_flags = alg->cra_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	ualg->cru_refcnt = refcount_read(&alg->cra_refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (nla_put_u32(skb, CRYPTOCFGA_PRIORITY_VAL, alg->cra_priority))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		struct crypto_stat_larval rl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		memset(&rl, 0, sizeof(rl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		strscpy(rl.type, "larval", sizeof(rl.type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		if (nla_put(skb, CRYPTOCFGA_STAT_LARVAL, sizeof(rl), &rl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	switch (alg->cra_flags & (CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_LARVAL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	case CRYPTO_ALG_TYPE_AEAD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		if (crypto_report_aead(skb, alg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	case CRYPTO_ALG_TYPE_SKCIPHER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		if (crypto_report_cipher(skb, alg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	case CRYPTO_ALG_TYPE_CIPHER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		if (crypto_report_cipher(skb, alg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	case CRYPTO_ALG_TYPE_COMPRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		if (crypto_report_comp(skb, alg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	case CRYPTO_ALG_TYPE_ACOMPRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		if (crypto_report_acomp(skb, alg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	case CRYPTO_ALG_TYPE_SCOMPRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		if (crypto_report_acomp(skb, alg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	case CRYPTO_ALG_TYPE_AKCIPHER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		if (crypto_report_akcipher(skb, alg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	case CRYPTO_ALG_TYPE_KPP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		if (crypto_report_kpp(skb, alg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	case CRYPTO_ALG_TYPE_AHASH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		if (crypto_report_ahash(skb, alg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	case CRYPTO_ALG_TYPE_HASH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		if (crypto_report_shash(skb, alg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	case CRYPTO_ALG_TYPE_RNG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		if (crypto_report_rng(skb, alg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		pr_err("ERROR: Unhandled alg %d in %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		       alg->cra_flags & (CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_LARVAL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		       __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static int crypto_reportstat_alg(struct crypto_alg *alg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 				 struct crypto_dump_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	struct sk_buff *in_skb = info->in_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	struct sk_buff *skb = info->out_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	struct nlmsghdr *nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	struct crypto_user_alg *ualg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	nlh = nlmsg_put(skb, NETLINK_CB(in_skb).portid, info->nlmsg_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			CRYPTO_MSG_GETSTAT, sizeof(*ualg), info->nlmsg_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	if (!nlh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		err = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	ualg = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	err = crypto_reportstat_one(alg, ualg, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		nlmsg_cancel(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	nlmsg_end(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) int crypto_reportstat(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		      struct nlattr **attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	struct net *net = sock_net(in_skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	struct crypto_user_alg *p = nlmsg_data(in_nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	struct crypto_alg *alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	struct crypto_dump_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	alg = crypto_alg_match(p, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	if (!alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		goto drop_alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	info.in_skb = in_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	info.out_skb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	info.nlmsg_seq = in_nlh->nlmsg_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	info.nlmsg_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	err = crypto_reportstat_alg(alg, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) drop_alg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	crypto_mod_put(alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	return nlmsg_unicast(net->crypto_nlsk, skb, NETLINK_CB(in_skb).portid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) MODULE_LICENSE("GPL");