aboutsummaryrefslogtreecommitdiffstats
path: root/security/keys
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2010-04-30 09:32:34 -0400
committerJames Morris <jmorris@namei.org>2010-05-05 20:56:55 -0400
commit2b9e4688fad8867b6e918610f396af3ab9246898 (patch)
treec0146493e6ea4dff7b51259de1d7e83729a26c94 /security/keys
parent553d603c8fce8cf727eb26e4bf6b9549cd4623f1 (diff)
KEYS: Better handling of errors from construct_alloc_key()
Errors from construct_alloc_key() shouldn't just be ignored in the way they are by construct_key_and_link(). The only error that can be ignored so is EINPROGRESS as that is used to indicate that we've found a key and don't need to construct one. We don't, however, handle ENOMEM, EDQUOT or EACCES to indicate allocation failures of one sort or another. Reported-by: Vegard Nossum <vegard.nossum@gmail.com> Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'security/keys')
-rw-r--r--security/keys/request_key.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/security/keys/request_key.c b/security/keys/request_key.c
index d737cea5347c..1bc38587adc4 100644
--- a/security/keys/request_key.c
+++ b/security/keys/request_key.c
@@ -302,6 +302,7 @@ static int construct_alloc_key(struct key_type *type,
302 const struct cred *cred = current_cred(); 302 const struct cred *cred = current_cred();
303 struct key *key; 303 struct key *key;
304 key_ref_t key_ref; 304 key_ref_t key_ref;
305 int ret;
305 306
306 kenter("%s,%s,,,", type->name, description); 307 kenter("%s,%s,,,", type->name, description);
307 308
@@ -337,14 +338,23 @@ static int construct_alloc_key(struct key_type *type,
337 kleave(" = 0 [%d]", key_serial(key)); 338 kleave(" = 0 [%d]", key_serial(key));
338 return 0; 339 return 0;
339 340
341 /* the key is now present - we tell the caller that we found it by
342 * returning -EINPROGRESS */
340key_already_present: 343key_already_present:
341 mutex_unlock(&key_construction_mutex); 344 mutex_unlock(&key_construction_mutex);
345 ret = 0;
342 if (dest_keyring) { 346 if (dest_keyring) {
343 __key_link(dest_keyring, key_ref_to_ptr(key_ref)); 347 ret = __key_link(dest_keyring, key_ref_to_ptr(key_ref));
344 up_write(&dest_keyring->sem); 348 up_write(&dest_keyring->sem);
345 } 349 }
346 mutex_unlock(&user->cons_lock); 350 mutex_unlock(&user->cons_lock);
347 key_put(key); 351 key_put(key);
352 if (ret < 0) {
353 key_ref_put(key_ref);
354 *_key = NULL;
355 kleave(" = %d [link]", ret);
356 return ret;
357 }
348 *_key = key = key_ref_to_ptr(key_ref); 358 *_key = key = key_ref_to_ptr(key_ref);
349 kleave(" = -EINPROGRESS [%d]", key_serial(key)); 359 kleave(" = -EINPROGRESS [%d]", key_serial(key));
350 return -EINPROGRESS; 360 return -EINPROGRESS;
@@ -390,6 +400,10 @@ static struct key *construct_key_and_link(struct key_type *type,
390 kdebug("cons failed"); 400 kdebug("cons failed");
391 goto construction_failed; 401 goto construction_failed;
392 } 402 }
403 } else if (ret == -EINPROGRESS) {
404 ret = 0;
405 } else {
406 key = ERR_PTR(ret);
393 } 407 }
394 408
395 key_put(dest_keyring); 409 key_put(dest_keyring);
@@ -422,6 +436,7 @@ struct key *request_key_and_link(struct key_type *type,
422 const struct cred *cred = current_cred(); 436 const struct cred *cred = current_cred();
423 struct key *key; 437 struct key *key;
424 key_ref_t key_ref; 438 key_ref_t key_ref;
439 int ret;
425 440
426 kenter("%s,%s,%p,%zu,%p,%p,%lx", 441 kenter("%s,%s,%p,%zu,%p,%p,%lx",
427 type->name, description, callout_info, callout_len, aux, 442 type->name, description, callout_info, callout_len, aux,
@@ -435,8 +450,13 @@ struct key *request_key_and_link(struct key_type *type,
435 key = key_ref_to_ptr(key_ref); 450 key = key_ref_to_ptr(key_ref);
436 if (dest_keyring) { 451 if (dest_keyring) {
437 construct_get_dest_keyring(&dest_keyring); 452 construct_get_dest_keyring(&dest_keyring);
438 key_link(dest_keyring, key); 453 ret = key_link(dest_keyring, key);
439 key_put(dest_keyring); 454 key_put(dest_keyring);
455 if (ret < 0) {
456 key_put(key);
457 key = ERR_PTR(ret);
458 goto error;
459 }
440 } 460 }
441 } else if (PTR_ERR(key_ref) != -EAGAIN) { 461 } else if (PTR_ERR(key_ref) != -EAGAIN) {
442 key = ERR_CAST(key_ref); 462 key = ERR_CAST(key_ref);