summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2017-04-06 04:16:08 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2017-04-10 07:17:26 -0400
commit4473710df1f8779c59b33737eeaa151596907761 (patch)
tree1c2a0a8e17befe7dc53385d20808300af58d599e
parentca3bff70ab320a9132c5524c495455526df4b078 (diff)
crypto: user - Prepare for CRYPTO_MAX_ALG_NAME expansion
This patch hard-codes CRYPTO_MAX_NAME in the user-space API to 64, which is the current value of CRYPTO_MAX_ALG_NAME. This patch also replaces all remaining occurences of CRYPTO_MAX_ALG_NAME in the user-space API with CRYPTO_MAX_NAME. This way the user-space API will not be modified when we raise the value of CRYPTO_MAX_ALG_NAME. Furthermore, the code has been updated to handle names longer than the user-space API. They will be truncated. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Acked-by: Alexander Sverdlin <alexander.sverdlin@nokia.com> Tested-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
-rw-r--r--crypto/crypto_user.c18
-rw-r--r--include/uapi/linux/cryptouser.h10
2 files changed, 14 insertions, 14 deletions
diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
index a90404a0c5ff..89acaab1d909 100644
--- a/crypto/crypto_user.c
+++ b/crypto/crypto_user.c
@@ -83,7 +83,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
83{ 83{
84 struct crypto_report_cipher rcipher; 84 struct crypto_report_cipher rcipher;
85 85
86 strncpy(rcipher.type, "cipher", sizeof(rcipher.type)); 86 strlcpy(rcipher.type, "cipher", sizeof(rcipher.type));
87 87
88 rcipher.blocksize = alg->cra_blocksize; 88 rcipher.blocksize = alg->cra_blocksize;
89 rcipher.min_keysize = alg->cra_cipher.cia_min_keysize; 89 rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
@@ -102,7 +102,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
102{ 102{
103 struct crypto_report_comp rcomp; 103 struct crypto_report_comp rcomp;
104 104
105 strncpy(rcomp.type, "compression", sizeof(rcomp.type)); 105 strlcpy(rcomp.type, "compression", sizeof(rcomp.type));
106 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS, 106 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
107 sizeof(struct crypto_report_comp), &rcomp)) 107 sizeof(struct crypto_report_comp), &rcomp))
108 goto nla_put_failure; 108 goto nla_put_failure;
@@ -116,7 +116,7 @@ static int crypto_report_acomp(struct sk_buff *skb, struct crypto_alg *alg)
116{ 116{
117 struct crypto_report_acomp racomp; 117 struct crypto_report_acomp racomp;
118 118
119 strncpy(racomp.type, "acomp", sizeof(racomp.type)); 119 strlcpy(racomp.type, "acomp", sizeof(racomp.type));
120 120
121 if (nla_put(skb, CRYPTOCFGA_REPORT_ACOMP, 121 if (nla_put(skb, CRYPTOCFGA_REPORT_ACOMP,
122 sizeof(struct crypto_report_acomp), &racomp)) 122 sizeof(struct crypto_report_acomp), &racomp))
@@ -131,7 +131,7 @@ static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg)
131{ 131{
132 struct crypto_report_akcipher rakcipher; 132 struct crypto_report_akcipher rakcipher;
133 133
134 strncpy(rakcipher.type, "akcipher", sizeof(rakcipher.type)); 134 strlcpy(rakcipher.type, "akcipher", sizeof(rakcipher.type));
135 135
136 if (nla_put(skb, CRYPTOCFGA_REPORT_AKCIPHER, 136 if (nla_put(skb, CRYPTOCFGA_REPORT_AKCIPHER,
137 sizeof(struct crypto_report_akcipher), &rakcipher)) 137 sizeof(struct crypto_report_akcipher), &rakcipher))
@@ -146,7 +146,7 @@ static int crypto_report_kpp(struct sk_buff *skb, struct crypto_alg *alg)
146{ 146{
147 struct crypto_report_kpp rkpp; 147 struct crypto_report_kpp rkpp;
148 148
149 strncpy(rkpp.type, "kpp", sizeof(rkpp.type)); 149 strlcpy(rkpp.type, "kpp", sizeof(rkpp.type));
150 150
151 if (nla_put(skb, CRYPTOCFGA_REPORT_KPP, 151 if (nla_put(skb, CRYPTOCFGA_REPORT_KPP,
152 sizeof(struct crypto_report_kpp), &rkpp)) 152 sizeof(struct crypto_report_kpp), &rkpp))
@@ -160,10 +160,10 @@ nla_put_failure:
160static int crypto_report_one(struct crypto_alg *alg, 160static int crypto_report_one(struct crypto_alg *alg,
161 struct crypto_user_alg *ualg, struct sk_buff *skb) 161 struct crypto_user_alg *ualg, struct sk_buff *skb)
162{ 162{
163 strncpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name)); 163 strlcpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
164 strncpy(ualg->cru_driver_name, alg->cra_driver_name, 164 strlcpy(ualg->cru_driver_name, alg->cra_driver_name,
165 sizeof(ualg->cru_driver_name)); 165 sizeof(ualg->cru_driver_name));
166 strncpy(ualg->cru_module_name, module_name(alg->cra_module), 166 strlcpy(ualg->cru_module_name, module_name(alg->cra_module),
167 sizeof(ualg->cru_module_name)); 167 sizeof(ualg->cru_module_name));
168 168
169 ualg->cru_type = 0; 169 ualg->cru_type = 0;
@@ -176,7 +176,7 @@ static int crypto_report_one(struct crypto_alg *alg,
176 if (alg->cra_flags & CRYPTO_ALG_LARVAL) { 176 if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
177 struct crypto_report_larval rl; 177 struct crypto_report_larval rl;
178 178
179 strncpy(rl.type, "larval", sizeof(rl.type)); 179 strlcpy(rl.type, "larval", sizeof(rl.type));
180 if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL, 180 if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL,
181 sizeof(struct crypto_report_larval), &rl)) 181 sizeof(struct crypto_report_larval), &rl))
182 goto nla_put_failure; 182 goto nla_put_failure;
diff --git a/include/uapi/linux/cryptouser.h b/include/uapi/linux/cryptouser.h
index 11d21fce14d6..b4def5c630e7 100644
--- a/include/uapi/linux/cryptouser.h
+++ b/include/uapi/linux/cryptouser.h
@@ -31,7 +31,7 @@ enum {
31#define CRYPTO_MSG_MAX (__CRYPTO_MSG_MAX - 1) 31#define CRYPTO_MSG_MAX (__CRYPTO_MSG_MAX - 1)
32#define CRYPTO_NR_MSGTYPES (CRYPTO_MSG_MAX + 1 - CRYPTO_MSG_BASE) 32#define CRYPTO_NR_MSGTYPES (CRYPTO_MSG_MAX + 1 - CRYPTO_MSG_BASE)
33 33
34#define CRYPTO_MAX_NAME CRYPTO_MAX_ALG_NAME 34#define CRYPTO_MAX_NAME 64
35 35
36/* Netlink message attributes. */ 36/* Netlink message attributes. */
37enum crypto_attr_type_t { 37enum crypto_attr_type_t {
@@ -53,9 +53,9 @@ enum crypto_attr_type_t {
53}; 53};
54 54
55struct crypto_user_alg { 55struct crypto_user_alg {
56 char cru_name[CRYPTO_MAX_ALG_NAME]; 56 char cru_name[CRYPTO_MAX_NAME];
57 char cru_driver_name[CRYPTO_MAX_ALG_NAME]; 57 char cru_driver_name[CRYPTO_MAX_NAME];
58 char cru_module_name[CRYPTO_MAX_ALG_NAME]; 58 char cru_module_name[CRYPTO_MAX_NAME];
59 __u32 cru_type; 59 __u32 cru_type;
60 __u32 cru_mask; 60 __u32 cru_mask;
61 __u32 cru_refcnt; 61 __u32 cru_refcnt;
@@ -73,7 +73,7 @@ struct crypto_report_hash {
73}; 73};
74 74
75struct crypto_report_cipher { 75struct crypto_report_cipher {
76 char type[CRYPTO_MAX_ALG_NAME]; 76 char type[CRYPTO_MAX_NAME];
77 unsigned int blocksize; 77 unsigned int blocksize;
78 unsigned int min_keysize; 78 unsigned int min_keysize;
79 unsigned int max_keysize; 79 unsigned int max_keysize;