Skip to content

Commit

Permalink
crypto: user - Zeroize whole structure given to user space
Browse files Browse the repository at this point in the history
For preventing uninitialized data to be given to user-space (and so leak
potential useful data), the crypto_stat structure must be correctly
initialized.

Reported-by: Dan Carpenter <[email protected]>
Fixes: cac5818 ("crypto: user - Implement a generic crypto statistics")
Signed-off-by: Corentin Labbe <[email protected]>
[EB: also fix it in crypto_reportstat_one()]
[EB: use sizeof(var) rather than sizeof(type)]
Signed-off-by: Eric Biggers <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
montjoie authored and herbertx committed Nov 9, 2018
1 parent f43f399 commit 9f4debe
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions crypto/crypto_user_stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ static int crypto_report_aead(struct sk_buff *skb, struct crypto_alg *alg)
u64 v64;
u32 v32;

memset(&raead, 0, sizeof(raead));

strncpy(raead.type, "aead", sizeof(raead.type));

v32 = atomic_read(&alg->encrypt_cnt);
Expand Down Expand Up @@ -65,6 +67,8 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
u64 v64;
u32 v32;

memset(&rcipher, 0, sizeof(rcipher));

strlcpy(rcipher.type, "cipher", sizeof(rcipher.type));

v32 = atomic_read(&alg->encrypt_cnt);
Expand Down Expand Up @@ -93,6 +97,8 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
u64 v64;
u32 v32;

memset(&rcomp, 0, sizeof(rcomp));

strlcpy(rcomp.type, "compression", sizeof(rcomp.type));
v32 = atomic_read(&alg->compress_cnt);
rcomp.stat_compress_cnt = v32;
Expand Down Expand Up @@ -120,6 +126,8 @@ static int crypto_report_acomp(struct sk_buff *skb, struct crypto_alg *alg)
u64 v64;
u32 v32;

memset(&racomp, 0, sizeof(racomp));

strlcpy(racomp.type, "acomp", sizeof(racomp.type));
v32 = atomic_read(&alg->compress_cnt);
racomp.stat_compress_cnt = v32;
Expand Down Expand Up @@ -147,6 +155,8 @@ static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg)
u64 v64;
u32 v32;

memset(&rakcipher, 0, sizeof(rakcipher));

strncpy(rakcipher.type, "akcipher", sizeof(rakcipher.type));
v32 = atomic_read(&alg->encrypt_cnt);
rakcipher.stat_encrypt_cnt = v32;
Expand Down Expand Up @@ -177,6 +187,8 @@ static int crypto_report_kpp(struct sk_buff *skb, struct crypto_alg *alg)
struct crypto_stat rkpp;
u32 v;

memset(&rkpp, 0, sizeof(rkpp));

strlcpy(rkpp.type, "kpp", sizeof(rkpp.type));

v = atomic_read(&alg->setsecret_cnt);
Expand All @@ -203,6 +215,8 @@ static int crypto_report_ahash(struct sk_buff *skb, struct crypto_alg *alg)
u64 v64;
u32 v32;

memset(&rhash, 0, sizeof(rhash));

strncpy(rhash.type, "ahash", sizeof(rhash.type));

v32 = atomic_read(&alg->hash_cnt);
Expand All @@ -227,6 +241,8 @@ static int crypto_report_shash(struct sk_buff *skb, struct crypto_alg *alg)
u64 v64;
u32 v32;

memset(&rhash, 0, sizeof(rhash));

strncpy(rhash.type, "shash", sizeof(rhash.type));

v32 = atomic_read(&alg->hash_cnt);
Expand All @@ -251,6 +267,8 @@ static int crypto_report_rng(struct sk_buff *skb, struct crypto_alg *alg)
u64 v64;
u32 v32;

memset(&rrng, 0, sizeof(rrng));

strncpy(rrng.type, "rng", sizeof(rrng.type));

v32 = atomic_read(&alg->generate_cnt);
Expand All @@ -275,6 +293,8 @@ static int crypto_reportstat_one(struct crypto_alg *alg,
struct crypto_user_alg *ualg,
struct sk_buff *skb)
{
memset(ualg, 0, sizeof(*ualg));

strlcpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
strlcpy(ualg->cru_driver_name, alg->cra_driver_name,
sizeof(ualg->cru_driver_name));
Expand All @@ -291,6 +311,7 @@ static int crypto_reportstat_one(struct crypto_alg *alg,
if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
struct crypto_stat rl;

memset(&rl, 0, sizeof(rl));
strlcpy(rl.type, "larval", sizeof(rl.type));
if (nla_put(skb, CRYPTOCFGA_STAT_LARVAL,
sizeof(struct crypto_stat), &rl))
Expand Down

0 comments on commit 9f4debe

Please sign in to comment.