sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget(/translations/zh_CN/security/credentialsmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/zh_TW/security/credentialsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/it_IT/security/credentialsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/ja_JP/security/credentialsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/ko_KR/security/credentialsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/sp_SP/security/credentialsmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhsection)}(hhh](htitle)}(hCredentials in Linuxh]hCredentials in Linux}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhB/var/lib/git/docbuild/linux/Documentation/security/credentials.rsthKubh paragraph)}(h'By: David Howells h](hBy: David Howells <}(hhhhhNhNubh reference)}(hdhowells@redhat.comh]hdhowells@redhat.com}(hhhhhNhNubah}(h]h ]h"]h$]h&]refurimailto:dhowells@redhat.comuh1hhhubh>}(hhhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubhtopic)}(hhh]h bullet_list)}(hhh](h list_item)}(hhh]h)}(hhh]h)}(hhh]hOverview}(hhhhhNhNubah}(h]id1ah ]h"]h$]h&]refidoverviewuh1hhhubah}(h]h ]h"]h$]h&]uh1hhhubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]hTypes of Credentials}(hjhhhNhNubah}(h]id2ah ]h"]h$]h&]refidtypes-of-credentialsuh1hhjubah}(h]h ]h"]h$]h&]uh1hhj ubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]h File Markings}(hj3hhhNhNubah}(h]id3ah ]h"]h$]h&]refid file-markingsuh1hhj0ubah}(h]h ]h"]h$]h&]uh1hhj-ubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh](h)}(hhh]h)}(hhh]hTask Credentials}(hjUhhhNhNubah}(h]id4ah ]h"]h$]h&]refidtask-credentialsuh1hhjRubah}(h]h ]h"]h$]h&]uh1hhjOubh)}(hhh](h)}(hhh]h)}(hhh]h)}(hhh]hImmutable Credentials}(hjthhhNhNubah}(h]id5ah ]h"]h$]h&]refidimmutable-credentialsuh1hhjqubah}(h]h ]h"]h$]h&]uh1hhjnubah}(h]h ]h"]h$]h&]uh1hhjkubh)}(hhh]h)}(hhh]h)}(hhh]hAccessing Task Credentials}(hjhhhNhNubah}(h]id6ah ]h"]h$]h&]refidaccessing-task-credentialsuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhjkubh)}(hhh]h)}(hhh]h)}(hhh]h&Accessing Another Task’s Credentials}(hjhhhNhNubah}(h]id7ah ]h"]h$]h&]refid$accessing-another-task-s-credentialsuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhjkubh)}(hhh]h)}(hhh]h)}(hhh]hAltering Credentials}(hjhhhNhNubah}(h]id8ah ]h"]h$]h&]refidaltering-credentialsuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhjkubh)}(hhh]h)}(hhh]h)}(hhh]hManaging Credentials}(hjhhhNhNubah}(h]id9ah ]h"]h$]h&]refidmanaging-credentialsuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhjkubeh}(h]h ]h"]h$]h&]uh1hhjOubeh}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]hOpen File Credentials}(hj*hhhNhNubah}(h]id10ah ]h"]h$]h&]refidopen-file-credentialsuh1hhj'ubah}(h]h ]h"]h$]h&]uh1hhj$ubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]h)Overriding the VFS’s Use of Credentials}(hjLhhhNhNubah}(h]id11ah ]h"]h$]h&]refid'overriding-the-vfs-s-use-of-credentialsuh1hhjIubah}(h]h ]h"]h$]h&]uh1hhjFubah}(h]h ]h"]h$]h&]uh1hhhubeh}(h]h ]h"]h$]h&]uh1hhhhhhNhNubah}(h]contentsah ](contentslocaleh"]contentsah$]h&]uh1hhhhKhhhhubh)}(hhh](h)}(hOverviewh]hOverview}(hj{hhhNhNubah}(h]h ]h"]h$]h&]refidhuh1hhjxhhhhhK ubh)}(hcThere are several parts to the security check performed by Linux when one object acts upon another:h]hcThere are several parts to the security check performed by Linux when one object acts upon another:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hjxhhubh block_quote)}(hXS1. Objects. Objects are things in the system that may be acted upon directly by userspace programs. Linux has a variety of actionable objects, including: - Tasks - Files/inodes - Sockets - Message queues - Shared memory segments - Semaphores - Keys As a part of the description of all these objects there is a set of credentials. What's in the set depends on the type of object. 2. Object ownership. Amongst the credentials of most objects, there will be a subset that indicates the ownership of that object. This is used for resource accounting and limitation (disk quotas and task rlimits for example). In a standard UNIX filesystem, for instance, this will be defined by the UID marked on the inode. 3. The objective context. Also amongst the credentials of those objects, there will be a subset that indicates the 'objective context' of that object. This may or may not be the same set as in (2) - in standard UNIX files, for instance, this is the defined by the UID and the GID marked on the inode. The objective context is used as part of the security calculation that is carried out when an object is acted upon. 4. Subjects. A subject is an object that is acting upon another object. Most of the objects in the system are inactive: they don't act on other objects within the system. Processes/tasks are the obvious exception: they do stuff; they access and manipulate things. Objects other than tasks may under some circumstances also be subjects. For instance an open file may send SIGIO to a task using the UID and EUID given to it by a task that called ``fcntl(F_SETOWN)`` upon it. In this case, the file struct will have a subjective context too. 5. The subjective context. A subject has an additional interpretation of its credentials. A subset of its credentials forms the 'subjective context'. The subjective context is used as part of the security calculation that is carried out when a subject acts. A Linux task, for example, has the FSUID, FSGID and the supplementary group list for when it is acting upon a file - which are quite separate from the real UID and GID that normally form the objective context of the task. 6. Actions. Linux has a number of actions available that a subject may perform upon an object. The set of actions available depends on the nature of the subject and the object. Actions include reading, writing, creating and deleting files; forking or signalling and tracing tasks. 7. Rules, access control lists and security calculations. When a subject acts upon an object, a security calculation is made. This involves taking the subjective context, the objective context and the action, and searching one or more sets of rules to see whether the subject is granted or denied permission to act in the desired manner on the object, given those contexts. There are two main sources of rules: a. Discretionary access control (DAC): Sometimes the object will include sets of rules as part of its description. This is an 'Access Control List' or 'ACL'. A Linux file may supply more than one ACL. A traditional UNIX file, for example, includes a permissions mask that is an abbreviated ACL with three fixed classes of subject ('user', 'group' and 'other'), each of which may be granted certain privileges ('read', 'write' and 'execute' - whatever those map to for the object in question). UNIX file permissions do not allow the arbitrary specification of subjects, however, and so are of limited use. A Linux file might also sport a POSIX ACL. This is a list of rules that grants various permissions to arbitrary subjects. b. Mandatory access control (MAC): The system as a whole may have one or more sets of rules that get applied to all subjects and objects, regardless of their source. SELinux and Smack are examples of this. In the case of SELinux and Smack, each object is given a label as part of its credentials. When an action is requested, they take the subject label, the object label and the action and look for a rule that says that this action is either granted or denied. h]henumerated_list)}(hhh](h)}(hXObjects. Objects are things in the system that may be acted upon directly by userspace programs. Linux has a variety of actionable objects, including: - Tasks - Files/inodes - Sockets - Message queues - Shared memory segments - Semaphores - Keys As a part of the description of all these objects there is a set of credentials. What's in the set depends on the type of object. h](h)}(hObjects.h]hObjects.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubj)}(hXObjects are things in the system that may be acted upon directly by userspace programs. Linux has a variety of actionable objects, including: - Tasks - Files/inodes - Sockets - Message queues - Shared memory segments - Semaphores - Keys As a part of the description of all these objects there is a set of credentials. What's in the set depends on the type of object. h](h)}(hObjects are things in the system that may be acted upon directly by userspace programs. Linux has a variety of actionable objects, including:h]hObjects are things in the system that may be acted upon directly by userspace programs. Linux has a variety of actionable objects, including:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubj)}(h_- Tasks - Files/inodes - Sockets - Message queues - Shared memory segments - Semaphores - Keys h]h)}(hhh](h)}(hTasksh]h)}(hjh]hTasks}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjubh)}(h Files/inodesh]h)}(hjh]h Files/inodes}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hSocketsh]h)}(hjh]hSockets}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hMessage queuesh]h)}(hjh]hMessage queues}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hShared memory segmentsh]h)}(hj,h]hShared memory segments}(hj.hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj*ubah}(h]h ]h"]h$]h&]uh1hhjubh)}(h Semaphoresh]h)}(hjCh]h Semaphores}(hjEhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjAubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hKeys h]h)}(hKeysh]hKeys}(hj\hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjXubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]bullet-uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhhhKhjubh)}(hAs a part of the description of all these objects there is a set of credentials. What's in the set depends on the type of object.h]hAs a part of the description of all these objects there is a set of credentials. What’s in the set depends on the type of object.}(hj~hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubeh}(h]h ]h"]h$]h&]uh1jhhhKhjubeh}(h]h ]h"]h$]h&]uh1hhjubh)}(hXIObject ownership. Amongst the credentials of most objects, there will be a subset that indicates the ownership of that object. This is used for resource accounting and limitation (disk quotas and task rlimits for example). In a standard UNIX filesystem, for instance, this will be defined by the UID marked on the inode. h](h)}(hObject ownership.h]hObject ownership.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubj)}(hX1Amongst the credentials of most objects, there will be a subset that indicates the ownership of that object. This is used for resource accounting and limitation (disk quotas and task rlimits for example). In a standard UNIX filesystem, for instance, this will be defined by the UID marked on the inode. h](h)}(hAmongst the credentials of most objects, there will be a subset that indicates the ownership of that object. This is used for resource accounting and limitation (disk quotas and task rlimits for example).h]hAmongst the credentials of most objects, there will be a subset that indicates the ownership of that object. This is used for resource accounting and limitation (disk quotas and task rlimits for example).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK!hjubh)}(haIn a standard UNIX filesystem, for instance, this will be defined by the UID marked on the inode.h]haIn a standard UNIX filesystem, for instance, this will be defined by the UID marked on the inode.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK%hjubeh}(h]h ]h"]h$]h&]uh1jhhhK!hjubeh}(h]h ]h"]h$]h&]uh1hhjubh)}(hXThe objective context. Also amongst the credentials of those objects, there will be a subset that indicates the 'objective context' of that object. This may or may not be the same set as in (2) - in standard UNIX files, for instance, this is the defined by the UID and the GID marked on the inode. The objective context is used as part of the security calculation that is carried out when an object is acted upon. h](h)}(hThe objective context.h]hThe objective context.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK(hjubj)}(hXAlso amongst the credentials of those objects, there will be a subset that indicates the 'objective context' of that object. This may or may not be the same set as in (2) - in standard UNIX files, for instance, this is the defined by the UID and the GID marked on the inode. The objective context is used as part of the security calculation that is carried out when an object is acted upon. h](h)}(hXAlso amongst the credentials of those objects, there will be a subset that indicates the 'objective context' of that object. This may or may not be the same set as in (2) - in standard UNIX files, for instance, this is the defined by the UID and the GID marked on the inode.h]hXAlso amongst the credentials of those objects, there will be a subset that indicates the ‘objective context’ of that object. This may or may not be the same set as in (2) - in standard UNIX files, for instance, this is the defined by the UID and the GID marked on the inode.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK*hjubh)}(hsThe objective context is used as part of the security calculation that is carried out when an object is acted upon.h]hsThe objective context is used as part of the security calculation that is carried out when an object is acted upon.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK/hjubeh}(h]h ]h"]h$]h&]uh1jhhhK*hjubeh}(h]h ]h"]h$]h&]uh1hhjubh)}(hX%Subjects. A subject is an object that is acting upon another object. Most of the objects in the system are inactive: they don't act on other objects within the system. Processes/tasks are the obvious exception: they do stuff; they access and manipulate things. Objects other than tasks may under some circumstances also be subjects. For instance an open file may send SIGIO to a task using the UID and EUID given to it by a task that called ``fcntl(F_SETOWN)`` upon it. In this case, the file struct will have a subjective context too. h](h)}(h Subjects.h]h Subjects.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK2hjubj)}(hXA subject is an object that is acting upon another object. Most of the objects in the system are inactive: they don't act on other objects within the system. Processes/tasks are the obvious exception: they do stuff; they access and manipulate things. Objects other than tasks may under some circumstances also be subjects. For instance an open file may send SIGIO to a task using the UID and EUID given to it by a task that called ``fcntl(F_SETOWN)`` upon it. In this case, the file struct will have a subjective context too. h](h)}(h:A subject is an object that is acting upon another object.h]h:A subject is an object that is acting upon another object.}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK4hj&ubh)}(hMost of the objects in the system are inactive: they don't act on other objects within the system. Processes/tasks are the obvious exception: they do stuff; they access and manipulate things.h]hMost of the objects in the system are inactive: they don’t act on other objects within the system. Processes/tasks are the obvious exception: they do stuff; they access and manipulate things.}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK6hj&ubh)}(hXObjects other than tasks may under some circumstances also be subjects. For instance an open file may send SIGIO to a task using the UID and EUID given to it by a task that called ``fcntl(F_SETOWN)`` upon it. In this case, the file struct will have a subjective context too.h](hObjects other than tasks may under some circumstances also be subjects. For instance an open file may send SIGIO to a task using the UID and EUID given to it by a task that called }(hjFhhhNhNubhliteral)}(h``fcntl(F_SETOWN)``h]hfcntl(F_SETOWN)}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjFubhL upon it. In this case, the file struct will have a subjective context too.}(hjFhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK:hj&ubeh}(h]h ]h"]h$]h&]uh1jhhhK4hjubeh}(h]h ]h"]h$]h&]uh1hhjubh)}(hXThe subjective context. A subject has an additional interpretation of its credentials. A subset of its credentials forms the 'subjective context'. The subjective context is used as part of the security calculation that is carried out when a subject acts. A Linux task, for example, has the FSUID, FSGID and the supplementary group list for when it is acting upon a file - which are quite separate from the real UID and GID that normally form the objective context of the task. h](h)}(hThe subjective context.h]hThe subjective context.}(hjxhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK?hjtubj)}(hXA subject has an additional interpretation of its credentials. A subset of its credentials forms the 'subjective context'. The subjective context is used as part of the security calculation that is carried out when a subject acts. A Linux task, for example, has the FSUID, FSGID and the supplementary group list for when it is acting upon a file - which are quite separate from the real UID and GID that normally form the objective context of the task. h](h)}(hA subject has an additional interpretation of its credentials. A subset of its credentials forms the 'subjective context'. The subjective context is used as part of the security calculation that is carried out when a subject acts.h]hA subject has an additional interpretation of its credentials. A subset of its credentials forms the ‘subjective context’. The subjective context is used as part of the security calculation that is carried out when a subject acts.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKAhjubh)}(hA Linux task, for example, has the FSUID, FSGID and the supplementary group list for when it is acting upon a file - which are quite separate from the real UID and GID that normally form the objective context of the task.h]hA Linux task, for example, has the FSUID, FSGID and the supplementary group list for when it is acting upon a file - which are quite separate from the real UID and GID that normally form the objective context of the task.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKFhjubeh}(h]h ]h"]h$]h&]uh1jhhhKAhjtubeh}(h]h ]h"]h$]h&]uh1hhjubh)}(hXActions. Linux has a number of actions available that a subject may perform upon an object. The set of actions available depends on the nature of the subject and the object. Actions include reading, writing, creating and deleting files; forking or signalling and tracing tasks. h](h)}(hActions.h]hActions.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKKhjubj)}(hXLinux has a number of actions available that a subject may perform upon an object. The set of actions available depends on the nature of the subject and the object. Actions include reading, writing, creating and deleting files; forking or signalling and tracing tasks. h](h)}(hLinux has a number of actions available that a subject may perform upon an object. The set of actions available depends on the nature of the subject and the object.h]hLinux has a number of actions available that a subject may perform upon an object. The set of actions available depends on the nature of the subject and the object.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKMhjubh)}(hgActions include reading, writing, creating and deleting files; forking or signalling and tracing tasks.h]hgActions include reading, writing, creating and deleting files; forking or signalling and tracing tasks.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKQhjubeh}(h]h ]h"]h$]h&]uh1jhhhKMhjubeh}(h]h ]h"]h$]h&]uh1hhjubh)}(hXRules, access control lists and security calculations. When a subject acts upon an object, a security calculation is made. This involves taking the subjective context, the objective context and the action, and searching one or more sets of rules to see whether the subject is granted or denied permission to act in the desired manner on the object, given those contexts. There are two main sources of rules: a. Discretionary access control (DAC): Sometimes the object will include sets of rules as part of its description. This is an 'Access Control List' or 'ACL'. A Linux file may supply more than one ACL. A traditional UNIX file, for example, includes a permissions mask that is an abbreviated ACL with three fixed classes of subject ('user', 'group' and 'other'), each of which may be granted certain privileges ('read', 'write' and 'execute' - whatever those map to for the object in question). UNIX file permissions do not allow the arbitrary specification of subjects, however, and so are of limited use. A Linux file might also sport a POSIX ACL. This is a list of rules that grants various permissions to arbitrary subjects. b. Mandatory access control (MAC): The system as a whole may have one or more sets of rules that get applied to all subjects and objects, regardless of their source. SELinux and Smack are examples of this. In the case of SELinux and Smack, each object is given a label as part of its credentials. When an action is requested, they take the subject label, the object label and the action and look for a rule that says that this action is either granted or denied. h](h)}(h6Rules, access control lists and security calculations.h]h6Rules, access control lists and security calculations.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKThjubj)}(hX^When a subject acts upon an object, a security calculation is made. This involves taking the subjective context, the objective context and the action, and searching one or more sets of rules to see whether the subject is granted or denied permission to act in the desired manner on the object, given those contexts. There are two main sources of rules: a. Discretionary access control (DAC): Sometimes the object will include sets of rules as part of its description. This is an 'Access Control List' or 'ACL'. A Linux file may supply more than one ACL. A traditional UNIX file, for example, includes a permissions mask that is an abbreviated ACL with three fixed classes of subject ('user', 'group' and 'other'), each of which may be granted certain privileges ('read', 'write' and 'execute' - whatever those map to for the object in question). UNIX file permissions do not allow the arbitrary specification of subjects, however, and so are of limited use. A Linux file might also sport a POSIX ACL. This is a list of rules that grants various permissions to arbitrary subjects. b. Mandatory access control (MAC): The system as a whole may have one or more sets of rules that get applied to all subjects and objects, regardless of their source. SELinux and Smack are examples of this. In the case of SELinux and Smack, each object is given a label as part of its credentials. When an action is requested, they take the subject label, the object label and the action and look for a rule that says that this action is either granted or denied. h](h)}(hX<When a subject acts upon an object, a security calculation is made. This involves taking the subjective context, the objective context and the action, and searching one or more sets of rules to see whether the subject is granted or denied permission to act in the desired manner on the object, given those contexts.h]hX<When a subject acts upon an object, a security calculation is made. This involves taking the subjective context, the objective context and the action, and searching one or more sets of rules to see whether the subject is granted or denied permission to act in the desired manner on the object, given those contexts.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKVhjubh)}(h$There are two main sources of rules:h]h$There are two main sources of rules:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK\hjubj)}(hhh](h)}(hXDiscretionary access control (DAC): Sometimes the object will include sets of rules as part of its description. This is an 'Access Control List' or 'ACL'. A Linux file may supply more than one ACL. A traditional UNIX file, for example, includes a permissions mask that is an abbreviated ACL with three fixed classes of subject ('user', 'group' and 'other'), each of which may be granted certain privileges ('read', 'write' and 'execute' - whatever those map to for the object in question). UNIX file permissions do not allow the arbitrary specification of subjects, however, and so are of limited use. A Linux file might also sport a POSIX ACL. This is a list of rules that grants various permissions to arbitrary subjects. h](h)}(h#Discretionary access control (DAC):h]h#Discretionary access control (DAC):}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK^hj%ubj)}(hXSometimes the object will include sets of rules as part of its description. This is an 'Access Control List' or 'ACL'. A Linux file may supply more than one ACL. A traditional UNIX file, for example, includes a permissions mask that is an abbreviated ACL with three fixed classes of subject ('user', 'group' and 'other'), each of which may be granted certain privileges ('read', 'write' and 'execute' - whatever those map to for the object in question). UNIX file permissions do not allow the arbitrary specification of subjects, however, and so are of limited use. A Linux file might also sport a POSIX ACL. This is a list of rules that grants various permissions to arbitrary subjects. h](h)}(hSometimes the object will include sets of rules as part of its description. This is an 'Access Control List' or 'ACL'. A Linux file may supply more than one ACL.h]hSometimes the object will include sets of rules as part of its description. This is an ‘Access Control List’ or ‘ACL’. A Linux file may supply more than one ACL.}(hj;hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK`hj7ubh)}(hXA traditional UNIX file, for example, includes a permissions mask that is an abbreviated ACL with three fixed classes of subject ('user', 'group' and 'other'), each of which may be granted certain privileges ('read', 'write' and 'execute' - whatever those map to for the object in question). UNIX file permissions do not allow the arbitrary specification of subjects, however, and so are of limited use.h]hXA traditional UNIX file, for example, includes a permissions mask that is an abbreviated ACL with three fixed classes of subject (‘user’, ‘group’ and ‘other’), each of which may be granted certain privileges (‘read’, ‘write’ and ‘execute’ - whatever those map to for the object in question). UNIX file permissions do not allow the arbitrary specification of subjects, however, and so are of limited use.}(hjIhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKdhj7ubh)}(hzA Linux file might also sport a POSIX ACL. This is a list of rules that grants various permissions to arbitrary subjects.h]hzA Linux file might also sport a POSIX ACL. This is a list of rules that grants various permissions to arbitrary subjects.}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKkhj7ubeh}(h]h ]h"]h$]h&]uh1jhhhK`hj%ubeh}(h]h ]h"]h$]h&]uh1hhj"ubh)}(hXMandatory access control (MAC): The system as a whole may have one or more sets of rules that get applied to all subjects and objects, regardless of their source. SELinux and Smack are examples of this. In the case of SELinux and Smack, each object is given a label as part of its credentials. When an action is requested, they take the subject label, the object label and the action and look for a rule that says that this action is either granted or denied. h](h)}(hMandatory access control (MAC):h]hMandatory access control (MAC):}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKnhjqubj)}(hXThe system as a whole may have one or more sets of rules that get applied to all subjects and objects, regardless of their source. SELinux and Smack are examples of this. In the case of SELinux and Smack, each object is given a label as part of its credentials. When an action is requested, they take the subject label, the object label and the action and look for a rule that says that this action is either granted or denied. h](h)}(hThe system as a whole may have one or more sets of rules that get applied to all subjects and objects, regardless of their source. SELinux and Smack are examples of this.h]hThe system as a whole may have one or more sets of rules that get applied to all subjects and objects, regardless of their source. SELinux and Smack are examples of this.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKphjubh)}(hXIn the case of SELinux and Smack, each object is given a label as part of its credentials. When an action is requested, they take the subject label, the object label and the action and look for a rule that says that this action is either granted or denied.h]hXIn the case of SELinux and Smack, each object is given a label as part of its credentials. When an action is requested, they take the subject label, the object label and the action and look for a rule that says that this action is either granted or denied.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKthjubeh}(h]h ]h"]h$]h&]uh1jhhhKphjqubeh}(h]h ]h"]h$]h&]uh1hhj"ubeh}(h]h ]h"]h$]h&]enumtype loweralphaprefixhsuffix.uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhKVhjubeh}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]jarabicjhjjuh1jhjubah}(h]h ]h"]h$]h&]uh1jhhhKhjxhhubeh}(h]hah ]h"]overviewah$]h&]uh1hhhhhhhhK ubh)}(hhh](h)}(hTypes of Credentialsh]hTypes of Credentials}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjhhhhhK{ubh)}(h=The Linux kernel supports the following types of credentials:h]h=The Linux kernel supports the following types of credentials:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK}hjhhubj)}(hX 1. Traditional UNIX credentials. - Real User ID - Real Group ID The UID and GID are carried by most, if not all, Linux objects, even if in some cases it has to be invented (FAT or CIFS files for example, which are derived from Windows). These (mostly) define the objective context of that object, with tasks being slightly different in some cases. - Effective, Saved and FS User ID - Effective, Saved and FS Group ID - Supplementary groups These are additional credentials used by tasks only. Usually, an EUID/EGID/GROUPS will be used as the subjective context, and real UID/GID will be used as the objective. For tasks, it should be noted that this is not always true. 2. Capabilities. - Set of permitted capabilities - Set of inheritable capabilities - Set of effective capabilities - Capability bounding set These are only carried by tasks. They indicate superior capabilities granted piecemeal to a task that an ordinary task wouldn't otherwise have. These are manipulated implicitly by changes to the traditional UNIX credentials, but can also be manipulated directly by the ``capset()`` system call. The permitted capabilities are those caps that the process might grant itself to its effective or permitted sets through ``capset()``. This inheritable set might also be so constrained. The effective capabilities are the ones that a task is actually allowed to make use of itself. The inheritable capabilities are the ones that may get passed across ``execve()``. The bounding set limits the capabilities that may be inherited across ``execve()``, especially when a binary is executed that will execute as UID 0. 3. Secure management flags (securebits). These are only carried by tasks. These govern the way the above credentials are manipulated and inherited over certain operations such as execve(). They aren't used directly as objective or subjective credentials. 4. Keys and keyrings. These are only carried by tasks. They carry and cache security tokens that don't fit into the other standard UNIX credentials. They are for making such things as network filesystem keys available to the file accesses performed by processes, without the necessity of ordinary programs having to know about security details involved. Keyrings are a special type of key. They carry sets of other keys and can be searched for the desired key. Each process may subscribe to a number of keyrings: Per-thread keying Per-process keyring Per-session keyring When a process accesses a key, if not already present, it will normally be cached on one of these keyrings for future accesses to find. For more information on using keys, see ``Documentation/security/keys/*``. 5. LSM The Linux Security Module allows extra controls to be placed over the operations that a task may do. Currently Linux supports several LSM options. Some work by labelling the objects in a system and then applying sets of rules (policies) that say what operations a task with one label may do to an object with another label. 6. AF_KEY This is a socket-based approach to credential management for networking stacks [RFC 2367]. It isn't discussed by this document as it doesn't interact directly with task and file credentials; rather it keeps system level credentials. h]j)}(hhh](h)}(hXTraditional UNIX credentials. - Real User ID - Real Group ID The UID and GID are carried by most, if not all, Linux objects, even if in some cases it has to be invented (FAT or CIFS files for example, which are derived from Windows). These (mostly) define the objective context of that object, with tasks being slightly different in some cases. - Effective, Saved and FS User ID - Effective, Saved and FS Group ID - Supplementary groups These are additional credentials used by tasks only. Usually, an EUID/EGID/GROUPS will be used as the subjective context, and real UID/GID will be used as the objective. For tasks, it should be noted that this is not always true. h](h)}(hTraditional UNIX credentials.h]hTraditional UNIX credentials.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubj)}(hX - Real User ID - Real Group ID The UID and GID are carried by most, if not all, Linux objects, even if in some cases it has to be invented (FAT or CIFS files for example, which are derived from Windows). These (mostly) define the objective context of that object, with tasks being slightly different in some cases. - Effective, Saved and FS User ID - Effective, Saved and FS Group ID - Supplementary groups These are additional credentials used by tasks only. Usually, an EUID/EGID/GROUPS will be used as the subjective context, and real UID/GID will be used as the objective. For tasks, it should be noted that this is not always true. h](j)}(h- Real User ID - Real Group ID h]h)}(hhh](h)}(h Real User IDh]h)}(hjh]h Real User ID}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hReal Group ID h]h)}(h Real Group IDh]h Real Group ID}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj4ubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]jvjwuh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhhhKhjubh)}(hXThe UID and GID are carried by most, if not all, Linux objects, even if in some cases it has to be invented (FAT or CIFS files for example, which are derived from Windows). These (mostly) define the objective context of that object, with tasks being slightly different in some cases.h]hXThe UID and GID are carried by most, if not all, Linux objects, even if in some cases it has to be invented (FAT or CIFS files for example, which are derived from Windows). These (mostly) define the objective context of that object, with tasks being slightly different in some cases.}(hjXhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubj)}(h\- Effective, Saved and FS User ID - Effective, Saved and FS Group ID - Supplementary groups h]h)}(hhh](h)}(hEffective, Saved and FS User IDh]h)}(hjoh]hEffective, Saved and FS User ID}(hjqhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjmubah}(h]h ]h"]h$]h&]uh1hhjjubh)}(h Effective, Saved and FS Group IDh]h)}(hjh]h Effective, Saved and FS Group ID}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjjubh)}(hSupplementary groups h]h)}(hSupplementary groupsh]hSupplementary groups}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjjubeh}(h]h ]h"]h$]h&]jvjwuh1hhhhKhjfubah}(h]h ]h"]h$]h&]uh1jhhhKhjubh)}(hThese are additional credentials used by tasks only. Usually, an EUID/EGID/GROUPS will be used as the subjective context, and real UID/GID will be used as the objective. For tasks, it should be noted that this is not always true.h]hThese are additional credentials used by tasks only. Usually, an EUID/EGID/GROUPS will be used as the subjective context, and real UID/GID will be used as the objective. For tasks, it should be noted that this is not always true.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubeh}(h]h ]h"]h$]h&]uh1jhhhKhjubeh}(h]h ]h"]h$]h&]uh1hhjubh)}(hXCapabilities. - Set of permitted capabilities - Set of inheritable capabilities - Set of effective capabilities - Capability bounding set These are only carried by tasks. They indicate superior capabilities granted piecemeal to a task that an ordinary task wouldn't otherwise have. These are manipulated implicitly by changes to the traditional UNIX credentials, but can also be manipulated directly by the ``capset()`` system call. The permitted capabilities are those caps that the process might grant itself to its effective or permitted sets through ``capset()``. This inheritable set might also be so constrained. The effective capabilities are the ones that a task is actually allowed to make use of itself. The inheritable capabilities are the ones that may get passed across ``execve()``. The bounding set limits the capabilities that may be inherited across ``execve()``, especially when a binary is executed that will execute as UID 0. h](h)}(h Capabilities.h]h Capabilities.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubj)}(hX - Set of permitted capabilities - Set of inheritable capabilities - Set of effective capabilities - Capability bounding set These are only carried by tasks. They indicate superior capabilities granted piecemeal to a task that an ordinary task wouldn't otherwise have. These are manipulated implicitly by changes to the traditional UNIX credentials, but can also be manipulated directly by the ``capset()`` system call. The permitted capabilities are those caps that the process might grant itself to its effective or permitted sets through ``capset()``. This inheritable set might also be so constrained. The effective capabilities are the ones that a task is actually allowed to make use of itself. The inheritable capabilities are the ones that may get passed across ``execve()``. The bounding set limits the capabilities that may be inherited across ``execve()``, especially when a binary is executed that will execute as UID 0. h](j)}(h|- Set of permitted capabilities - Set of inheritable capabilities - Set of effective capabilities - Capability bounding set h]h)}(hhh](h)}(hSet of permitted capabilitiesh]h)}(hjh]hSet of permitted capabilities}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hSet of inheritable capabilitiesh]h)}(hjh]hSet of inheritable capabilities}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hSet of effective capabilitiesh]h)}(hj&h]hSet of effective capabilities}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj$ubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hCapability bounding set h]h)}(hCapability bounding seth]hCapability bounding set}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj;ubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]jvjwuh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhhhKhjubh)}(hX'These are only carried by tasks. They indicate superior capabilities granted piecemeal to a task that an ordinary task wouldn't otherwise have. These are manipulated implicitly by changes to the traditional UNIX credentials, but can also be manipulated directly by the ``capset()`` system call.h](hXThese are only carried by tasks. They indicate superior capabilities granted piecemeal to a task that an ordinary task wouldn’t otherwise have. These are manipulated implicitly by changes to the traditional UNIX credentials, but can also be manipulated directly by the }(hj_hhhNhNubjO)}(h ``capset()``h]hcapset()}(hjghhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj_ubh system call.}(hj_hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(hThe permitted capabilities are those caps that the process might grant itself to its effective or permitted sets through ``capset()``. This inheritable set might also be so constrained.h](hyThe permitted capabilities are those caps that the process might grant itself to its effective or permitted sets through }(hjhhhNhNubjO)}(h ``capset()``h]hcapset()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh5. This inheritable set might also be so constrained.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(h^The effective capabilities are the ones that a task is actually allowed to make use of itself.h]h^The effective capabilities are the ones that a task is actually allowed to make use of itself.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(hRThe inheritable capabilities are the ones that may get passed across ``execve()``.h](hEThe inheritable capabilities are the ones that may get passed across }(hjhhhNhNubjO)}(h ``execve()``h]hexecve()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(hThe bounding set limits the capabilities that may be inherited across ``execve()``, especially when a binary is executed that will execute as UID 0.h](hFThe bounding set limits the capabilities that may be inherited across }(hjhhhNhNubjO)}(h ``execve()``h]hexecve()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubhB, especially when a binary is executed that will execute as UID 0.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubeh}(h]h ]h"]h$]h&]uh1jhhhKhjubeh}(h]h ]h"]h$]h&]uh1hhjubh)}(hXSecure management flags (securebits). These are only carried by tasks. These govern the way the above credentials are manipulated and inherited over certain operations such as execve(). They aren't used directly as objective or subjective credentials. h](h)}(h%Secure management flags (securebits).h]h%Secure management flags (securebits).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubj)}(hThese are only carried by tasks. These govern the way the above credentials are manipulated and inherited over certain operations such as execve(). They aren't used directly as objective or subjective credentials. h]h)}(hThese are only carried by tasks. These govern the way the above credentials are manipulated and inherited over certain operations such as execve(). They aren't used directly as objective or subjective credentials.h]hThese are only carried by tasks. These govern the way the above credentials are manipulated and inherited over certain operations such as execve(). They aren’t used directly as objective or subjective credentials.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhhhKhjubeh}(h]h ]h"]h$]h&]uh1hhjubh)}(hX+Keys and keyrings. These are only carried by tasks. They carry and cache security tokens that don't fit into the other standard UNIX credentials. They are for making such things as network filesystem keys available to the file accesses performed by processes, without the necessity of ordinary programs having to know about security details involved. Keyrings are a special type of key. They carry sets of other keys and can be searched for the desired key. Each process may subscribe to a number of keyrings: Per-thread keying Per-process keyring Per-session keyring When a process accesses a key, if not already present, it will normally be cached on one of these keyrings for future accesses to find. For more information on using keys, see ``Documentation/security/keys/*``. h](h)}(hKeys and keyrings.h]hKeys and keyrings.}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj)ubj)}(hX These are only carried by tasks. They carry and cache security tokens that don't fit into the other standard UNIX credentials. They are for making such things as network filesystem keys available to the file accesses performed by processes, without the necessity of ordinary programs having to know about security details involved. Keyrings are a special type of key. They carry sets of other keys and can be searched for the desired key. Each process may subscribe to a number of keyrings: Per-thread keying Per-process keyring Per-session keyring When a process accesses a key, if not already present, it will normally be cached on one of these keyrings for future accesses to find. For more information on using keys, see ``Documentation/security/keys/*``. h](h)}(hXMThese are only carried by tasks. They carry and cache security tokens that don't fit into the other standard UNIX credentials. They are for making such things as network filesystem keys available to the file accesses performed by processes, without the necessity of ordinary programs having to know about security details involved.h]hXOThese are only carried by tasks. They carry and cache security tokens that don’t fit into the other standard UNIX credentials. They are for making such things as network filesystem keys available to the file accesses performed by processes, without the necessity of ordinary programs having to know about security details involved.}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj;ubh)}(hKeyrings are a special type of key. They carry sets of other keys and can be searched for the desired key. Each process may subscribe to a number of keyrings:h]hKeyrings are a special type of key. They carry sets of other keys and can be searched for the desired key. Each process may subscribe to a number of keyrings:}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj;ubj)}(h:Per-thread keying Per-process keyring Per-session keyring h]h)}(h9Per-thread keying Per-process keyring Per-session keyringh]h9Per-thread keying Per-process keyring Per-session keyring}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj[ubah}(h]h ]h"]h$]h&]uh1jhhhKhj;ubh)}(hWhen a process accesses a key, if not already present, it will normally be cached on one of these keyrings for future accesses to find.h]hWhen a process accesses a key, if not already present, it will normally be cached on one of these keyrings for future accesses to find.}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj;ubh)}(hJFor more information on using keys, see ``Documentation/security/keys/*``.h](h(For more information on using keys, see }(hjhhhNhNubjO)}(h!``Documentation/security/keys/*``h]hDocumentation/security/keys/*}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj;ubeh}(h]h ]h"]h$]h&]uh1jhhhKhj)ubeh}(h]h ]h"]h$]h&]uh1hhjubh)}(hXQLSM The Linux Security Module allows extra controls to be placed over the operations that a task may do. Currently Linux supports several LSM options. Some work by labelling the objects in a system and then applying sets of rules (policies) that say what operations a task with one label may do to an object with another label. h](h)}(hLSMh]hLSM}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubj)}(hXFThe Linux Security Module allows extra controls to be placed over the operations that a task may do. Currently Linux supports several LSM options. Some work by labelling the objects in a system and then applying sets of rules (policies) that say what operations a task with one label may do to an object with another label. h](h)}(hThe Linux Security Module allows extra controls to be placed over the operations that a task may do. Currently Linux supports several LSM options.h]hThe Linux Security Module allows extra controls to be placed over the operations that a task may do. Currently Linux supports several LSM options.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(hSome work by labelling the objects in a system and then applying sets of rules (policies) that say what operations a task with one label may do to an object with another label.h]hSome work by labelling the objects in a system and then applying sets of rules (policies) that say what operations a task with one label may do to an object with another label.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubeh}(h]h ]h"]h$]h&]uh1jhhhKhjubeh}(h]h ]h"]h$]h&]uh1hhjubh)}(hAF_KEY This is a socket-based approach to credential management for networking stacks [RFC 2367]. It isn't discussed by this document as it doesn't interact directly with task and file credentials; rather it keeps system level credentials. h](h)}(hAF_KEYh]hAF_KEY}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubj)}(hThis is a socket-based approach to credential management for networking stacks [RFC 2367]. It isn't discussed by this document as it doesn't interact directly with task and file credentials; rather it keeps system level credentials. h]h)}(hThis is a socket-based approach to credential management for networking stacks [RFC 2367]. It isn't discussed by this document as it doesn't interact directly with task and file credentials; rather it keeps system level credentials.h]hThis is a socket-based approach to credential management for networking stacks [RFC 2367]. It isn’t discussed by this document as it doesn’t interact directly with task and file credentials; rather it keeps system level credentials.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhhhKhjubeh}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]jjjhjjuh1jhjubah}(h]h ]h"]h$]h&]uh1jhhhKhjhhubh)}(hXWhen a file is opened, part of the opening task's subjective context is recorded in the file struct created. This allows operations using that file struct to use those credentials instead of the subjective context of the task that issued the operation. An example of this would be a file opened on a network filesystem where the credentials of the opened file should be presented to the server, regardless of who is actually doing a read or a write upon it.h]hXWhen a file is opened, part of the opening task’s subjective context is recorded in the file struct created. This allows operations using that file struct to use those credentials instead of the subjective context of the task that issued the operation. An example of this would be a file opened on a network filesystem where the credentials of the opened file should be presented to the server, regardless of who is actually doing a read or a write upon it.}(hj' hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]j ah ]h"]types of credentialsah$]h&]uh1hhhhhhhhK{ubh)}(hhh](h)}(h File Markingsh]h File Markings}(hj? hhhNhNubah}(h]h ]h"]h$]h&]jj<uh1hhj< hhhhhKubh)}(hFiles on disk or obtained over the network may have annotations that form the objective security context of that file. Depending on the type of filesystem, this may include one or more of the following:h]hFiles on disk or obtained over the network may have annotations that form the objective security context of that file. Depending on the type of filesystem, this may include one or more of the following:}(hjM hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj< hhubj)}(h* UNIX UID, GID, mode; * Windows user ID; * Access control list; * LSM security label; * UNIX exec privilege escalation bits (SUID/SGID); * File capabilities exec privilege escalation bits. h]h)}(hhh](h)}(hUNIX UID, GID, mode;h]h)}(hjd h]hUNIX UID, GID, mode;}(hjf hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjb ubah}(h]h ]h"]h$]h&]uh1hhj_ ubh)}(hWindows user ID;h]h)}(hj{ h]hWindows user ID;}(hj} hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjy ubah}(h]h ]h"]h$]h&]uh1hhj_ ubh)}(hAccess control list;h]h)}(hj h]hAccess control list;}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1hhj_ ubh)}(hLSM security label;h]h)}(hj h]hLSM security label;}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1hhj_ ubh)}(h0UNIX exec privilege escalation bits (SUID/SGID);h]h)}(hj h]h0UNIX exec privilege escalation bits (SUID/SGID);}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1hhj_ ubh)}(h2File capabilities exec privilege escalation bits. h]h)}(h1File capabilities exec privilege escalation bits.h]h1File capabilities exec privilege escalation bits.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1hhj_ ubeh}(h]h ]h"]h$]h&]jv*uh1hhhhKhj[ ubah}(h]h ]h"]h$]h&]uh1jhhhKhj< hhubh)}(hX&These are compared to the task's subjective security context, and certain operations allowed or disallowed as a result. In the case of execve(), the privilege escalation bits come into play, and may allow the resulting process extra privileges, based on the annotations on the executable file.h]hX(These are compared to the task’s subjective security context, and certain operations allowed or disallowed as a result. In the case of execve(), the privilege escalation bits come into play, and may allow the resulting process extra privileges, based on the annotations on the executable file.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj< hhubeh}(h]jBah ]h"] file markingsah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hTask Credentialsh]hTask Credentials}(hj hhhNhNubah}(h]h ]h"]h$]h&]jj^uh1hhj hhhhhKubh)}(hIn Linux, all of a task's credentials are held in (uid, gid) or through (groups, keys, LSM security) a refcounted structure of type 'struct cred'. Each task points to its credentials by a pointer called 'cred' in its task_struct.h]hIn Linux, all of a task’s credentials are held in (uid, gid) or through (groups, keys, LSM security) a refcounted structure of type ‘struct cred’. Each task points to its credentials by a pointer called ‘cred’ in its task_struct.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj hhubh)}(hsOnce a set of credentials has been prepared and committed, it may not be changed, barring the following exceptions:h]hsOnce a set of credentials has been prepared and committed, it may not be changed, barring the following exceptions:}(hj. hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj hhubj)}(hX$1. its reference count may be changed; 2. the reference count on the group_info struct it points to may be changed; 3. the reference count on the security data it points to may be changed; 4. the reference count on any keyrings it points to may be changed; 5. any keyrings it points to may be revoked, expired or have their security attributes changed; and 6. the contents of any keyrings to which it points may be changed (the whole point of keyrings being a shared set of credentials, modifiable by anyone with appropriate access). h]j)}(hhh](h)}(h$its reference count may be changed; h]h)}(h#its reference count may be changed;h]h#its reference count may be changed;}(hjG hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjC ubah}(h]h ]h"]h$]h&]uh1hhj@ ubh)}(hJthe reference count on the group_info struct it points to may be changed; h]h)}(hIthe reference count on the group_info struct it points to may be changed;h]hIthe reference count on the group_info struct it points to may be changed;}(hj_ hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj[ ubah}(h]h ]h"]h$]h&]uh1hhj@ ubh)}(hFthe reference count on the security data it points to may be changed; h]h)}(hEthe reference count on the security data it points to may be changed;h]hEthe reference count on the security data it points to may be changed;}(hjw hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjs ubah}(h]h ]h"]h$]h&]uh1hhj@ ubh)}(hAthe reference count on any keyrings it points to may be changed; h]h)}(h@the reference count on any keyrings it points to may be changed;h]h@the reference count on any keyrings it points to may be changed;}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1hhj@ ubh)}(haany keyrings it points to may be revoked, expired or have their security attributes changed; and h]h)}(h`any keyrings it points to may be revoked, expired or have their security attributes changed; andh]h`any keyrings it points to may be revoked, expired or have their security attributes changed; and}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj ubah}(h]h ]h"]h$]h&]uh1hhj@ ubh)}(hthe contents of any keyrings to which it points may be changed (the whole point of keyrings being a shared set of credentials, modifiable by anyone with appropriate access). h]h)}(hthe contents of any keyrings to which it points may be changed (the whole point of keyrings being a shared set of credentials, modifiable by anyone with appropriate access).h]hthe contents of any keyrings to which it points may be changed (the whole point of keyrings being a shared set of credentials, modifiable by anyone with appropriate access).}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj ubah}(h]h ]h"]h$]h&]uh1hhj@ ubeh}(h]h ]h"]h$]h&]jjjhjjuh1jhj< ubah}(h]h ]h"]h$]h&]uh1jhhhMhj hhubh)}(hXTo alter anything in the cred struct, the copy-and-replace principle must be adhered to. First take a copy, then alter the copy and then use RCU to change the task pointer to make it point to the new copy. There are wrappers to aid with this (see below).h]hXTo alter anything in the cred struct, the copy-and-replace principle must be adhered to. First take a copy, then alter the copy and then use RCU to change the task pointer to make it point to the new copy. There are wrappers to aid with this (see below).}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hXA task may only alter its _own_ credentials; it is no longer permitted for a task to alter another's credentials. This means the ``capset()`` system call is no longer permitted to take any PID other than the one of the current process. Also ``keyctl_instantiate()`` and ``keyctl_negate()`` functions no longer permit attachment to process-specific keyrings in the requesting process as the instantiating process may need to create them.h](hA task may only alter its _own_ credentials; it is no longer permitted for a task to alter another’s credentials. This means the }(hj hhhNhNubjO)}(h ``capset()``h]hcapset()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubhd system call is no longer permitted to take any PID other than the one of the current process. Also }(hj hhhNhNubjO)}(h``keyctl_instantiate()``h]hkeyctl_instantiate()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh and }(hj hhhNhNubjO)}(h``keyctl_negate()``h]hkeyctl_negate()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh functions no longer permit attachment to process-specific keyrings in the requesting process as the instantiating process may need to create them.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hhh](h)}(hImmutable Credentialsh]hImmutable Credentials}(hj4 hhhNhNubah}(h]h ]h"]h$]h&]jj}uh1hhj1 hhhhhMubh)}(hOnce a set of credentials has been made public (by calling ``commit_creds()`` for example), it must be considered immutable, barring two exceptions:h](h;Once a set of credentials has been made public (by calling }(hjB hhhNhNubjO)}(h``commit_creds()``h]hcommit_creds()}(hjJ hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjB ubhG for example), it must be considered immutable, barring two exceptions:}(hjB hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM!hj1 hhubj)}(h1. The reference count may be altered. 2. While the keyring subscriptions of a set of credentials may not be changed, the keyrings subscribed to may have their contents altered. h]j)}(hhh](h)}(h$The reference count may be altered. h]h)}(h#The reference count may be altered.h]h#The reference count may be altered.}(hjm hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM$hji ubah}(h]h ]h"]h$]h&]uh1hhjf ubh)}(hWhile the keyring subscriptions of a set of credentials may not be changed, the keyrings subscribed to may have their contents altered. h]h)}(hWhile the keyring subscriptions of a set of credentials may not be changed, the keyrings subscribed to may have their contents altered.h]hWhile the keyring subscriptions of a set of credentials may not be changed, the keyrings subscribed to may have their contents altered.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM&hj ubah}(h]h ]h"]h$]h&]uh1hhjf ubeh}(h]h ]h"]h$]h&]jjjhjjuh1jhjb ubah}(h]h ]h"]h$]h&]uh1jhhhM$hj1 hhubh)}(hXxTo catch accidental credential alteration at compile time, struct task_struct has _const_ pointers to its credential sets, as does struct file. Furthermore, certain functions such as ``get_cred()`` and ``put_cred()`` operate on const pointers, thus rendering casts unnecessary, but require to temporarily ditch the const qualification to be able to alter the reference count.h](hTo catch accidental credential alteration at compile time, struct task_struct has _const_ pointers to its credential sets, as does struct file. Furthermore, certain functions such as }(hj hhhNhNubjO)}(h``get_cred()``h]h get_cred()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh and }(hj hhhNhNubjO)}(h``put_cred()``h]h put_cred()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh operate on const pointers, thus rendering casts unnecessary, but require to temporarily ditch the const qualification to be able to alter the reference count.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM)hj1 hhubeh}(h]jah ]h"]immutable credentialsah$]h&]uh1hhj hhhhhMubh)}(hhh](h)}(hAccessing Task Credentialsh]hAccessing Task Credentials}(hj hhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhj hhhhhM1ubh)}(hA task being able to alter only its own credentials permits the current process to read or replace its own credentials without the need for any form of locking -- which simplifies things greatly. It can just call::h]hA task being able to alter only its own credentials permits the current process to read or replace its own credentials without the need for any form of locking -- which simplifies things greatly. It can just call:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM3hj hhubh literal_block)}(h!const struct cred *current_cred()h]h!const struct cred *current_cred()}hj sbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1j hhhM7hj hhubh)}(h\to get a pointer to its credentials structure, and it doesn't have to release it afterwards.h]h^to get a pointer to its credentials structure, and it doesn’t have to release it afterwards.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM9hj hhubh)}(hThere are convenience wrappers for retrieving specific aspects of a task's credentials (the value is simply returned in each case)::h]hThere are convenience wrappers for retrieving specific aspects of a task’s credentials (the value is simply returned in each case):}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM<hj hhubj )}(hXuid_t current_uid(void) Current's real UID gid_t current_gid(void) Current's real GID uid_t current_euid(void) Current's effective UID gid_t current_egid(void) Current's effective GID uid_t current_fsuid(void) Current's file access UID gid_t current_fsgid(void) Current's file access GID kernel_cap_t current_cap(void) Current's effective capabilities struct user_struct *current_user(void) Current's user accounth]hXuid_t current_uid(void) Current's real UID gid_t current_gid(void) Current's real GID uid_t current_euid(void) Current's effective UID gid_t current_egid(void) Current's effective GID uid_t current_fsuid(void) Current's file access UID gid_t current_fsgid(void) Current's file access GID kernel_cap_t current_cap(void) Current's effective capabilities struct user_struct *current_user(void) Current's user account}hj+ sbah}(h]h ]h"]h$]h&]j j uh1j hhhM?hj hhubh)}(hfThere are also convenience wrappers for retrieving specific associated pairs of a task's credentials::h]hgThere are also convenience wrappers for retrieving specific associated pairs of a task’s credentials:}(hj9 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMHhj hhubj )}(h}void current_uid_gid(uid_t *, gid_t *); void current_euid_egid(uid_t *, gid_t *); void current_fsuid_fsgid(uid_t *, gid_t *);h]h}void current_uid_gid(uid_t *, gid_t *); void current_euid_egid(uid_t *, gid_t *); void current_fsuid_fsgid(uid_t *, gid_t *);}hjG sbah}(h]h ]h"]h$]h&]j j uh1j hhhMKhj hhubh)}(huwhich return these pairs of values through their arguments after retrieving them from the current task's credentials.h]hwwhich return these pairs of values through their arguments after retrieving them from the current task’s credentials.}(hjU hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMOhj hhubh)}(hpIn addition, there is a function for obtaining a reference on the current process's current set of credentials::h]hqIn addition, there is a function for obtaining a reference on the current process’s current set of credentials:}(hjc hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMShj hhubj )}(h*const struct cred *get_current_cred(void);h]h*const struct cred *get_current_cred(void);}hjq sbah}(h]h ]h"]h$]h&]j j uh1j hhhMVhj hhubh)}(hhand functions for getting references to one of the credentials that don't actually live in struct cred::h]hiand functions for getting references to one of the credentials that don’t actually live in struct cred:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMXhj hhubj )}(hXstruct user_struct *get_current_user(void); struct group_info *get_current_groups(void);h]hXstruct user_struct *get_current_user(void); struct group_info *get_current_groups(void);}hj sbah}(h]h ]h"]h$]h&]j j uh1j hhhM[hj hhubh)}(hswhich get references to the current process's user accounting structure and supplementary groups list respectively.h]huwhich get references to the current process’s user accounting structure and supplementary groups list respectively.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM^hj hhubh)}(hOnce a reference has been obtained, it must be released with ``put_cred()``, ``free_uid()`` or ``put_group_info()`` as appropriate.h](h=Once a reference has been obtained, it must be released with }(hj hhhNhNubjO)}(h``put_cred()``h]h put_cred()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh, }(hj hhhNhNubjO)}(h``free_uid()``h]h free_uid()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh or }(hj hhhNhNubjO)}(h``put_group_info()``h]hput_group_info()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh as appropriate.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMahj hhubeh}(h]jah ]h"]accessing task credentialsah$]h&]uh1hhj hhhhhM1ubh)}(hhh](h)}(h$Accessing Another Task's Credentialsh]h&Accessing Another Task’s Credentials}(hj hhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhj hhhhhMfubh)}(hWhile a task may access its own credentials without the need for locking, the same is not true of a task wanting to access another task's credentials. It must use the RCU read lock and ``rcu_dereference()``.h](hWhile a task may access its own credentials without the need for locking, the same is not true of a task wanting to access another task’s credentials. It must use the RCU read lock and }(hj hhhNhNubjO)}(h``rcu_dereference()``h]hrcu_dereference()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhhj hhubh)}(h)The ``rcu_dereference()`` is wrapped by::h](hThe }(hj% hhhNhNubjO)}(h``rcu_dereference()``h]hrcu_dereference()}(hj- hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj% ubh is wrapped by:}(hj% hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMlhj hhubj )}(h9const struct cred *__task_cred(struct task_struct *task);h]h9const struct cred *__task_cred(struct task_struct *task);}hjE sbah}(h]h ]h"]h$]h&]j j uh1j hhhMnhj hhubh)}(hKThis should be used inside the RCU read lock, as in the following example::h]hJThis should be used inside the RCU read lock, as in the following example:}(hjS hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMphj hhubj )}(hX2void foo(struct task_struct *t, struct foo_data *f) { const struct cred *tcred; ... rcu_read_lock(); tcred = __task_cred(t); f->uid = tcred->uid; f->gid = tcred->gid; f->groups = get_group_info(tcred->groups); rcu_read_unlock(); ... }h]hX2void foo(struct task_struct *t, struct foo_data *f) { const struct cred *tcred; ... rcu_read_lock(); tcred = __task_cred(t); f->uid = tcred->uid; f->gid = tcred->gid; f->groups = get_group_info(tcred->groups); rcu_read_unlock(); ... }}hja sbah}(h]h ]h"]h$]h&]j j uh1j hhhMrhj hhubh)}(hShould it be necessary to hold another task's credentials for a long period of time, and possibly to sleep while doing so, then the caller should get a reference on them using::h]hShould it be necessary to hold another task’s credentials for a long period of time, and possibly to sleep while doing so, then the caller should get a reference on them using:}(hjo hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubj )}(h;const struct cred *get_task_cred(struct task_struct *task);h]h;const struct cred *get_task_cred(struct task_struct *task);}hj} sbah}(h]h ]h"]h$]h&]j j uh1j hhhMhj hhubh)}(hThis does all the RCU magic inside of it. The caller must call put_cred() on the credentials so obtained when they're finished with.h]hThis does all the RCU magic inside of it. The caller must call put_cred() on the credentials so obtained when they’re finished with.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubhnote)}(hxThe result of ``__task_cred()`` should not be passed directly to ``get_cred()`` as this may race with ``commit_cred()``.h]h)}(hxThe result of ``__task_cred()`` should not be passed directly to ``get_cred()`` as this may race with ``commit_cred()``.h](hThe result of }(hj hhhNhNubjO)}(h``__task_cred()``h]h __task_cred()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh" should not be passed directly to }(hj hhhNhNubjO)}(h``get_cred()``h]h get_cred()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh as this may race with }(hj hhhNhNubjO)}(h``commit_cred()``h]h commit_cred()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1j hj hhhhhNubh)}(hThere are a couple of convenience functions to access bits of another task's credentials, hiding the RCU magic from the caller::h]hThere are a couple of convenience functions to access bits of another task’s credentials, hiding the RCU magic from the caller:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubj )}(hduid_t task_uid(task) Task's real UID uid_t task_euid(task) Task's effective UIDh]hduid_t task_uid(task) Task's real UID uid_t task_euid(task) Task's effective UID}hj sbah}(h]h ]h"]h$]h&]j j uh1j hhhMhj hhubh)}(hEIf the caller is holding the RCU read lock at the time anyway, then::h]hDIf the caller is holding the RCU read lock at the time anyway, then:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubj )}(h.__task_cred(task)->uid __task_cred(task)->euidh]h.__task_cred(task)->uid __task_cred(task)->euid}hjsbah}(h]h ]h"]h$]h&]j j uh1j hhhMhj hhubh)}(hXfshould be used instead. Similarly, if multiple aspects of a task's credentials need to be accessed, RCU read lock should be used, ``__task_cred()`` called, the result stored in a temporary pointer and then the credential aspects called from that before dropping the lock. This prevents the potentially expensive RCU magic from being invoked multiple times.h](hshould be used instead. Similarly, if multiple aspects of a task’s credentials need to be accessed, RCU read lock should be used, }(hj!hhhNhNubjO)}(h``__task_cred()``h]h __task_cred()}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj!ubh called, the result stored in a temporary pointer and then the credential aspects called from that before dropping the lock. This prevents the potentially expensive RCU magic from being invoked multiple times.}(hj!hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hjShould some other single aspect of another task's credentials need to be accessed, then this can be used::h]hkShould some other single aspect of another task’s credentials need to be accessed, then this can be used:}(hjAhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubj )}(htask_cred_xxx(task, member)h]htask_cred_xxx(task, member)}hjOsbah}(h]h ]h"]h$]h&]j j uh1j hhhMhj hhubh)}(hJwhere 'member' is a non-pointer member of the cred struct. For instance::h]hMwhere ‘member’ is a non-pointer member of the cred struct. For instance:}(hj]hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubj )}(h uid_t task_cred_xxx(task, suid);h]h uid_t task_cred_xxx(task, suid);}hjksbah}(h]h ]h"]h$]h&]j j uh1j hhhMhj hhubh)}(hwill retrieve 'struct cred::suid' from the task, doing the appropriate RCU magic. This may not be used for pointer members as what they point to may disappear the moment the RCU read lock is dropped.h]hwill retrieve ‘struct cred::suid’ from the task, doing the appropriate RCU magic. This may not be used for pointer members as what they point to may disappear the moment the RCU read lock is dropped.}(hjyhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubeh}(h]jah ]h"]$accessing another task's credentialsah$]h&]uh1hhj hhhhhMfubh)}(hhh](h)}(hAltering Credentialsh]hAltering Credentials}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjhhhhhMubh)}(hAs previously mentioned, a task may only alter its own credentials, and may not alter those of another task. This means that it doesn't need to use any locking to alter its own credentials.h]hAs previously mentioned, a task may only alter its own credentials, and may not alter those of another task. This means that it doesn’t need to use any locking to alter its own credentials.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hqTo alter the current process's credentials, a function should first prepare a new set of credentials by calling::h]hrTo alter the current process’s credentials, a function should first prepare a new set of credentials by calling:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj )}(h!struct cred *prepare_creds(void);h]h!struct cred *prepare_creds(void);}hjsbah}(h]h ]h"]h$]h&]j j uh1j hhhMhjhhubh)}(hthis locks current->cred_replace_mutex and then allocates and constructs a duplicate of the current process's credentials, returning with the mutex still held if successful. It returns NULL if not successful (out of memory).h]hthis locks current->cred_replace_mutex and then allocates and constructs a duplicate of the current process’s credentials, returning with the mutex still held if successful. It returns NULL if not successful (out of memory).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hThe mutex prevents ``ptrace()`` from altering the ptrace state of a process while security checks on credentials construction and changing is taking place as the ptrace state may alter the outcome, particularly in the case of ``execve()``.h](hThe mutex prevents }(hjhhhNhNubjO)}(h ``ptrace()``h]hptrace()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh from altering the ptrace state of a process while security checks on credentials construction and changing is taking place as the ptrace state may alter the outcome, particularly in the case of }(hjhhhNhNubjO)}(h ``execve()``h]hexecve()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hThe new credentials set should be altered appropriately, and any security checks and hooks done. Both the current and the proposed sets of credentials are available for this purpose as current_cred() will return the current set still at this point.h]hThe new credentials set should be altered appropriately, and any security checks and hooks done. Both the current and the proposed sets of credentials are available for this purpose as current_cred() will return the current set still at this point.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hXWhen replacing the group list, the new list must be sorted before it is added to the credential, as a binary search is used to test for membership. In practice, this means groups_sort() should be called before set_groups() or set_current_groups(). groups_sort() must not be called on a ``struct group_list`` which is shared as it may permute elements as part of the sorting process even if the array is already sorted.h](hXWhen replacing the group list, the new list must be sorted before it is added to the credential, as a binary search is used to test for membership. In practice, this means groups_sort() should be called before set_groups() or set_current_groups(). groups_sort() must not be called on a }(hjhhhNhNubjO)}(h``struct group_list``h]hstruct group_list}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubho which is shared as it may permute elements as part of the sorting process even if the array is already sorted.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h\When the credential set is ready, it should be committed to the current process by calling::h]h[When the credential set is ready, it should be committed to the current process by calling:}(hj7hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj )}(h#int commit_creds(struct cred *new);h]h#int commit_creds(struct cred *new);}hjEsbah}(h]h ]h"]h$]h&]j j uh1j hhhMhjhhubh)}(hXcThis will alter various aspects of the credentials and the process, giving the LSM a chance to do likewise, then it will use ``rcu_assign_pointer()`` to actually commit the new credentials to ``current->cred``, it will release ``current->cred_replace_mutex`` to allow ``ptrace()`` to take place, and it will notify the scheduler and others of the changes.h](h}This will alter various aspects of the credentials and the process, giving the LSM a chance to do likewise, then it will use }(hjShhhNhNubjO)}(h``rcu_assign_pointer()``h]hrcu_assign_pointer()}(hj[hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjSubh+ to actually commit the new credentials to }(hjShhhNhNubjO)}(h``current->cred``h]h current->cred}(hjmhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjSubh, it will release }(hjShhhNhNubjO)}(h``current->cred_replace_mutex``h]hcurrent->cred_replace_mutex}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjSubh to allow }(hjShhhNhNubjO)}(h ``ptrace()``h]hptrace()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjSubhK to take place, and it will notify the scheduler and others of the changes.}(hjShhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h{This function is guaranteed to return 0, so that it can be tail-called at the end of such functions as ``sys_setresuid()``.h](hgThis function is guaranteed to return 0, so that it can be tail-called at the end of such functions as }(hjhhhNhNubjO)}(h``sys_setresuid()``h]hsys_setresuid()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hNote that this function consumes the caller's reference to the new credentials. The caller should _not_ call ``put_cred()`` on the new credentials afterwards.h](hoNote that this function consumes the caller’s reference to the new credentials. The caller should _not_ call }(hjhhhNhNubjO)}(h``put_cred()``h]h put_cred()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh# on the new credentials afterwards.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h|Furthermore, once this function has been called on a new set of credentials, those credentials may _not_ be changed further.h]h|Furthermore, once this function has been called on a new set of credentials, those credentials may _not_ be changed further.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hShould the security checks fail or some other error occur after ``prepare_creds()`` has been called, then the following function should be invoked::h](h@Should the security checks fail or some other error occur after }(hjhhhNhNubjO)}(h``prepare_creds()``h]hprepare_creds()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh@ has been called, then the following function should be invoked:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj )}(h#void abort_creds(struct cred *new);h]h#void abort_creds(struct cred *new);}hjsbah}(h]h ]h"]h$]h&]j j uh1j hhhMhjhhubh)}(h}This releases the lock on ``current->cred_replace_mutex`` that ``prepare_creds()`` got and then releases the new credentials.h](hThis releases the lock on }(hj%hhhNhNubjO)}(h``current->cred_replace_mutex``h]hcurrent->cred_replace_mutex}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj%ubh that }(hj%hhhNhNubjO)}(h``prepare_creds()``h]hprepare_creds()}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj%ubh+ got and then releases the new credentials.}(hj%hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hJA typical credentials alteration function would look something like this::h]hIA typical credentials alteration function would look something like this:}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj )}(hX`int alter_suid(uid_t suid) { struct cred *new; int ret; new = prepare_creds(); if (!new) return -ENOMEM; new->suid = suid; ret = security_alter_suid(new); if (ret < 0) { abort_creds(new); return ret; } return commit_creds(new); }h]hX`int alter_suid(uid_t suid) { struct cred *new; int ret; new = prepare_creds(); if (!new) return -ENOMEM; new->suid = suid; ret = security_alter_suid(new); if (ret < 0) { abort_creds(new); return ret; } return commit_creds(new); }}hjesbah}(h]h ]h"]h$]h&]j j uh1j hhhMhjhhubeh}(h]jah ]h"]altering credentialsah$]h&]uh1hhj hhhhhMubh)}(hhh](h)}(hManaging Credentialsh]hManaging Credentials}(hj}hhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjzhhhhhMubh)}(h4There are some functions to help manage credentials:h]h4There are some functions to help manage credentials:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjzhhubj)}(hX- ``void put_cred(const struct cred *cred);`` This releases a reference to the given set of credentials. If the reference count reaches zero, the credentials will be scheduled for destruction by the RCU system. - ``const struct cred *get_cred(const struct cred *cred);`` This gets a reference on a live set of credentials, returning a pointer to that set of credentials. h]h)}(hhh](h)}(h``void put_cred(const struct cred *cred);`` This releases a reference to the given set of credentials. If the reference count reaches zero, the credentials will be scheduled for destruction by the RCU system. h](h)}(h+``void put_cred(const struct cred *cred);``h]jO)}(hjh]h'void put_cred(const struct cred *cred);}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubah}(h]h ]h"]h$]h&]uh1hhhhMhjubj)}(hThis releases a reference to the given set of credentials. If the reference count reaches zero, the credentials will be scheduled for destruction by the RCU system. h]h)}(hThis releases a reference to the given set of credentials. If the reference count reaches zero, the credentials will be scheduled for destruction by the RCU system.h]hThis releases a reference to the given set of credentials. If the reference count reaches zero, the credentials will be scheduled for destruction by the RCU system.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hjubah}(h]h ]h"]h$]h&]uh1jhhhM hjubeh}(h]h ]h"]h$]h&]uh1hhjubh)}(h``const struct cred *get_cred(const struct cred *cred);`` This gets a reference on a live set of credentials, returning a pointer to that set of credentials. h](h)}(h9``const struct cred *get_cred(const struct cred *cred);``h]jO)}(hjh]h5const struct cred *get_cred(const struct cred *cred);}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubah}(h]h ]h"]h$]h&]uh1hhhhM hjubj)}(heThis gets a reference on a live set of credentials, returning a pointer to that set of credentials. h]h)}(hcThis gets a reference on a live set of credentials, returning a pointer to that set of credentials.h]hcThis gets a reference on a live set of credentials, returning a pointer to that set of credentials.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhhhMhjubeh}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]jvjwuh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhhhMhjzhhubeh}(h]j ah ]h"]managing credentialsah$]h&]uh1hhj hhhhhMubeh}(h]jdah ]h"]task credentialsah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hOpen File Credentialsh]hOpen File Credentials}(hj/hhhNhNubah}(h]h ]h"]h$]h&]jj3uh1hhj,hhhhhMubh)}(hX4When a new file is opened, a reference is obtained on the opening task's credentials and this is attached to the file struct as ``f_cred`` in place of ``f_uid`` and ``f_gid``. Code that used to access ``file->f_uid`` and ``file->f_gid`` should now access ``file->f_cred->fsuid`` and ``file->f_cred->fsgid``.h](hWhen a new file is opened, a reference is obtained on the opening task’s credentials and this is attached to the file struct as }(hj=hhhNhNubjO)}(h ``f_cred``h]hf_cred}(hjEhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj=ubh in place of }(hj=hhhNhNubjO)}(h ``f_uid``h]hf_uid}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj=ubh and }(hj=hhhNhNubjO)}(h ``f_gid``h]hf_gid}(hjihhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj=ubh. Code that used to access }(hj=hhhNhNubjO)}(h``file->f_uid``h]h file->f_uid}(hj{hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj=ubh and }(hj=hhhNhNubjO)}(h``file->f_gid``h]h file->f_gid}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj=ubh should now access }(hj=hhhNhNubjO)}(h``file->f_cred->fsuid``h]hfile->f_cred->fsuid}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj=ubh and }hj=sbjO)}(h``file->f_cred->fsgid``h]hfile->f_cred->fsgid}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj=ubh.}(hj=hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj,hhubh)}(hX It is safe to access ``f_cred`` without the use of RCU or locking because the pointer will not change over the lifetime of the file struct, and nor will the contents of the cred struct pointed to, barring the exceptions listed above (see the Task Credentials section).h](hIt is safe to access }(hjhhhNhNubjO)}(h ``f_cred``h]hf_cred}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh without the use of RCU or locking because the pointer will not change over the lifetime of the file struct, and nor will the contents of the cred struct pointed to, barring the exceptions listed above (see the Task Credentials section).}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj,hhubh)}(hTo avoid "confused deputy" privilege escalation attacks, access control checks during subsequent operations on an opened file should use these credentials instead of "current"'s credentials, as the file may have been passed to a more privileged process.h]hXTo avoid “confused deputy” privilege escalation attacks, access control checks during subsequent operations on an opened file should use these credentials instead of “current“‘s credentials, as the file may have been passed to a more privileged process.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM!hj,hhubeh}(h]j9ah ]h"]open file credentialsah$]h&]uh1hhhhhhhhMubh)}(hhh](h)}(h'Overriding the VFS's Use of Credentialsh]h)Overriding the VFS’s Use of Credentials}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjUuh1hhjhhhhhM'ubh)}(hUnder some circumstances it is desirable to override the credentials used by the VFS, and that can be done by calling into such as ``vfs_mkdir()`` with a different set of credentials. This is done in the following places:h](hUnder some circumstances it is desirable to override the credentials used by the VFS, and that can be done by calling into such as }(hjhhhNhNubjO)}(h``vfs_mkdir()``h]h vfs_mkdir()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubhL with a different set of credentials. This is done in the following places:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM)hjhhubj)}(h<* ``sys_faccessat()``. * ``do_coredump()``. * nfs4recover.c.h]h)}(hhh](h)}(h``sys_faccessat()``.h]h)}(hj8h](jO)}(h``sys_faccessat()``h]hsys_faccessat()}(hj=hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj:ubh.}(hj:hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM-hj6ubah}(h]h ]h"]h$]h&]uh1hhj3ubh)}(h``do_coredump()``.h]h)}(hj]h](jO)}(h``do_coredump()``h]h do_coredump()}(hjbhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj_ubh.}(hj_hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM.hj[ubah}(h]h ]h"]h$]h&]uh1hhj3ubh)}(hnfs4recover.c.h]h)}(hjh]hnfs4recover.c.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM/hjubah}(h]h ]h"]h$]h&]uh1hhj3ubeh}(h]h ]h"]h$]h&]jvj uh1hhhhM-hj/ubah}(h]h ]h"]h$]h&]uh1jhhhM-hjhhubeh}(h]j[ah ]h"]'overriding the vfs's use of credentialsah$]h&]uh1hhhhhhhhM'ubeh}(h]credentials-in-linuxah ]h"]credentials in linuxah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(jjjujpjhj9 j j jBj)jdj jj jjjjwjj"j jj9jj[u nametypes}(jjujj9 j j)j j jjwj"jjuh}(jhjphhjxj jjBj< jdj jj1 jj jj jjj jzj9j,j[jhhjjj<j3j^jUj}jtjjjjjjjjj3j*jUjLu footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}jK sRparse_messages]transform_messages] transformerN include_log] decorationNhhub.