Lines Matching refs:the

6 user mappings, and similar to be cached in the kernel for the use of
17 This document has the following sections:
37 tokens, keyrings, etc.. These are represented in the kernel by struct key.
51 the lifetime of that key. All serial numbers are positive non-zero 32-bit
57 (*) Each key is of a defined "type". Types must be registered inside the
61 Key types are represented in the kernel by struct key_type. This defines a
64 Should a type be removed from the system, all the keys of that type will
68 type provides an operation to perform a match between the description on a
73 whether a kernel service will be able to find the key.
75 (*) Each key can be set to expire at a specific time by the key type's
78 (*) Each key can have a payload. This is a quantity of data that represent the
79 actual "key". In the case of a keyring, this is a list of keys to which
80 the keyring links; in the case of a user-defined key, it's an arbitrary
83 Having a payload is not required; and the payload can, in fact, just be a
84 value stored in the struct key itself.
86 When a key is instantiated, the key type's instantiation function is
87 called with a blob of data, and that then creates the key's payload in
90 Similarly, when userspace wants to read back the contents of the key, if
91 permitted, another key type operation will be called to convert the key's
99 (*) Instantiated. This is the normal state. The key is fully formed, and
114 (*) Dead. The key's type was unregistered, and so the key is now useless.
116 Keys in the last three states are subject to garbage collection. See the
144 accessible to the kernel but not to userspace programs.
147 length string that describes the key "subclass". The subclass is
148 separated from the rest of the description by a ':'. "logon" keys can
149 be created and updated from userspace, but the payload is only
155 The thread-specific keyring is discarded from the child when any sort of
159 The process-specific keyring is replaced with an empty one in the child on
161 shared. execve also discards the process's process keyring and creates a
165 execve, even when the latter executes a set-UID or set-GID binary. A
170 The ownership of the thread keyring changes when the real UID and GID of
171 the thread changes.
173 (*) Each user ID resident in the system holds two special keyrings: a user
175 keyring is initialised with a link to the user-specific keyring.
178 will be subscribed to the default session key for the new UID.
181 it will be subscribed to the default for its current UID.
183 (*) Each user has two quotas against which the keys they own are tracked. One
184 limits the total number of keys and keyrings, the other limits the total
188 files. The root user may also alter the quota limits through sysctl files
189 (see the section "New procfs files").
194 If a system call that modifies a key or keyring in some way would put the
195 user over quota, the operation is refused and error EDQUOT is returned.
203 (*) There's a way for the a search done from the kernel to call back to
206 (*) An optional filesystem is available through which the key database can be
241 keyring to a key, a process must have Write permission on the keyring and
242 Link permission on the key.
248 For changing the ownership, group ID or permissions mask, being the owner of
249 the key or having the sysadmin capability is sufficient.
258 is preliminary, and is likely to change quite significantly in the near future.
259 Currently, all of the basic permissions explained above are provided in SELinux
263 The value of the file /proc/self/attr/keycreate influences the labeling of
264 newly-created keys. If the contents of that file correspond to an SELinux
265 security context, then the key will be assigned that context. Otherwise, the
266 key will be assigned the current context of the task that invoked the key
268 particular context to newly-created keys, using the "create" permission in the
271 The default keyrings associated with users will be labeled with the default
272 context of the user if and only if the login programs have been instrumented to
273 properly initialize keycreate during the login process. Otherwise, they will
274 be labeled with the context of the login program itself.
276 Note, however, that the default keyrings associated with the root user are
277 labeled with the default kernel context, since they are created early in the
280 The keyrings associated with new threads are each labeled with the context of
290 about the status of the key service:
294 This lists the keys that are currently viewable by the task reading the
296 It is not possible to view the payload of the key this way, though some
299 The only keys included in the list are those that grant View permission to
300 the reading process whether or not it possesses them. Note that LSM
302 the current process is not authorised to view.
304 The contents of the file look like this:
329 This file lists the tracking data for each user that has at least one key
330 on the system. Such data includes quota information and statistics:
346 Four new sysctl files have been added also for the purpose of controlling the
352 These files hold the maximum number of keys that root may have and the
359 These files hold the maximum number of keys that each non-root user may
360 have and the maximum total number of bytes of data that each of those
364 the appropriate file.
375 When referring to a key directly, userspace programs should use the key's
377 values available for referring to special keys and keyrings that relate to the
378 process making the call:
394 (*) Create a new key of given type, description and payload and add it to the
401 If a key of the same type and description as that proposed already exists
402 in the keyring, this will try to update it with the given payload, or it
403 will return error EEXIST if that function is not supported by the key
404 type. The process must also have permission to write to the key to be able
408 Otherwise, this will attempt to create a new key of the specified type and
409 description, and to instantiate it with the supplied payload and attach it
410 to the keyring. In this case, an error will be generated if the process
411 does not have permission to write to the keyring.
413 If the key type supports it, if the description is NULL or an empty
414 string, the key type will try and generate a description from the content
415 of the payload.
417 The payload is optional, and the pointer can be NULL if not required by
418 the type. The payload is plen in size, and plen can be zero for an empty
421 A new keyring can be generated by setting type "keyring", the keyring name
422 as the description (or NULL) and setting the payload to NULL.
429 Any other type must have been registered with the kernel in advance by a
432 The ID of the new or updated key is returned if successful.
435 (*) Search the process's keyrings for a key, potentially calling out to
442 This function searches all the process's keyrings in the order thread,
444 KEYCTL_SEARCH, including the optional attachment of the discovered key to
449 callout_info string will be passed as an argument to the program.
461 The special key specified by "id" is looked up (with the key being created
462 if necessary) and the ID of the key or keyring thus found is returned if
465 If the key does not yet exist, the key will be created if "create" is
466 non-zero; and the error ENOKEY will be returned if "create" is zero.
469 (*) Replace the session keyring this process subscribes to with a new one:
473 If name is NULL, an anonymous keyring is created attached to the process
474 as its session keyring, displacing the old session keyring.
476 If name is not NULL, if a keyring of that name exists, the process
477 attempts to attach it as the session keyring, returning an error if that
479 attached as the session keyring.
481 To attach to a named keyring, the keyring must have search permission for
482 the process's ownership.
484 The ID of the new session keyring is returned if successful.
487 (*) Update the specified key:
492 This will try to update the specified key with the given payload, or it
493 will return error EOPNOTSUPP if that function is not supported by the key
494 type. The process must also have permission to write to the key to be able
506 use the key will be met with error EKEYREVOKED, and the key will no longer
510 (*) Change the ownership of a key:
517 Only the superuser can change a key's owner to something other than the
518 key's current owner. Similarly, only the superuser can change a key's
519 group ID to something other than the calling process's group ID or one of
523 (*) Change the permissions mask on a key:
527 This function permits the owner of a key or the superuser to change the
530 Only bits the available bits are permitted; if any other bits are set,
539 This function returns a summary of the key's attributes (but not its
540 payload data) as a string in the buffer provided.
542 Unless there's an error, it always returns the amount of data it could
543 produce, even if that's too big for the buffer, but it won't copy more
544 than requested to userspace. If the buffer pointer is NULL then no copy
547 A process must have view permission on the key for this function to be
550 If successful, a string is placed in the buffer in the following format:
555 is hexadecimal. A NUL character is included at the end of the string if
556 the buffer is sufficiently big.
567 This function clears the list of keys attached to a keyring. The calling
568 process must have write permission on the keyring, and it must be a
572 are appropriately marked if the user has CAP_SYS_ADMIN capability. The
580 This function creates a link from the keyring to the key. The process must
581 have write permission on the keyring and must have link permission on the
584 Should the keyring not be a keyring, error ENOTDIR will result; and if the
587 The link procedure checks the nesting of the keyrings, returning ELOOP if
588 it appears too deep or EDEADLK if the link would introduce a cycle.
590 Any links within the keyring to keys that match the new key in terms of
591 type and description will be discarded from the keyring as the new one is
599 This function looks through the keyring for the first link to the
601 ignored. The process must have write permission on the keyring.
603 If the keyring is not a keyring, error ENOTDIR will result; and if the key
604 is not present, error ENOENT will be the result.
613 This searches the keyring tree headed by the specified keyring until a key
614 is found that matches the type and description criteria. Each keyring is
617 The process must have search permission on the top level keyring, or else
618 error EACCES will result. Only keyrings that the process has search
620 a process has search permission can be matched. If the specified keyring
623 If the search succeeds, the function will attempt to link the found key
624 into the destination keyring if one is supplied (non-zero ID). All the
627 Error ENOKEY, EKEYREVOKED or EKEYEXPIRED will be returned if the search
628 fails. On success, the resulting key ID will be returned.
631 (*) Read the payload data from a key:
636 This function attempts to read the payload data from the specified key
637 into the buffer. The process must have read permission on the key to
640 The returned data will be processed for presentation by the key type. For
642 representing the IDs of all the keys to which it is subscribed. The user
646 As much of the data as can be fitted into the buffer will be copied to
647 userspace if the buffer pointer is not NULL.
649 On a successful return, the function will always return the amount of data
650 available rather than the amount copied.
662 If the kernel calls back to userspace to complete the instantiation of a
663 key, userspace should use this call to supply data for the key before the
664 invoked process returns, or else the key will be marked negative
667 The process must have write access on the key to be able to instantiate
668 it, and the key must be uninstantiated.
670 If a keyring is specified (non-zero), the key will also be linked into
671 that keyring, however all the constraints applying in KEYCTL_LINK apply in
674 The payload and plen arguments describe the payload data as for add_key().
676 The payload_iov and ioc arguments describe the payload data in an iovec
687 If the kernel calls back to userspace to complete the instantiation of a
688 key, userspace should use this call mark the key as negative before the
689 invoked process returns if it is unable to fulfill the request.
691 The process must have write access on the key to be able to instantiate
692 it, and the key must be uninstantiated.
694 If a keyring is specified (non-zero), the key will also be linked into
695 that keyring, however all the constraints applying in KEYCTL_LINK apply in
698 If the key is rejected, future searches for it will return the specified
699 error code until the rejected key expires. Negating the key is the same
700 as rejecting the key with ENOKEY as the error code.
703 (*) Set the default request-key destination keyring.
707 This sets the default keyring to which implicitly requested keys will be
722 returned if reqkey_defl is not one of the above values.
724 The default keyring can be overridden by the keyring indicated to the
729 [1] The default is: the thread keyring if there is one, otherwise
730 the process keyring if there is one, otherwise the session keyring if
731 there is one, otherwise the user default session keyring.
734 (*) Set the timeout on a key.
738 This sets or clears the timeout on a key. The timeout can be 0 to clear
739 the timeout or a number of seconds to set the expiry time that far into
740 the future.
747 (*) Assume the authority granted to instantiate a key
751 This assumes or divests the authority required to instantiate the
752 specified key. Authority can only be assumed if the thread has the
753 authorisation key associated with the specified key in its keyrings
756 Once authority is assumed, searches for keys will also search the
757 requester's keyrings using the requester's security label, UID, GID and
760 If the requested authority is unavailable, error EPERM will be returned,
761 likewise if the authority has been revoked because the target key is
764 If the specified key is 0, then any assumed authority will be divested.
769 (*) Get the LSM security context attached to a key.
774 This function returns a string that represents the LSM security context
775 attached to a key in the buffer provided.
777 Unless there's an error, it always returns the amount of data it could
778 produce, even if that's too big for the buffer, but it won't copy more
779 than requested to userspace. If the buffer pointer is NULL then no copy
782 A NUL character is included at the end of the string if the buffer is
783 sufficiently big. This is included in the returned count. If no LSM is
786 A process must have view permission on the key for this function to be
790 (*) Install the calling process's session keyring on its parent.
794 This functions attempts to install the calling process's session keyring
795 on to the calling process's parent, replacing the parent's current session
798 The calling process must have the same ownership as its parent, the
799 keyring must have the same ownership as the calling process, the calling
800 process must have LINK permission on the keyring and the active LSM module
804 the operation, otherwise 0 will be returned to indicate success.
806 The keyring will be replaced next time the parent process leaves the
814 This function marks a key as being invalidated and then wakes up the
816 keys from all keyrings and deletes the key when its reference count
823 A process must have search permission on the key for this function to be
834 Dealing with keys is fairly straightforward. Firstly, the kernel service
836 the key as long as it has need of it, and then it should release it. For a
837 filesystem or device file, a search would probably be performed during the open
838 call, and the key released upon close. How to deal with conflicting keys due to
839 two different users opening the same file is left to the filesystem author to
842 To access the key manager, the following header must be #included:
856 This simply points to the key structure itself. Key structures will be at
861 This is equivalent to a struct key *, but the least significant bit is set
862 if the caller "possesses" the key. By "possession" it is meant that the
863 calling processes has a searchable link to the key from one of its
875 The second function retrieves the key pointer from a reference and the
876 third retrieves the possession flag.
879 prevent access vs modification races. See the section "Notes on accessing
889 the description specified according to the key type's match_preparse()
892 the key from userspace. In that case, callout_string will be passed as an
893 argument to the program.
895 Should the function fail error ENOKEY, EKEYEXPIRED or EKEYREVOKED will be
898 If successful, the key will have been attached to the default keyring for
904 (*) To search for a key, passing auxiliary data to the upcaller, call:
912 This is identical to request_key(), except that the auxiliary data is
913 passed to the key_type->request_key() op if it exists, and the callout_info
914 is a blob of length callout_len, if given (the length may be 0).
935 These two functions return with the key potentially still under
936 construction. To wait for construction completion, the following should be
941 The function will wait for the key to finish being constructed and then
942 invokes key_validate() to return an appropriate value to indicate the state
943 of the key (0 indicates the key is usable).
945 If intr is true, then the wait can be interrupted by a signal, in which
949 (*) When it is no longer required, the key should be released using:
958 the argument will not be parsed.
961 (*) Extra references can be made to a key by calling one of the following
970 In the case of key_get(), if the pointer is NULL or CONFIG_KEYS is not set
971 then the key will not be dereferenced and no increment will take place.
978 If key is NULL or if CONFIG_KEYS is not set then 0 will be returned (in the
979 latter case without parsing the argument).
982 (*) If a keyring was found in the search, this can be further searched by:
988 This searches the keyring tree specified for a matching key. Error ENOKEY
990 the returned key will need to be released.
992 The possession attribute from the keyring reference is used to control
993 access through the permissions mask and is propagated to the returned key
1005 This creates a keyring with the given attributes and returns it. If dest
1006 is not NULL, the new keyring will be linked into the keyring to which it
1007 points. No permission checks are made upon the destination keyring.
1009 Error EDQUOT can be returned if the keyring would overload the quota (pass
1010 KEY_ALLOC_NOT_IN_QUOTA in flags if the keyring shouldn't be accounted
1011 towards the user's quota). Error ENOMEM can also be returned.
1014 (*) To check the validity of a key, this function can be called:
1018 This checks that the key in question hasn't expired or and hasn't been
1019 revoked. Should the key be invalid, error EKEYEXPIRED or EKEYREVOKED will
1020 be returned. If the key is NULL or if CONFIG_KEYS is not set then 0 will be
1021 returned (in the latter case without parsing the argument).
1024 (*) To register a key type, the following function should be called:
1028 This will return error EEXIST if a type of the same name is already
1038 The facility provides access to the keyring type for managing such a bundle:
1053 case, there's no need to indulge in RCU or locking when accessing the payload.
1055 More complex payload contents must be allocated and pointers to them set in the
1056 key->payload.data[] array. One of the following ways must be selected to
1057 access the data:
1061 If the key type does not have a modify method, then the key's payload can
1067 The semaphore could be used to govern access to the payload and to control
1068 the payload pointer. It must be write-locked for modifications and would
1070 is that the accessor may be required to sleep.
1074 RCU must be used when the semaphore isn't already held; if the semaphore
1075 is held then the contents can't change under you unexpectedly as the
1076 semaphore must still be used to serialise modifications to the key. The
1077 key management code takes care of this for the key type.
1083 to read the pointer, and:
1087 to set the pointer and dispose of the old contents after a grace period.
1088 Note that only the key type should ever modify a key's payload.
1090 Furthermore, an RCU controlled payload must hold a struct rcu_head for the
1091 use of call_rcu() and, if the payload is of variable size, the length of
1092 the payload. key->datalen cannot be relied upon to be consistent with the
1093 payload just dereferenced if the key's semaphore is not held.
1097 wrap the RCU calls to this element:
1109 author fills in a key_type struct and registers it with the system.
1111 Source files that implement key types should include the following header file:
1119 The name of the key type. This is used to translate a key type name
1120 supplied by userspace into a pointer to the structure.
1125 This is optional - it supplies the default payload data length as
1126 contributed to the quota. If the key type's payload is always or almost
1127 always the same size, then this is a more efficient way to do things.
1134 With the revised data length. Error EDQUOT will be returned if this is not
1140 This optional method is called to vet a key description. If the key type
1141 doesn't approve of the key description, it may return an error, otherwise
1147 This optional method permits the key type to attempt to parse payload
1148 before a key is created (add key) or the key semaphore is taken (update or
1160 Before calling the method, the caller will fill in data and datalen with
1161 the payload blob parameters; quotalen will be filled in with the default
1162 quota size from the key type; expiry will be set to TIME_T_MAX and the
1165 If a description can be proposed from the payload contents, that should be
1166 attached as a string to the description field. This will be used for the
1167 key description if the caller of add_key() passes NULL or "".
1170 along to the instantiate() or update() operations. If set, the expiry
1171 time will be applied to the key if it is instantiated from this data.
1179 This method is only required if the preparse() method is provided,
1180 otherwise it is unused. It cleans up anything attached to the description
1181 and payload fields of the key_preparsed_payload struct as filled in by the
1189 The payload attached need not bear any relation to the data passed to this
1192 The prep->data and prep->datalen fields will define the original payload
1195 If the amount of data attached to the key differs from the size in
1198 This method does not have to lock the key in order to attach a payload.
1200 anything else from gaining access to the key.
1204 generic_key_instantiate() is provided to simply copy the data from
1206 the first element. It will then clear prep->payload.data[] so that the
1207 free_preparse method doesn't release the data.
1213 It is called to update a key's payload from the blob of data provided.
1215 The prep->data and prep->datalen fields will define the original payload
1218 key_payload_reserve() should be called if the data length might change
1219 before any changes are actually made. Note that if this succeeds, the type
1220 is committed to changing the key because it's already been altered, so all
1224 but this only deters other writers; any changes to the key's payload must
1226 the old payload.
1228 key_payload_reserve() should be called before the changes are made, but
1238 performed. It is given the following structure:
1248 On entry, raw_data will be pointing to the criteria to be used in matching
1249 a key by the caller and should not be modified. (*cmp)() will be pointing
1250 to the default matcher function (which does an exact description match
1255 [*] KEYRING_SEARCH_LOOKUP_DIRECT - A direct lookup hashes the type and
1256 description to narrow down the search to a small number of keys.
1258 [*] KEYRING_SEARCH_LOOKUP_ITERATE - An iterative lookup walks all the
1259 keys in the keyring until one is matched. This must be used for any
1260 search that's not doing a simple direct match on the key description.
1264 and may attach something to the preparsed pointer for use by (*cmp)().
1267 If preparsed is set, it may be necessary to use the match_free() method to
1288 This method is optional. It is called to discard part of the payload
1289 data upon a key being revoked. The caller will have the key semaphore
1293 a deadlock against the key semaphore.
1298 This method is optional. It is called to discard the payload data on a key
1301 This method does not need to lock the key to access the payload; it can
1302 consider the key as being inaccessible at this time. Note that the key's
1305 It is not safe to sleep in this method; the caller may hold spinlocks.
1313 This method will be called with the RCU read lock held. rcu_dereference()
1314 should be used to read the payload pointer if the payload is to be
1315 accessed. key->datalen cannot be trusted to stay consistent with the
1316 contents of the payload.
1318 The description will not change, though the key's state may.
1320 It is not safe to sleep in this method; the RCU read lock is held by the
1326 This method is optional. It is called by KEYCTL_READ to translate the
1328 Ideally, the blob should be in the same format as that passed in to the
1331 If successful, the blob size that could be produced should be returned
1332 rather than the size copied.
1334 This method will be called with the key's semaphore read-locked. This will
1335 prevent the key's payload changing. It is not necessary to use RCU locking
1336 when accessing the key's payload. It is safe to sleep in this method, such
1337 as might happen when the userspace buffer is accessed.
1348 similar or is NULL otherwise. Also passed are the construction record for
1349 the key to be operated upon and the operation type (currently only
1352 This method is permitted to return before the upcall is complete, but the
1353 following function must be called under all circumstances to complete the
1360 construction record is destroyed by this action and the authorisation key
1361 will be revoked. If an error is indicated, the key under construction
1364 If this method returns an error, that error will be returned to the
1368 The key under construction and the authorisation key can be found in the
1384 To create a new key, the kernel will attempt to execute the following command
1390 <key> is the key being constructed, and the three keyrings are the process
1391 keyrings from the process that caused the search to be issued. These are
1394 (1) There may be an authentication token in one of the keyrings that is
1395 required to obtain the key, eg: a Kerberos Ticket-Granting Ticket.
1401 hand the request off to (perhaps a path held in placed in another key by, for
1402 example, the KDE desktop manager).
1404 The program (or whatever it calls) should finish construction of the key by
1406 cache the key in one of the keyrings (probably the session ring) before
1407 returning. Alternatively, the key can be marked as negative with KEYCTL_NEGATE
1408 or KEYCTL_REJECT; this also permits the key to be cached in one of the
1411 If it returns with the key remaining in the unconstructed state, the key will
1412 be marked as being negative, it will be added to the session keyring, and an
1413 error will be returned to the key requestor.
1416 service. This will be passed as the <callout_info> parameter. If no such
1421 Similarly, the kernel may attempt to update an expired or a soon to expire key
1427 In this case, the program isn't required to actually attach the key to a ring;
1428 the rings are provided for reference.
1435 Dead keys (for which the type has been removed) will be automatically unlinked