summaryrefslogtreecommitdiffstats
path: root/crypto/crypto_user.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/crypto_user.c')
-rw-r--r--crypto/crypto_user.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
index 35d700a97d79..dfd511fb39ee 100644
--- a/crypto/crypto_user.c
+++ b/crypto/crypto_user.c
@@ -30,6 +30,8 @@
30 30
31#include "internal.h" 31#include "internal.h"
32 32
33#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
34
33static DEFINE_MUTEX(crypto_cfg_mutex); 35static DEFINE_MUTEX(crypto_cfg_mutex);
34 36
35/* The crypto netlink socket */ 37/* The crypto netlink socket */
@@ -75,7 +77,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
75{ 77{
76 struct crypto_report_cipher rcipher; 78 struct crypto_report_cipher rcipher;
77 79
78 snprintf(rcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "cipher"); 80 strncpy(rcipher.type, "cipher", sizeof(rcipher.type));
79 81
80 rcipher.blocksize = alg->cra_blocksize; 82 rcipher.blocksize = alg->cra_blocksize;
81 rcipher.min_keysize = alg->cra_cipher.cia_min_keysize; 83 rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
@@ -94,8 +96,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
94{ 96{
95 struct crypto_report_comp rcomp; 97 struct crypto_report_comp rcomp;
96 98
97 snprintf(rcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "compression"); 99 strncpy(rcomp.type, "compression", sizeof(rcomp.type));
98
99 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS, 100 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
100 sizeof(struct crypto_report_comp), &rcomp)) 101 sizeof(struct crypto_report_comp), &rcomp))
101 goto nla_put_failure; 102 goto nla_put_failure;
@@ -108,12 +109,14 @@ nla_put_failure:
108static int crypto_report_one(struct crypto_alg *alg, 109static int crypto_report_one(struct crypto_alg *alg,
109 struct crypto_user_alg *ualg, struct sk_buff *skb) 110 struct crypto_user_alg *ualg, struct sk_buff *skb)
110{ 111{
111 memcpy(&ualg->cru_name, &alg->cra_name, sizeof(ualg->cru_name)); 112 strncpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
112 memcpy(&ualg->cru_driver_name, &alg->cra_driver_name, 113 strncpy(ualg->cru_driver_name, alg->cra_driver_name,
113 sizeof(ualg->cru_driver_name)); 114 sizeof(ualg->cru_driver_name));
114 memcpy(&ualg->cru_module_name, module_name(alg->cra_module), 115 strncpy(ualg->cru_module_name, module_name(alg->cra_module),
115 CRYPTO_MAX_ALG_NAME); 116 sizeof(ualg->cru_module_name));
116 117
118 ualg->cru_type = 0;
119 ualg->cru_mask = 0;
117 ualg->cru_flags = alg->cra_flags; 120 ualg->cru_flags = alg->cra_flags;
118 ualg->cru_refcnt = atomic_read(&alg->cra_refcnt); 121 ualg->cru_refcnt = atomic_read(&alg->cra_refcnt);
119 122
@@ -122,8 +125,7 @@ static int crypto_report_one(struct crypto_alg *alg,
122 if (alg->cra_flags & CRYPTO_ALG_LARVAL) { 125 if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
123 struct crypto_report_larval rl; 126 struct crypto_report_larval rl;
124 127
125 snprintf(rl.type, CRYPTO_MAX_ALG_NAME, "%s", "larval"); 128 strncpy(rl.type, "larval", sizeof(rl.type));
126
127 if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL, 129 if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL,
128 sizeof(struct crypto_report_larval), &rl)) 130 sizeof(struct crypto_report_larval), &rl))
129 goto nla_put_failure; 131 goto nla_put_failure;
@@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
196 struct crypto_dump_info info; 198 struct crypto_dump_info info;
197 int err; 199 int err;
198 200
199 if (!p->cru_driver_name) 201 if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
202 return -EINVAL;
203
204 if (!p->cru_driver_name[0])
200 return -EINVAL; 205 return -EINVAL;
201 206
202 alg = crypto_alg_match(p, 1); 207 alg = crypto_alg_match(p, 1);
@@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
260 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL]; 265 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
261 LIST_HEAD(list); 266 LIST_HEAD(list);
262 267
268 if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
269 return -EINVAL;
270
263 if (priority && !strlen(p->cru_driver_name)) 271 if (priority && !strlen(p->cru_driver_name))
264 return -EINVAL; 272 return -EINVAL;
265 273
@@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
287 struct crypto_alg *alg; 295 struct crypto_alg *alg;
288 struct crypto_user_alg *p = nlmsg_data(nlh); 296 struct crypto_user_alg *p = nlmsg_data(nlh);
289 297
298 if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
299 return -EINVAL;
300
290 alg = crypto_alg_match(p, 1); 301 alg = crypto_alg_match(p, 1);
291 if (!alg) 302 if (!alg)
292 return -ENOENT; 303 return -ENOENT;
@@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
368 struct crypto_user_alg *p = nlmsg_data(nlh); 379 struct crypto_user_alg *p = nlmsg_data(nlh);
369 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL]; 380 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
370 381
382 if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
383 return -EINVAL;
384
371 if (strlen(p->cru_driver_name)) 385 if (strlen(p->cru_driver_name))
372 exact = 1; 386 exact = 1;
373 387