diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-10-09 03:02:35 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-10-09 03:02:35 -0400 |
commit | 1236d6bb6e19fc72ffc6bbcdeb1bfefe450e54ee (patch) | |
tree | 47da3feee8e263e8c9352c85cf518e624be3c211 /security/keys/request_key_auth.c | |
parent | 750b1a6894ecc9b178c6e3d0a1170122971b2036 (diff) | |
parent | 8a5776a5f49812d29fe4b2d0a2d71675c3facf3f (diff) |
Merge 4.14-rc4 into staging-next
We want the staging/iio fixes in here as well to handle merge issues.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'security/keys/request_key_auth.c')
-rw-r--r-- | security/keys/request_key_auth.c | 74 |
1 files changed, 33 insertions, 41 deletions
diff --git a/security/keys/request_key_auth.c b/security/keys/request_key_auth.c index afe9d22ab361..6ebf1af8fce9 100644 --- a/security/keys/request_key_auth.c +++ b/security/keys/request_key_auth.c | |||
@@ -120,6 +120,18 @@ static void request_key_auth_revoke(struct key *key) | |||
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | static void free_request_key_auth(struct request_key_auth *rka) | ||
124 | { | ||
125 | if (!rka) | ||
126 | return; | ||
127 | key_put(rka->target_key); | ||
128 | key_put(rka->dest_keyring); | ||
129 | if (rka->cred) | ||
130 | put_cred(rka->cred); | ||
131 | kfree(rka->callout_info); | ||
132 | kfree(rka); | ||
133 | } | ||
134 | |||
123 | /* | 135 | /* |
124 | * Destroy an instantiation authorisation token key. | 136 | * Destroy an instantiation authorisation token key. |
125 | */ | 137 | */ |
@@ -129,15 +141,7 @@ static void request_key_auth_destroy(struct key *key) | |||
129 | 141 | ||
130 | kenter("{%d}", key->serial); | 142 | kenter("{%d}", key->serial); |
131 | 143 | ||
132 | if (rka->cred) { | 144 | free_request_key_auth(rka); |
133 | put_cred(rka->cred); | ||
134 | rka->cred = NULL; | ||
135 | } | ||
136 | |||
137 | key_put(rka->target_key); | ||
138 | key_put(rka->dest_keyring); | ||
139 | kfree(rka->callout_info); | ||
140 | kfree(rka); | ||
141 | } | 145 | } |
142 | 146 | ||
143 | /* | 147 | /* |
@@ -151,22 +155,18 @@ struct key *request_key_auth_new(struct key *target, const void *callout_info, | |||
151 | const struct cred *cred = current->cred; | 155 | const struct cred *cred = current->cred; |
152 | struct key *authkey = NULL; | 156 | struct key *authkey = NULL; |
153 | char desc[20]; | 157 | char desc[20]; |
154 | int ret; | 158 | int ret = -ENOMEM; |
155 | 159 | ||
156 | kenter("%d,", target->serial); | 160 | kenter("%d,", target->serial); |
157 | 161 | ||
158 | /* allocate a auth record */ | 162 | /* allocate a auth record */ |
159 | rka = kmalloc(sizeof(*rka), GFP_KERNEL); | 163 | rka = kzalloc(sizeof(*rka), GFP_KERNEL); |
160 | if (!rka) { | 164 | if (!rka) |
161 | kleave(" = -ENOMEM"); | 165 | goto error; |
162 | return ERR_PTR(-ENOMEM); | 166 | rka->callout_info = kmemdup(callout_info, callout_len, GFP_KERNEL); |
163 | } | 167 | if (!rka->callout_info) |
164 | rka->callout_info = kmalloc(callout_len, GFP_KERNEL); | 168 | goto error_free_rka; |
165 | if (!rka->callout_info) { | 169 | rka->callout_len = callout_len; |
166 | kleave(" = -ENOMEM"); | ||
167 | kfree(rka); | ||
168 | return ERR_PTR(-ENOMEM); | ||
169 | } | ||
170 | 170 | ||
171 | /* see if the calling process is already servicing the key request of | 171 | /* see if the calling process is already servicing the key request of |
172 | * another process */ | 172 | * another process */ |
@@ -176,8 +176,12 @@ struct key *request_key_auth_new(struct key *target, const void *callout_info, | |||
176 | 176 | ||
177 | /* if the auth key has been revoked, then the key we're | 177 | /* if the auth key has been revoked, then the key we're |
178 | * servicing is already instantiated */ | 178 | * servicing is already instantiated */ |
179 | if (test_bit(KEY_FLAG_REVOKED, &cred->request_key_auth->flags)) | 179 | if (test_bit(KEY_FLAG_REVOKED, |
180 | goto auth_key_revoked; | 180 | &cred->request_key_auth->flags)) { |
181 | up_read(&cred->request_key_auth->sem); | ||
182 | ret = -EKEYREVOKED; | ||
183 | goto error_free_rka; | ||
184 | } | ||
181 | 185 | ||
182 | irka = cred->request_key_auth->payload.data[0]; | 186 | irka = cred->request_key_auth->payload.data[0]; |
183 | rka->cred = get_cred(irka->cred); | 187 | rka->cred = get_cred(irka->cred); |
@@ -193,8 +197,6 @@ struct key *request_key_auth_new(struct key *target, const void *callout_info, | |||
193 | 197 | ||
194 | rka->target_key = key_get(target); | 198 | rka->target_key = key_get(target); |
195 | rka->dest_keyring = key_get(dest_keyring); | 199 | rka->dest_keyring = key_get(dest_keyring); |
196 | memcpy(rka->callout_info, callout_info, callout_len); | ||
197 | rka->callout_len = callout_len; | ||
198 | 200 | ||
199 | /* allocate the auth key */ | 201 | /* allocate the auth key */ |
200 | sprintf(desc, "%x", target->serial); | 202 | sprintf(desc, "%x", target->serial); |
@@ -205,32 +207,22 @@ struct key *request_key_auth_new(struct key *target, const void *callout_info, | |||
205 | KEY_USR_VIEW, KEY_ALLOC_NOT_IN_QUOTA, NULL); | 207 | KEY_USR_VIEW, KEY_ALLOC_NOT_IN_QUOTA, NULL); |
206 | if (IS_ERR(authkey)) { | 208 | if (IS_ERR(authkey)) { |
207 | ret = PTR_ERR(authkey); | 209 | ret = PTR_ERR(authkey); |
208 | goto error_alloc; | 210 | goto error_free_rka; |
209 | } | 211 | } |
210 | 212 | ||
211 | /* construct the auth key */ | 213 | /* construct the auth key */ |
212 | ret = key_instantiate_and_link(authkey, rka, 0, NULL, NULL); | 214 | ret = key_instantiate_and_link(authkey, rka, 0, NULL, NULL); |
213 | if (ret < 0) | 215 | if (ret < 0) |
214 | goto error_inst; | 216 | goto error_put_authkey; |
215 | 217 | ||
216 | kleave(" = {%d,%d}", authkey->serial, refcount_read(&authkey->usage)); | 218 | kleave(" = {%d,%d}", authkey->serial, refcount_read(&authkey->usage)); |
217 | return authkey; | 219 | return authkey; |
218 | 220 | ||
219 | auth_key_revoked: | 221 | error_put_authkey: |
220 | up_read(&cred->request_key_auth->sem); | ||
221 | kfree(rka->callout_info); | ||
222 | kfree(rka); | ||
223 | kleave("= -EKEYREVOKED"); | ||
224 | return ERR_PTR(-EKEYREVOKED); | ||
225 | |||
226 | error_inst: | ||
227 | key_revoke(authkey); | ||
228 | key_put(authkey); | 222 | key_put(authkey); |
229 | error_alloc: | 223 | error_free_rka: |
230 | key_put(rka->target_key); | 224 | free_request_key_auth(rka); |
231 | key_put(rka->dest_keyring); | 225 | error: |
232 | kfree(rka->callout_info); | ||
233 | kfree(rka); | ||
234 | kleave("= %d", ret); | 226 | kleave("= %d", ret); |
235 | return ERR_PTR(ret); | 227 | return ERR_PTR(ret); |
236 | } | 228 | } |