diff options
author | Mathias Krause <minipli@googlemail.com> | 2013-02-05 12:19:13 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2013-02-19 07:27:03 -0500 |
commit | 9a5467bf7b6e9e02ec9c3da4e23747c05faeaac6 (patch) | |
tree | 321e685947c9d47ca369efabb061bf50e1921c1d /crypto/crypto_user.c | |
parent | 7eb9c5df92361c55daab4d8d4e8468eb774e297b (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>
Diffstat (limited to 'crypto/crypto_user.c')
-rw-r--r-- | crypto/crypto_user.c | 22 |
1 files changed, 11 insertions, 11 deletions
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: | |||
108 | static int crypto_report_one(struct crypto_alg *alg, | 107 | static 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; |