Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:security\keys\request_key.c Create Date:2022-07-28 18:23:36
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:Allocate a new key in under-construction state and attempt to link it in to* the requested keyring.* May return a key that's already under construction instead if there was a* race between two thread calling request_key().

Proto:static int construct_alloc_key(struct keyring_search_context *ctx, struct key *dest_keyring, unsigned long flags, struct key_user *user, struct key **_key)

Type:int

Parameter:

TypeParameterName
struct keyring_search_context *ctx
struct key *dest_keyring
unsigned longflags
struct key_user *user
struct key **_key
372  struct assoc_array_edit * edit = NULL
378  kenter("%s,%s,,,", name, description)
381  * _key = NULL
382  mutex_lock( & construction initiation lock )
384  perm = possessor can view a key's attributes | possessor can find a key in search / search a keyring | possessor can create a link to a key/keyring | possessor can set key attributes
385  perm |= user permissions...
386  If read Then perm |= possessor can read key payload / view keyring
388  If type == key_type_keyring || update Then perm |= possessor can update key payload / add link to keyring
392  key = key_alloc - Allocate a key of the specified type.*@type: The type of key to allocate.*@desc: The key description to allow the key to be searched out.*@uid: The owner of the new key.*@gid: The group ID for the new key's group permissions.
395  If IS_ERR(key) Then Go to alloc_failed
398  Atomically set a bit in memory
400  If dest_keyring Then
401  ret = Lock keyring for link.
402  If ret < 0 Then Go to link_lock_failed
404  ret = Preallocate memory so that a key can be linked into to a keyring.
405  If ret < 0 Then Go to link_prealloc_failed
412  mutex_lock( & We serialise key instantiation and link )
414  _read_lock() - mark the beginning of an RCU read-side critical section* When synchronize_rcu() is invoked on one CPU while other CPUs* are within RCU read-side critical sections, then the* synchronize_rcu() is guaranteed to block until after all the other
415  key_ref = Search the process keyrings attached to the supplied cred for the first* matching key in the manner of search_my_process_keyrings(), but also search* the keys attached to the assumed authorisation key using its credentials if* one is available.
416  _read_unlock() - marks the end of an RCU read-side critical section.* In most situations, rcu_read_unlock() is immune from deadlock.* However, in kernels built with CONFIG_RCU_BOOST, rcu_read_unlock()
417  If Not IS_ERR(key_ref) Then Go to key_already_present
420  If dest_keyring Then Link a key into to a keyring.* Must be called with __key_link_begin() having being called. Discards any* already extant link to matching key if there is one, so that each keyring* holds at most one link to any given key of a particular type+description
423  mutex_unlock - release the mutex*@lock: the mutex to be released* Unlock a mutex that has been locked by this task previously.* This function must not be used in interrupt context. Unlocking* of a not locked mutex is not allowed.
424  If dest_keyring Then Finish linking a key into to a keyring.* Must be called with __key_link_begin() having being called.
426  mutex_unlock - release the mutex*@lock: the mutex to be released* Unlock a mutex that has been locked by this task previously.* This function must not be used in interrupt context. Unlocking* of a not locked mutex is not allowed.
427  _key = key
428  kleave(" = 0 [%d]", key_serial(key))
429  Return 0
433  key_already_present :
434  key_put - Discard a reference to a key.*@key: The key to discard a reference from.* Discard a reference to a key, and when all the references are gone, we* schedule the cleanup task to come and pull it out of the tree in process
435  mutex_unlock - release the mutex*@lock: the mutex to be released* Unlock a mutex that has been locked by this task previously.* This function must not be used in interrupt context. Unlocking* of a not locked mutex is not allowed.
436  key = key_ref_to_ptr(key_ref)
437  If dest_keyring Then
438  ret = Check already instantiated keys aren't going to be a problem.* The caller must have called __key_link_begin(). Don't need to call this for* keys that were created since __key_link_begin() was called.
439  If ret == 0 Then Link a key into to a keyring.* Must be called with __key_link_begin() having being called. Discards any* already extant link to matching key if there is one, so that each keyring* holds at most one link to any given key of a particular type+description
441  Finish linking a key into to a keyring.* Must be called with __key_link_begin() having being called.
442  If ret < 0 Then Go to link_check_failed
445  mutex_unlock - release the mutex*@lock: the mutex to be released* Unlock a mutex that has been locked by this task previously.* This function must not be used in interrupt context. Unlocking* of a not locked mutex is not allowed.
446  _key = key
447  kleave(" = -EINPROGRESS [%d]", key_serial(key))
448  Return -EINPROGRESS
450  link_check_failed :
451  mutex_unlock - release the mutex*@lock: the mutex to be released* Unlock a mutex that has been locked by this task previously.* This function must not be used in interrupt context. Unlocking* of a not locked mutex is not allowed.
452  key_put - Discard a reference to a key.*@key: The key to discard a reference from.* Discard a reference to a key, and when all the references are gone, we* schedule the cleanup task to come and pull it out of the tree in process
453  kleave(" = %d [linkcheck]", ret)
454  Return ret
456  link_prealloc_failed :
457  Finish linking a key into to a keyring.* Must be called with __key_link_begin() having being called.
458  link_lock_failed :
459  mutex_unlock - release the mutex*@lock: the mutex to be released* Unlock a mutex that has been locked by this task previously.* This function must not be used in interrupt context. Unlocking* of a not locked mutex is not allowed.
460  key_put - Discard a reference to a key.*@key: The key to discard a reference from.* Discard a reference to a key, and when all the references are gone, we* schedule the cleanup task to come and pull it out of the tree in process
461  kleave(" = %d [prelink]", ret)
462  Return ret
464  alloc_failed :
465  mutex_unlock - release the mutex*@lock: the mutex to be released* Unlock a mutex that has been locked by this task previously.* This function must not be used in interrupt context. Unlocking* of a not locked mutex is not allowed.
466  kleave(" = %ld", PTR_ERR(key))
467  Return PTR_ERR(key)
Caller
NameDescribe
construct_key_and_linkCommence key construction.