提交 37db69e0 编写于 作者: E Eric Biggers 提交者: Herbert Xu

crypto: user - clean up report structure copying

There have been a pretty ridiculous number of issues with initializing
the report structures that are copied to userspace by NETLINK_CRYPTO.
Commit 4473710d ("crypto: user - Prepare for CRYPTO_MAX_ALG_NAME
expansion") replaced some strncpy()s with strlcpy()s, thereby
introducing information leaks.  Later two other people tried to replace
other strncpy()s with strlcpy() too, which would have introduced even
more information leaks:

    - https://lore.kernel.org/patchwork/patch/954991/
    - https://patchwork.kernel.org/patch/10434351/

Commit cac5818c ("crypto: user - Implement a generic crypto
statistics") also uses the buggy strlcpy() approach and therefore leaks
uninitialized memory to userspace.  A fix was proposed, but it was
originally incomplete.

Seeing as how apparently no one can get this right with the current
approach, change all the reporting functions to:

- Start by memsetting the report structure to 0.  This guarantees it's
  always initialized, regardless of what happens later.
- Initialize all strings using strscpy().  This is safe after the
  memset, ensures null termination of long strings, avoids unnecessary
  work, and avoids the -Wstringop-truncation warnings from gcc.
- Use sizeof(var) instead of sizeof(type).  This is more robust against
  copy+paste errors.

For simplicity, also reuse the -EMSGSIZE return value from nla_put().
Signed-off-by: NEric Biggers <ebiggers@google.com>
Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
上级 ed848b65
...@@ -365,23 +365,19 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -365,23 +365,19 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
{ {
struct crypto_report_blkcipher rblkcipher; struct crypto_report_blkcipher rblkcipher;
strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type)); memset(&rblkcipher, 0, sizeof(rblkcipher));
strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<default>",
strscpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type));
strscpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<default>",
sizeof(rblkcipher.geniv)); sizeof(rblkcipher.geniv));
rblkcipher.geniv[sizeof(rblkcipher.geniv) - 1] = '\0';
rblkcipher.blocksize = alg->cra_blocksize; rblkcipher.blocksize = alg->cra_blocksize;
rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize; rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize; rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize;
rblkcipher.ivsize = alg->cra_ablkcipher.ivsize; rblkcipher.ivsize = alg->cra_ablkcipher.ivsize;
if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER, return nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
sizeof(struct crypto_report_blkcipher), &rblkcipher)) sizeof(rblkcipher), &rblkcipher);
goto nla_put_failure;
return 0;
nla_put_failure:
return -EMSGSIZE;
} }
#else #else
static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
...@@ -440,23 +436,19 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -440,23 +436,19 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
{ {
struct crypto_report_blkcipher rblkcipher; struct crypto_report_blkcipher rblkcipher;
strncpy(rblkcipher.type, "givcipher", sizeof(rblkcipher.type)); memset(&rblkcipher, 0, sizeof(rblkcipher));
strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<built-in>",
strscpy(rblkcipher.type, "givcipher", sizeof(rblkcipher.type));
strscpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<built-in>",
sizeof(rblkcipher.geniv)); sizeof(rblkcipher.geniv));
rblkcipher.geniv[sizeof(rblkcipher.geniv) - 1] = '\0';
rblkcipher.blocksize = alg->cra_blocksize; rblkcipher.blocksize = alg->cra_blocksize;
rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize; rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize; rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize;
rblkcipher.ivsize = alg->cra_ablkcipher.ivsize; rblkcipher.ivsize = alg->cra_ablkcipher.ivsize;
if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER, return nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
sizeof(struct crypto_report_blkcipher), &rblkcipher)) sizeof(rblkcipher), &rblkcipher);
goto nla_put_failure;
return 0;
nla_put_failure:
return -EMSGSIZE;
} }
#else #else
static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
......
...@@ -33,15 +33,11 @@ static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -33,15 +33,11 @@ static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg)
{ {
struct crypto_report_acomp racomp; struct crypto_report_acomp racomp;
strncpy(racomp.type, "acomp", sizeof(racomp.type)); memset(&racomp, 0, sizeof(racomp));
if (nla_put(skb, CRYPTOCFGA_REPORT_ACOMP, strscpy(racomp.type, "acomp", sizeof(racomp.type));
sizeof(struct crypto_report_acomp), &racomp))
goto nla_put_failure;
return 0;
nla_put_failure: return nla_put(skb, CRYPTOCFGA_REPORT_ACOMP, sizeof(racomp), &racomp);
return -EMSGSIZE;
} }
#else #else
static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg)
......
...@@ -119,20 +119,16 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -119,20 +119,16 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
struct crypto_report_aead raead; struct crypto_report_aead raead;
struct aead_alg *aead = container_of(alg, struct aead_alg, base); struct aead_alg *aead = container_of(alg, struct aead_alg, base);
strncpy(raead.type, "aead", sizeof(raead.type)); memset(&raead, 0, sizeof(raead));
strncpy(raead.geniv, "<none>", sizeof(raead.geniv));
strscpy(raead.type, "aead", sizeof(raead.type));
strscpy(raead.geniv, "<none>", sizeof(raead.geniv));
raead.blocksize = alg->cra_blocksize; raead.blocksize = alg->cra_blocksize;
raead.maxauthsize = aead->maxauthsize; raead.maxauthsize = aead->maxauthsize;
raead.ivsize = aead->ivsize; raead.ivsize = aead->ivsize;
if (nla_put(skb, CRYPTOCFGA_REPORT_AEAD, return nla_put(skb, CRYPTOCFGA_REPORT_AEAD, sizeof(raead), &raead);
sizeof(struct crypto_report_aead), &raead))
goto nla_put_failure;
return 0;
nla_put_failure:
return -EMSGSIZE;
} }
#else #else
static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
......
...@@ -498,18 +498,14 @@ static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -498,18 +498,14 @@ static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
{ {
struct crypto_report_hash rhash; struct crypto_report_hash rhash;
strncpy(rhash.type, "ahash", sizeof(rhash.type)); memset(&rhash, 0, sizeof(rhash));
strscpy(rhash.type, "ahash", sizeof(rhash.type));
rhash.blocksize = alg->cra_blocksize; rhash.blocksize = alg->cra_blocksize;
rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize; rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
if (nla_put(skb, CRYPTOCFGA_REPORT_HASH, return nla_put(skb, CRYPTOCFGA_REPORT_HASH, sizeof(rhash), &rhash);
sizeof(struct crypto_report_hash), &rhash))
goto nla_put_failure;
return 0;
nla_put_failure:
return -EMSGSIZE;
} }
#else #else
static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
......
...@@ -30,15 +30,12 @@ static int crypto_akcipher_report(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -30,15 +30,12 @@ static int crypto_akcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
{ {
struct crypto_report_akcipher rakcipher; struct crypto_report_akcipher rakcipher;
strncpy(rakcipher.type, "akcipher", sizeof(rakcipher.type)); memset(&rakcipher, 0, sizeof(rakcipher));
if (nla_put(skb, CRYPTOCFGA_REPORT_AKCIPHER, strscpy(rakcipher.type, "akcipher", sizeof(rakcipher.type));
sizeof(struct crypto_report_akcipher), &rakcipher))
goto nla_put_failure;
return 0;
nla_put_failure: return nla_put(skb, CRYPTOCFGA_REPORT_AKCIPHER,
return -EMSGSIZE; sizeof(rakcipher), &rakcipher);
} }
#else #else
static int crypto_akcipher_report(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_akcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
......
...@@ -507,23 +507,19 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -507,23 +507,19 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
{ {
struct crypto_report_blkcipher rblkcipher; struct crypto_report_blkcipher rblkcipher;
strncpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type)); memset(&rblkcipher, 0, sizeof(rblkcipher));
strncpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "<default>",
strscpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type));
strscpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "<default>",
sizeof(rblkcipher.geniv)); sizeof(rblkcipher.geniv));
rblkcipher.geniv[sizeof(rblkcipher.geniv) - 1] = '\0';
rblkcipher.blocksize = alg->cra_blocksize; rblkcipher.blocksize = alg->cra_blocksize;
rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize; rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize;
rblkcipher.max_keysize = alg->cra_blkcipher.max_keysize; rblkcipher.max_keysize = alg->cra_blkcipher.max_keysize;
rblkcipher.ivsize = alg->cra_blkcipher.ivsize; rblkcipher.ivsize = alg->cra_blkcipher.ivsize;
if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER, return nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
sizeof(struct crypto_report_blkcipher), &rblkcipher)) sizeof(rblkcipher), &rblkcipher);
goto nla_put_failure;
return 0;
nla_put_failure:
return -EMSGSIZE;
} }
#else #else
static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
......
...@@ -84,42 +84,38 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -84,42 +84,38 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
{ {
struct crypto_report_cipher rcipher; struct crypto_report_cipher rcipher;
strncpy(rcipher.type, "cipher", sizeof(rcipher.type)); memset(&rcipher, 0, sizeof(rcipher));
strscpy(rcipher.type, "cipher", sizeof(rcipher.type));
rcipher.blocksize = alg->cra_blocksize; rcipher.blocksize = alg->cra_blocksize;
rcipher.min_keysize = alg->cra_cipher.cia_min_keysize; rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
rcipher.max_keysize = alg->cra_cipher.cia_max_keysize; rcipher.max_keysize = alg->cra_cipher.cia_max_keysize;
if (nla_put(skb, CRYPTOCFGA_REPORT_CIPHER, return nla_put(skb, CRYPTOCFGA_REPORT_CIPHER,
sizeof(struct crypto_report_cipher), &rcipher)) sizeof(rcipher), &rcipher);
goto nla_put_failure;
return 0;
nla_put_failure:
return -EMSGSIZE;
} }
static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
{ {
struct crypto_report_comp rcomp; struct crypto_report_comp rcomp;
strncpy(rcomp.type, "compression", sizeof(rcomp.type)); memset(&rcomp, 0, sizeof(rcomp));
if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
sizeof(struct crypto_report_comp), &rcomp))
goto nla_put_failure;
return 0;
nla_put_failure: strscpy(rcomp.type, "compression", sizeof(rcomp.type));
return -EMSGSIZE;
return nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS, sizeof(rcomp), &rcomp);
} }
static int crypto_report_one(struct crypto_alg *alg, static int crypto_report_one(struct crypto_alg *alg,
struct crypto_user_alg *ualg, struct sk_buff *skb) struct crypto_user_alg *ualg, struct sk_buff *skb)
{ {
strncpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name)); memset(ualg, 0, sizeof(*ualg));
strncpy(ualg->cru_driver_name, alg->cra_driver_name,
strscpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
strscpy(ualg->cru_driver_name, alg->cra_driver_name,
sizeof(ualg->cru_driver_name)); sizeof(ualg->cru_driver_name));
strncpy(ualg->cru_module_name, module_name(alg->cra_module), strscpy(ualg->cru_module_name, module_name(alg->cra_module),
sizeof(ualg->cru_module_name)); sizeof(ualg->cru_module_name));
ualg->cru_type = 0; ualg->cru_type = 0;
...@@ -132,9 +128,9 @@ static int crypto_report_one(struct crypto_alg *alg, ...@@ -132,9 +128,9 @@ static int crypto_report_one(struct crypto_alg *alg,
if (alg->cra_flags & CRYPTO_ALG_LARVAL) { if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
struct crypto_report_larval rl; struct crypto_report_larval rl;
strncpy(rl.type, "larval", sizeof(rl.type)); memset(&rl, 0, sizeof(rl));
if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL, strscpy(rl.type, "larval", sizeof(rl.type));
sizeof(struct crypto_report_larval), &rl)) if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL, sizeof(rl), &rl))
goto nla_put_failure; goto nla_put_failure;
goto out; goto out;
} }
......
...@@ -39,7 +39,7 @@ static int crypto_report_aead(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -39,7 +39,7 @@ static int crypto_report_aead(struct sk_buff *skb, struct crypto_alg *alg)
memset(&raead, 0, sizeof(raead)); memset(&raead, 0, sizeof(raead));
strncpy(raead.type, "aead", sizeof(raead.type)); strscpy(raead.type, "aead", sizeof(raead.type));
v32 = atomic_read(&alg->encrypt_cnt); v32 = atomic_read(&alg->encrypt_cnt);
raead.stat_encrypt_cnt = v32; raead.stat_encrypt_cnt = v32;
...@@ -52,13 +52,7 @@ static int crypto_report_aead(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -52,13 +52,7 @@ static int crypto_report_aead(struct sk_buff *skb, struct crypto_alg *alg)
v32 = atomic_read(&alg->aead_err_cnt); v32 = atomic_read(&alg->aead_err_cnt);
raead.stat_aead_err_cnt = v32; raead.stat_aead_err_cnt = v32;
if (nla_put(skb, CRYPTOCFGA_STAT_AEAD, return nla_put(skb, CRYPTOCFGA_STAT_AEAD, sizeof(raead), &raead);
sizeof(struct crypto_stat), &raead))
goto nla_put_failure;
return 0;
nla_put_failure:
return -EMSGSIZE;
} }
static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
...@@ -69,7 +63,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -69,7 +63,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
memset(&rcipher, 0, sizeof(rcipher)); memset(&rcipher, 0, sizeof(rcipher));
strlcpy(rcipher.type, "cipher", sizeof(rcipher.type)); strscpy(rcipher.type, "cipher", sizeof(rcipher.type));
v32 = atomic_read(&alg->encrypt_cnt); v32 = atomic_read(&alg->encrypt_cnt);
rcipher.stat_encrypt_cnt = v32; rcipher.stat_encrypt_cnt = v32;
...@@ -82,13 +76,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -82,13 +76,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
v32 = atomic_read(&alg->cipher_err_cnt); v32 = atomic_read(&alg->cipher_err_cnt);
rcipher.stat_cipher_err_cnt = v32; rcipher.stat_cipher_err_cnt = v32;
if (nla_put(skb, CRYPTOCFGA_STAT_CIPHER, return nla_put(skb, CRYPTOCFGA_STAT_CIPHER, sizeof(rcipher), &rcipher);
sizeof(struct crypto_stat), &rcipher))
goto nla_put_failure;
return 0;
nla_put_failure:
return -EMSGSIZE;
} }
static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
...@@ -99,7 +87,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -99,7 +87,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
memset(&rcomp, 0, sizeof(rcomp)); memset(&rcomp, 0, sizeof(rcomp));
strlcpy(rcomp.type, "compression", sizeof(rcomp.type)); strscpy(rcomp.type, "compression", sizeof(rcomp.type));
v32 = atomic_read(&alg->compress_cnt); v32 = atomic_read(&alg->compress_cnt);
rcomp.stat_compress_cnt = v32; rcomp.stat_compress_cnt = v32;
v64 = atomic64_read(&alg->compress_tlen); v64 = atomic64_read(&alg->compress_tlen);
...@@ -111,13 +99,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -111,13 +99,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
v32 = atomic_read(&alg->cipher_err_cnt); v32 = atomic_read(&alg->cipher_err_cnt);
rcomp.stat_compress_err_cnt = v32; rcomp.stat_compress_err_cnt = v32;
if (nla_put(skb, CRYPTOCFGA_STAT_COMPRESS, return nla_put(skb, CRYPTOCFGA_STAT_COMPRESS, sizeof(rcomp), &rcomp);
sizeof(struct crypto_stat), &rcomp))
goto nla_put_failure;
return 0;
nla_put_failure:
return -EMSGSIZE;
} }
static int crypto_report_acomp(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_report_acomp(struct sk_buff *skb, struct crypto_alg *alg)
...@@ -128,7 +110,7 @@ static int crypto_report_acomp(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -128,7 +110,7 @@ static int crypto_report_acomp(struct sk_buff *skb, struct crypto_alg *alg)
memset(&racomp, 0, sizeof(racomp)); memset(&racomp, 0, sizeof(racomp));
strlcpy(racomp.type, "acomp", sizeof(racomp.type)); strscpy(racomp.type, "acomp", sizeof(racomp.type));
v32 = atomic_read(&alg->compress_cnt); v32 = atomic_read(&alg->compress_cnt);
racomp.stat_compress_cnt = v32; racomp.stat_compress_cnt = v32;
v64 = atomic64_read(&alg->compress_tlen); v64 = atomic64_read(&alg->compress_tlen);
...@@ -140,13 +122,7 @@ static int crypto_report_acomp(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -140,13 +122,7 @@ static int crypto_report_acomp(struct sk_buff *skb, struct crypto_alg *alg)
v32 = atomic_read(&alg->cipher_err_cnt); v32 = atomic_read(&alg->cipher_err_cnt);
racomp.stat_compress_err_cnt = v32; racomp.stat_compress_err_cnt = v32;
if (nla_put(skb, CRYPTOCFGA_STAT_ACOMP, return nla_put(skb, CRYPTOCFGA_STAT_ACOMP, sizeof(racomp), &racomp);
sizeof(struct crypto_stat), &racomp))
goto nla_put_failure;
return 0;
nla_put_failure:
return -EMSGSIZE;
} }
static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg)
...@@ -157,7 +133,7 @@ static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -157,7 +133,7 @@ static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg)
memset(&rakcipher, 0, sizeof(rakcipher)); memset(&rakcipher, 0, sizeof(rakcipher));
strncpy(rakcipher.type, "akcipher", sizeof(rakcipher.type)); strscpy(rakcipher.type, "akcipher", sizeof(rakcipher.type));
v32 = atomic_read(&alg->encrypt_cnt); v32 = atomic_read(&alg->encrypt_cnt);
rakcipher.stat_encrypt_cnt = v32; rakcipher.stat_encrypt_cnt = v32;
v64 = atomic64_read(&alg->encrypt_tlen); v64 = atomic64_read(&alg->encrypt_tlen);
...@@ -173,13 +149,8 @@ static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -173,13 +149,8 @@ static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg)
v32 = atomic_read(&alg->akcipher_err_cnt); v32 = atomic_read(&alg->akcipher_err_cnt);
rakcipher.stat_akcipher_err_cnt = v32; rakcipher.stat_akcipher_err_cnt = v32;
if (nla_put(skb, CRYPTOCFGA_STAT_AKCIPHER, return nla_put(skb, CRYPTOCFGA_STAT_AKCIPHER,
sizeof(struct crypto_stat), &rakcipher)) sizeof(rakcipher), &rakcipher);
goto nla_put_failure;
return 0;
nla_put_failure:
return -EMSGSIZE;
} }
static int crypto_report_kpp(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_report_kpp(struct sk_buff *skb, struct crypto_alg *alg)
...@@ -189,7 +160,7 @@ static int crypto_report_kpp(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -189,7 +160,7 @@ static int crypto_report_kpp(struct sk_buff *skb, struct crypto_alg *alg)
memset(&rkpp, 0, sizeof(rkpp)); memset(&rkpp, 0, sizeof(rkpp));
strlcpy(rkpp.type, "kpp", sizeof(rkpp.type)); strscpy(rkpp.type, "kpp", sizeof(rkpp.type));
v = atomic_read(&alg->setsecret_cnt); v = atomic_read(&alg->setsecret_cnt);
rkpp.stat_setsecret_cnt = v; rkpp.stat_setsecret_cnt = v;
...@@ -200,13 +171,7 @@ static int crypto_report_kpp(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -200,13 +171,7 @@ static int crypto_report_kpp(struct sk_buff *skb, struct crypto_alg *alg)
v = atomic_read(&alg->kpp_err_cnt); v = atomic_read(&alg->kpp_err_cnt);
rkpp.stat_kpp_err_cnt = v; rkpp.stat_kpp_err_cnt = v;
if (nla_put(skb, CRYPTOCFGA_STAT_KPP, return nla_put(skb, CRYPTOCFGA_STAT_KPP, sizeof(rkpp), &rkpp);
sizeof(struct crypto_stat), &rkpp))
goto nla_put_failure;
return 0;
nla_put_failure:
return -EMSGSIZE;
} }
static int crypto_report_ahash(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_report_ahash(struct sk_buff *skb, struct crypto_alg *alg)
...@@ -217,7 +182,7 @@ static int crypto_report_ahash(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -217,7 +182,7 @@ static int crypto_report_ahash(struct sk_buff *skb, struct crypto_alg *alg)
memset(&rhash, 0, sizeof(rhash)); memset(&rhash, 0, sizeof(rhash));
strncpy(rhash.type, "ahash", sizeof(rhash.type)); strscpy(rhash.type, "ahash", sizeof(rhash.type));
v32 = atomic_read(&alg->hash_cnt); v32 = atomic_read(&alg->hash_cnt);
rhash.stat_hash_cnt = v32; rhash.stat_hash_cnt = v32;
...@@ -226,13 +191,7 @@ static int crypto_report_ahash(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -226,13 +191,7 @@ static int crypto_report_ahash(struct sk_buff *skb, struct crypto_alg *alg)
v32 = atomic_read(&alg->hash_err_cnt); v32 = atomic_read(&alg->hash_err_cnt);
rhash.stat_hash_err_cnt = v32; rhash.stat_hash_err_cnt = v32;
if (nla_put(skb, CRYPTOCFGA_STAT_HASH, return nla_put(skb, CRYPTOCFGA_STAT_HASH, sizeof(rhash), &rhash);
sizeof(struct crypto_stat), &rhash))
goto nla_put_failure;
return 0;
nla_put_failure:
return -EMSGSIZE;
} }
static int crypto_report_shash(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_report_shash(struct sk_buff *skb, struct crypto_alg *alg)
...@@ -243,7 +202,7 @@ static int crypto_report_shash(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -243,7 +202,7 @@ static int crypto_report_shash(struct sk_buff *skb, struct crypto_alg *alg)
memset(&rhash, 0, sizeof(rhash)); memset(&rhash, 0, sizeof(rhash));
strncpy(rhash.type, "shash", sizeof(rhash.type)); strscpy(rhash.type, "shash", sizeof(rhash.type));
v32 = atomic_read(&alg->hash_cnt); v32 = atomic_read(&alg->hash_cnt);
rhash.stat_hash_cnt = v32; rhash.stat_hash_cnt = v32;
...@@ -252,13 +211,7 @@ static int crypto_report_shash(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -252,13 +211,7 @@ static int crypto_report_shash(struct sk_buff *skb, struct crypto_alg *alg)
v32 = atomic_read(&alg->hash_err_cnt); v32 = atomic_read(&alg->hash_err_cnt);
rhash.stat_hash_err_cnt = v32; rhash.stat_hash_err_cnt = v32;
if (nla_put(skb, CRYPTOCFGA_STAT_HASH, return nla_put(skb, CRYPTOCFGA_STAT_HASH, sizeof(rhash), &rhash);
sizeof(struct crypto_stat), &rhash))
goto nla_put_failure;
return 0;
nla_put_failure:
return -EMSGSIZE;
} }
static int crypto_report_rng(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_report_rng(struct sk_buff *skb, struct crypto_alg *alg)
...@@ -269,7 +222,7 @@ static int crypto_report_rng(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -269,7 +222,7 @@ static int crypto_report_rng(struct sk_buff *skb, struct crypto_alg *alg)
memset(&rrng, 0, sizeof(rrng)); memset(&rrng, 0, sizeof(rrng));
strncpy(rrng.type, "rng", sizeof(rrng.type)); strscpy(rrng.type, "rng", sizeof(rrng.type));
v32 = atomic_read(&alg->generate_cnt); v32 = atomic_read(&alg->generate_cnt);
rrng.stat_generate_cnt = v32; rrng.stat_generate_cnt = v32;
...@@ -280,13 +233,7 @@ static int crypto_report_rng(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -280,13 +233,7 @@ static int crypto_report_rng(struct sk_buff *skb, struct crypto_alg *alg)
v32 = atomic_read(&alg->hash_err_cnt); v32 = atomic_read(&alg->hash_err_cnt);
rrng.stat_rng_err_cnt = v32; rrng.stat_rng_err_cnt = v32;
if (nla_put(skb, CRYPTOCFGA_STAT_RNG, return nla_put(skb, CRYPTOCFGA_STAT_RNG, sizeof(rrng), &rrng);
sizeof(struct crypto_stat), &rrng))
goto nla_put_failure;
return 0;
nla_put_failure:
return -EMSGSIZE;
} }
static int crypto_reportstat_one(struct crypto_alg *alg, static int crypto_reportstat_one(struct crypto_alg *alg,
...@@ -295,10 +242,10 @@ static int crypto_reportstat_one(struct crypto_alg *alg, ...@@ -295,10 +242,10 @@ static int crypto_reportstat_one(struct crypto_alg *alg,
{ {
memset(ualg, 0, sizeof(*ualg)); memset(ualg, 0, sizeof(*ualg));
strlcpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name)); strscpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
strlcpy(ualg->cru_driver_name, alg->cra_driver_name, strscpy(ualg->cru_driver_name, alg->cra_driver_name,
sizeof(ualg->cru_driver_name)); sizeof(ualg->cru_driver_name));
strlcpy(ualg->cru_module_name, module_name(alg->cra_module), strscpy(ualg->cru_module_name, module_name(alg->cra_module),
sizeof(ualg->cru_module_name)); sizeof(ualg->cru_module_name));
ualg->cru_type = 0; ualg->cru_type = 0;
...@@ -312,9 +259,8 @@ static int crypto_reportstat_one(struct crypto_alg *alg, ...@@ -312,9 +259,8 @@ static int crypto_reportstat_one(struct crypto_alg *alg,
struct crypto_stat rl; struct crypto_stat rl;
memset(&rl, 0, sizeof(rl)); memset(&rl, 0, sizeof(rl));
strlcpy(rl.type, "larval", sizeof(rl.type)); strscpy(rl.type, "larval", sizeof(rl.type));
if (nla_put(skb, CRYPTOCFGA_STAT_LARVAL, if (nla_put(skb, CRYPTOCFGA_STAT_LARVAL, sizeof(rl), &rl))
sizeof(struct crypto_stat), &rl))
goto nla_put_failure; goto nla_put_failure;
goto out; goto out;
} }
......
...@@ -30,15 +30,11 @@ static int crypto_kpp_report(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -30,15 +30,11 @@ static int crypto_kpp_report(struct sk_buff *skb, struct crypto_alg *alg)
{ {
struct crypto_report_kpp rkpp; struct crypto_report_kpp rkpp;
strncpy(rkpp.type, "kpp", sizeof(rkpp.type)); memset(&rkpp, 0, sizeof(rkpp));
if (nla_put(skb, CRYPTOCFGA_REPORT_KPP, strscpy(rkpp.type, "kpp", sizeof(rkpp.type));
sizeof(struct crypto_report_kpp), &rkpp))
goto nla_put_failure;
return 0;
nla_put_failure: return nla_put(skb, CRYPTOCFGA_REPORT_KPP, sizeof(rkpp), &rkpp);
return -EMSGSIZE;
} }
#else #else
static int crypto_kpp_report(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_kpp_report(struct sk_buff *skb, struct crypto_alg *alg)
......
...@@ -74,17 +74,13 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -74,17 +74,13 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
{ {
struct crypto_report_rng rrng; struct crypto_report_rng rrng;
strncpy(rrng.type, "rng", sizeof(rrng.type)); memset(&rrng, 0, sizeof(rrng));
rrng.seedsize = seedsize(alg); strscpy(rrng.type, "rng", sizeof(rrng.type));
if (nla_put(skb, CRYPTOCFGA_REPORT_RNG, rrng.seedsize = seedsize(alg);
sizeof(struct crypto_report_rng), &rrng))
goto nla_put_failure;
return 0;
nla_put_failure: return nla_put(skb, CRYPTOCFGA_REPORT_RNG, sizeof(rrng), &rrng);
return -EMSGSIZE;
} }
#else #else
static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
......
...@@ -40,15 +40,12 @@ static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -40,15 +40,12 @@ static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg)
{ {
struct crypto_report_comp rscomp; struct crypto_report_comp rscomp;
strncpy(rscomp.type, "scomp", sizeof(rscomp.type)); memset(&rscomp, 0, sizeof(rscomp));
if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS, strscpy(rscomp.type, "scomp", sizeof(rscomp.type));
sizeof(struct crypto_report_comp), &rscomp))
goto nla_put_failure;
return 0;
nla_put_failure: return nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
return -EMSGSIZE; sizeof(rscomp), &rscomp);
} }
#else #else
static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg)
......
...@@ -408,18 +408,14 @@ static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -408,18 +408,14 @@ static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
struct crypto_report_hash rhash; struct crypto_report_hash rhash;
struct shash_alg *salg = __crypto_shash_alg(alg); struct shash_alg *salg = __crypto_shash_alg(alg);
strncpy(rhash.type, "shash", sizeof(rhash.type)); memset(&rhash, 0, sizeof(rhash));
strscpy(rhash.type, "shash", sizeof(rhash.type));
rhash.blocksize = alg->cra_blocksize; rhash.blocksize = alg->cra_blocksize;
rhash.digestsize = salg->digestsize; rhash.digestsize = salg->digestsize;
if (nla_put(skb, CRYPTOCFGA_REPORT_HASH, return nla_put(skb, CRYPTOCFGA_REPORT_HASH, sizeof(rhash), &rhash);
sizeof(struct crypto_report_hash), &rhash))
goto nla_put_failure;
return 0;
nla_put_failure:
return -EMSGSIZE;
} }
#else #else
static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
......
...@@ -897,21 +897,18 @@ static int crypto_skcipher_report(struct sk_buff *skb, struct crypto_alg *alg) ...@@ -897,21 +897,18 @@ static int crypto_skcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
struct skcipher_alg *skcipher = container_of(alg, struct skcipher_alg, struct skcipher_alg *skcipher = container_of(alg, struct skcipher_alg,
base); base);
strncpy(rblkcipher.type, "skcipher", sizeof(rblkcipher.type)); memset(&rblkcipher, 0, sizeof(rblkcipher));
strncpy(rblkcipher.geniv, "<none>", sizeof(rblkcipher.geniv));
strscpy(rblkcipher.type, "skcipher", sizeof(rblkcipher.type));
strscpy(rblkcipher.geniv, "<none>", sizeof(rblkcipher.geniv));
rblkcipher.blocksize = alg->cra_blocksize; rblkcipher.blocksize = alg->cra_blocksize;
rblkcipher.min_keysize = skcipher->min_keysize; rblkcipher.min_keysize = skcipher->min_keysize;
rblkcipher.max_keysize = skcipher->max_keysize; rblkcipher.max_keysize = skcipher->max_keysize;
rblkcipher.ivsize = skcipher->ivsize; rblkcipher.ivsize = skcipher->ivsize;
if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER, return nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
sizeof(struct crypto_report_blkcipher), &rblkcipher)) sizeof(rblkcipher), &rblkcipher);
goto nla_put_failure;
return 0;
nla_put_failure:
return -EMSGSIZE;
} }
#else #else
static int crypto_skcipher_report(struct sk_buff *skb, struct crypto_alg *alg) static int crypto_skcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册