aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Krause <minipli@googlemail.com>2013-02-05 12:19:13 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2013-02-19 07:27:03 -0500
commit9a5467bf7b6e9e02ec9c3da4e23747c05faeaac6 (patch)
tree321e685947c9d47ca369efabb061bf50e1921c1d
parent7eb9c5df92361c55daab4d8d4e8468eb774e297b (diff)
crypto: user - fix info leaks in report API
Three errors resulting in kernel memory disclosure: 1/ The structures used for the netlink based crypto algorithm report API are located on the stack. As snprintf() does not fill the remainder of the buffer with null bytes, those stack bytes will be disclosed to users of the API. Switch to strncpy() to fix this. 2/ crypto_report_one() does not initialize all field of struct crypto_user_alg. Fix this to fix the heap info leak. 3/ For the module name we should copy only as many bytes as module_name() returns -- not as much as the destination buffer could hold. But the current code does not and therefore copies random data from behind the end of the module name, as the module name is always shorter than CRYPTO_MAX_ALG_NAME. Also switch to use strncpy() to copy the algorithm's name and driver_name. They are strings, after all. Signed-off-by: Mathias Krause <minipli@googlemail.com> Cc: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--crypto/ablkcipher.c12
-rw-r--r--crypto/aead.c9
-rw-r--r--crypto/ahash.c2
-rw-r--r--crypto/blkcipher.c6
-rw-r--r--crypto/crypto_user.c22
-rw-r--r--crypto/pcompress.c3
-rw-r--r--crypto/rng.c2
-rw-r--r--crypto/shash.c3
8 files changed, 29 insertions, 30 deletions
diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
index 533de9550a82..7d4a8d28277e 100644
--- a/crypto/ablkcipher.c
+++ b/crypto/ablkcipher.c
@@ -388,9 +388,9 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
388{ 388{
389 struct crypto_report_blkcipher rblkcipher; 389 struct crypto_report_blkcipher rblkcipher;
390 390
391 snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "ablkcipher"); 391 strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type));
392 snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s", 392 strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<default>",
393 alg->cra_ablkcipher.geniv ?: "<default>"); 393 sizeof(rblkcipher.geniv));
394 394
395 rblkcipher.blocksize = alg->cra_blocksize; 395 rblkcipher.blocksize = alg->cra_blocksize;
396 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize; 396 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
@@ -469,9 +469,9 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
469{ 469{
470 struct crypto_report_blkcipher rblkcipher; 470 struct crypto_report_blkcipher rblkcipher;
471 471
472 snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "givcipher"); 472 strncpy(rblkcipher.type, "givcipher", sizeof(rblkcipher.type));
473 snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s", 473 strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<built-in>",
474 alg->cra_ablkcipher.geniv ?: "<built-in>"); 474 sizeof(rblkcipher.geniv));
475 475
476 rblkcipher.blocksize = alg->cra_blocksize; 476 rblkcipher.blocksize = alg->cra_blocksize;
477 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize; 477 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
diff --git a/crypto/aead.c b/crypto/aead.c
index 4d04e12ffde8..547491e35c63 100644
--- a/crypto/aead.c
+++ b/crypto/aead.c
@@ -117,9 +117,8 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
117 struct crypto_report_aead raead; 117 struct crypto_report_aead raead;
118 struct aead_alg *aead = &alg->cra_aead; 118 struct aead_alg *aead = &alg->cra_aead;
119 119
120 snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "aead"); 120 strncpy(raead.type, "aead", sizeof(raead.type));
121 snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s", 121 strncpy(raead.geniv, aead->geniv ?: "<built-in>", sizeof(raead.geniv));
122 aead->geniv ?: "<built-in>");
123 122
124 raead.blocksize = alg->cra_blocksize; 123 raead.blocksize = alg->cra_blocksize;
125 raead.maxauthsize = aead->maxauthsize; 124 raead.maxauthsize = aead->maxauthsize;
@@ -203,8 +202,8 @@ static int crypto_nivaead_report(struct sk_buff *skb, struct crypto_alg *alg)
203 struct crypto_report_aead raead; 202 struct crypto_report_aead raead;
204 struct aead_alg *aead = &alg->cra_aead; 203 struct aead_alg *aead = &alg->cra_aead;
205 204
206 snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "nivaead"); 205 strncpy(raead.type, "nivaead", sizeof(raead.type));
207 snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s", aead->geniv); 206 strncpy(raead.geniv, aead->geniv, sizeof(raead.geniv));
208 207
209 raead.blocksize = alg->cra_blocksize; 208 raead.blocksize = alg->cra_blocksize;
210 raead.maxauthsize = aead->maxauthsize; 209 raead.maxauthsize = aead->maxauthsize;
diff --git a/crypto/ahash.c b/crypto/ahash.c
index 3887856c2dd6..793a27f2493e 100644
--- a/crypto/ahash.c
+++ b/crypto/ahash.c
@@ -404,7 +404,7 @@ static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
404{ 404{
405 struct crypto_report_hash rhash; 405 struct crypto_report_hash rhash;
406 406
407 snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "ahash"); 407 strncpy(rhash.type, "ahash", sizeof(rhash.type));
408 408
409 rhash.blocksize = alg->cra_blocksize; 409 rhash.blocksize = alg->cra_blocksize;
410 rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize; 410 rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
index e9e7244d5ef5..a79e7e9ab86e 100644
--- a/crypto/blkcipher.c
+++ b/crypto/blkcipher.c
@@ -499,9 +499,9 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
499{ 499{
500 struct crypto_report_blkcipher rblkcipher; 500 struct crypto_report_blkcipher rblkcipher;
501 501
502 snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "blkcipher"); 502 strncpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type));
503 snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s", 503 strncpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "<default>",
504 alg->cra_blkcipher.geniv ?: "<default>"); 504 sizeof(rblkcipher.geniv));
505 505
506 rblkcipher.blocksize = alg->cra_blocksize; 506 rblkcipher.blocksize = alg->cra_blocksize;
507 rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize; 507 rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize;
diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
index 35d700a97d79..f6d9baf77f0a 100644
--- a/crypto/crypto_user.c
+++ b/crypto/crypto_user.c
@@ -75,7 +75,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
75{ 75{
76 struct crypto_report_cipher rcipher; 76 struct crypto_report_cipher rcipher;
77 77
78 snprintf(rcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "cipher"); 78 strncpy(rcipher.type, "cipher", sizeof(rcipher.type));
79 79
80 rcipher.blocksize = alg->cra_blocksize; 80 rcipher.blocksize = alg->cra_blocksize;
81 rcipher.min_keysize = alg->cra_cipher.cia_min_keysize; 81 rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
@@ -94,8 +94,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
94{ 94{
95 struct crypto_report_comp rcomp; 95 struct crypto_report_comp rcomp;
96 96
97 snprintf(rcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "compression"); 97 strncpy(rcomp.type, "compression", sizeof(rcomp.type));
98
99 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS, 98 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
100 sizeof(struct crypto_report_comp), &rcomp)) 99 sizeof(struct crypto_report_comp), &rcomp))
101 goto nla_put_failure; 100 goto nla_put_failure;
@@ -108,12 +107,14 @@ nla_put_failure:
108static int crypto_report_one(struct crypto_alg *alg, 107static int crypto_report_one(struct crypto_alg *alg,
109 struct crypto_user_alg *ualg, struct sk_buff *skb) 108 struct crypto_user_alg *ualg, struct sk_buff *skb)
110{ 109{
111 memcpy(&ualg->cru_name, &alg->cra_name, sizeof(ualg->cru_name)); 110 strncpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
112 memcpy(&ualg->cru_driver_name, &alg->cra_driver_name, 111 strncpy(ualg->cru_driver_name, alg->cra_driver_name,
113 sizeof(ualg->cru_driver_name)); 112 sizeof(ualg->cru_driver_name));
114 memcpy(&ualg->cru_module_name, module_name(alg->cra_module), 113 strncpy(ualg->cru_module_name, module_name(alg->cra_module),
115 CRYPTO_MAX_ALG_NAME); 114 sizeof(ualg->cru_module_name));
116 115
116 ualg->cru_type = 0;
117 ualg->cru_mask = 0;
117 ualg->cru_flags = alg->cra_flags; 118 ualg->cru_flags = alg->cra_flags;
118 ualg->cru_refcnt = atomic_read(&alg->cra_refcnt); 119 ualg->cru_refcnt = atomic_read(&alg->cra_refcnt);
119 120
@@ -122,8 +123,7 @@ static int crypto_report_one(struct crypto_alg *alg,
122 if (alg->cra_flags & CRYPTO_ALG_LARVAL) { 123 if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
123 struct crypto_report_larval rl; 124 struct crypto_report_larval rl;
124 125
125 snprintf(rl.type, CRYPTO_MAX_ALG_NAME, "%s", "larval"); 126 strncpy(rl.type, "larval", sizeof(rl.type));
126
127 if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL, 127 if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL,
128 sizeof(struct crypto_report_larval), &rl)) 128 sizeof(struct crypto_report_larval), &rl))
129 goto nla_put_failure; 129 goto nla_put_failure;
diff --git a/crypto/pcompress.c b/crypto/pcompress.c
index 04e083ff5373..7140fe70c7af 100644
--- a/crypto/pcompress.c
+++ b/crypto/pcompress.c
@@ -53,8 +53,7 @@ static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg)
53{ 53{
54 struct crypto_report_comp rpcomp; 54 struct crypto_report_comp rpcomp;
55 55
56 snprintf(rpcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "pcomp"); 56 strncpy(rpcomp.type, "pcomp", sizeof(rpcomp.type));
57
58 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS, 57 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
59 sizeof(struct crypto_report_comp), &rpcomp)) 58 sizeof(struct crypto_report_comp), &rpcomp))
60 goto nla_put_failure; 59 goto nla_put_failure;
diff --git a/crypto/rng.c b/crypto/rng.c
index f3b7894dec00..e0a25c2456de 100644
--- a/crypto/rng.c
+++ b/crypto/rng.c
@@ -65,7 +65,7 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
65{ 65{
66 struct crypto_report_rng rrng; 66 struct crypto_report_rng rrng;
67 67
68 snprintf(rrng.type, CRYPTO_MAX_ALG_NAME, "%s", "rng"); 68 strncpy(rrng.type, "rng", sizeof(rrng.type));
69 69
70 rrng.seedsize = alg->cra_rng.seedsize; 70 rrng.seedsize = alg->cra_rng.seedsize;
71 71
diff --git a/crypto/shash.c b/crypto/shash.c
index f426330f1017..929058a68561 100644
--- a/crypto/shash.c
+++ b/crypto/shash.c
@@ -530,7 +530,8 @@ static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
530 struct crypto_report_hash rhash; 530 struct crypto_report_hash rhash;
531 struct shash_alg *salg = __crypto_shash_alg(alg); 531 struct shash_alg *salg = __crypto_shash_alg(alg);
532 532
533 snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "shash"); 533 strncpy(rhash.type, "shash", sizeof(rhash.type));
534
534 rhash.blocksize = alg->cra_blocksize; 535 rhash.blocksize = alg->cra_blocksize;
535 rhash.digestsize = salg->digestsize; 536 rhash.digestsize = salg->digestsize;
536 537