aboutsummaryrefslogtreecommitdiffstats
path: root/security/keys/request_key.c
diff options
context:
space:
mode:
Diffstat (limited to 'security/keys/request_key.c')
-rw-r--r--security/keys/request_key.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/security/keys/request_key.c b/security/keys/request_key.c
index 22a31582bfaa..03fe63ed55bd 100644
--- a/security/keys/request_key.c
+++ b/security/keys/request_key.c
@@ -311,7 +311,8 @@ static int construct_alloc_key(struct key_type *type,
311 311
312 set_bit(KEY_FLAG_USER_CONSTRUCT, &key->flags); 312 set_bit(KEY_FLAG_USER_CONSTRUCT, &key->flags);
313 313
314 down_write(&dest_keyring->sem); 314 if (dest_keyring)
315 down_write(&dest_keyring->sem);
315 316
316 /* attach the key to the destination keyring under lock, but we do need 317 /* attach the key to the destination keyring under lock, but we do need
317 * to do another check just in case someone beat us to it whilst we 318 * to do another check just in case someone beat us to it whilst we
@@ -322,10 +323,12 @@ static int construct_alloc_key(struct key_type *type,
322 if (!IS_ERR(key_ref)) 323 if (!IS_ERR(key_ref))
323 goto key_already_present; 324 goto key_already_present;
324 325
325 __key_link(dest_keyring, key); 326 if (dest_keyring)
327 __key_link(dest_keyring, key);
326 328
327 mutex_unlock(&key_construction_mutex); 329 mutex_unlock(&key_construction_mutex);
328 up_write(&dest_keyring->sem); 330 if (dest_keyring)
331 up_write(&dest_keyring->sem);
329 mutex_unlock(&user->cons_lock); 332 mutex_unlock(&user->cons_lock);
330 *_key = key; 333 *_key = key;
331 kleave(" = 0 [%d]", key_serial(key)); 334 kleave(" = 0 [%d]", key_serial(key));