~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/security/keys/request-key.rst

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /Documentation/security/keys/request-key.rst (Version linux-6.12-rc7) and /Documentation/security/keys/request-key.rst (Version linux-4.18.20)


  1 ===================                                 1 ===================
  2 Key Request Service                                 2 Key Request Service
  3 ===================                                 3 ===================
  4                                                     4 
  5 The key request service is part of the key ret      5 The key request service is part of the key retention service (refer to
  6 Documentation/security/keys/core.rst).  This d      6 Documentation/security/keys/core.rst).  This document explains more fully how
  7 the requesting algorithm works.                     7 the requesting algorithm works.
  8                                                     8 
  9 The process starts by either the kernel reques      9 The process starts by either the kernel requesting a service by calling
 10 ``request_key*()``::                               10 ``request_key*()``::
 11                                                    11 
 12         struct key *request_key(const struct k     12         struct key *request_key(const struct key_type *type,
 13                                 const char *de     13                                 const char *description,
 14                                 const char *ca     14                                 const char *callout_info);
 15                                                    15 
 16 or::                                               16 or::
 17                                                    17 
 18         struct key *request_key_tag(const stru << 
 19                                     const char << 
 20                                     const stru << 
 21                                     const char << 
 22                                                << 
 23 or::                                           << 
 24                                                << 
 25         struct key *request_key_with_auxdata(c     18         struct key *request_key_with_auxdata(const struct key_type *type,
 26                                              c     19                                              const char *description,
 27                                              c << 
 28                                              c     20                                              const char *callout_info,
 29                                              s     21                                              size_t callout_len,
 30                                              v     22                                              void *aux);
 31                                                    23 
 32 or::                                               24 or::
 33                                                    25 
 34         struct key *request_key_rcu(const stru !!  26         struct key *request_key_async(const struct key_type *type,
 35                                     const char !!  27                                       const char *description,
 36                                     const stru !!  28                                       const char *callout_info,
                                                   >>  29                                       size_t callout_len);
                                                   >>  30 
                                                   >>  31 or::
                                                   >>  32 
                                                   >>  33         struct key *request_key_async_with_auxdata(const struct key_type *type,
                                                   >>  34                                                    const char *description,
                                                   >>  35                                                    const char *callout_info,
                                                   >>  36                                                    size_t callout_len,
                                                   >>  37                                                    void *aux);
 37                                                    38 
 38 Or by userspace invoking the request_key syste     39 Or by userspace invoking the request_key system call::
 39                                                    40 
 40         key_serial_t request_key(const char *t     41         key_serial_t request_key(const char *type,
 41                                  const char *d     42                                  const char *description,
 42                                  const char *c     43                                  const char *callout_info,
 43                                  key_serial_t      44                                  key_serial_t dest_keyring);
 44                                                    45 
 45 The main difference between the access points      46 The main difference between the access points is that the in-kernel interface
 46 does not need to link the key to a keyring to      47 does not need to link the key to a keyring to prevent it from being immediately
 47 destroyed.  The kernel interface returns a poi     48 destroyed.  The kernel interface returns a pointer directly to the key, and
 48 it's up to the caller to destroy the key.          49 it's up to the caller to destroy the key.
 49                                                    50 
 50 The request_key_tag() call is like the in-kern !!  51 The request_key*_with_auxdata() calls are like the in-kernel request_key*()
 51 also takes a domain tag that allows keys to be !!  52 calls, except that they permit auxiliary data to be passed to the upcaller (the
 52 killed off as a group.                         !!  53 default is NULL).  This is only useful for those key types that define their
 53                                                !!  54 own upcall mechanism rather than using /sbin/request-key.
 54 The request_key_with_auxdata() calls is like t !!  55 
 55 that they permit auxiliary data to be passed t !!  56 The two async in-kernel calls may return keys that are still in the process of
 56 NULL).  This is only useful for those key type !!  57 being constructed.  The two non-async ones will wait for construction to
 57 mechanism rather than using /sbin/request-key. !!  58 complete first.
 58                                                << 
 59 The request_key_rcu() call is like the request << 
 60 doesn't check for keys that are under construc << 
 61 construct missing keys.                        << 
 62                                                    59 
 63 The userspace interface links the key to a key     60 The userspace interface links the key to a keyring associated with the process
 64 to prevent the key from going away, and return     61 to prevent the key from going away, and returns the serial number of the key to
 65 the caller.                                        62 the caller.
 66                                                    63 
 67                                                    64 
 68 The following example assumes that the key typ     65 The following example assumes that the key types involved don't define their
 69 own upcall mechanisms.  If they do, then those     66 own upcall mechanisms.  If they do, then those should be substituted for the
 70 forking and execution of /sbin/request-key.        67 forking and execution of /sbin/request-key.
 71                                                    68 
 72                                                    69 
 73 The Process                                        70 The Process
 74 ===========                                        71 ===========
 75                                                    72 
 76 A request proceeds in the following manner:        73 A request proceeds in the following manner:
 77                                                    74 
 78   1) Process A calls request_key() [the usersp     75   1) Process A calls request_key() [the userspace syscall calls the kernel
 79      interface].                                   76      interface].
 80                                                    77 
 81   2) request_key() searches the process's subs     78   2) request_key() searches the process's subscribed keyrings to see if there's
 82      a suitable key there.  If there is, it re     79      a suitable key there.  If there is, it returns the key.  If there isn't,
 83      and callout_info is not set, an error is      80      and callout_info is not set, an error is returned.  Otherwise the process
 84      proceeds to the next step.                    81      proceeds to the next step.
 85                                                    82 
 86   3) request_key() sees that A doesn't have th     83   3) request_key() sees that A doesn't have the desired key yet, so it creates
 87      two things:                                   84      two things:
 88                                                    85 
 89       a) An uninstantiated key U of requested      86       a) An uninstantiated key U of requested type and description.
 90                                                    87 
 91       b) An authorisation key V that refers to     88       b) An authorisation key V that refers to key U and notes that process A
 92          is the context in which key U should      89          is the context in which key U should be instantiated and secured, and
 93          from which associated key requests ma     90          from which associated key requests may be satisfied.
 94                                                    91 
 95   4) request_key() then forks and executes /sb     92   4) request_key() then forks and executes /sbin/request-key with a new session
 96      keyring that contains a link to auth key      93      keyring that contains a link to auth key V.
 97                                                    94 
 98   5) /sbin/request-key assumes the authority a     95   5) /sbin/request-key assumes the authority associated with key U.
 99                                                    96 
100   6) /sbin/request-key execs an appropriate pr     97   6) /sbin/request-key execs an appropriate program to perform the actual
101      instantiation.                                98      instantiation.
102                                                    99 
103   7) The program may want to access another ke    100   7) The program may want to access another key from A's context (say a
104      Kerberos TGT key).  It just requests the     101      Kerberos TGT key).  It just requests the appropriate key, and the keyring
105      search notes that the session keyring has    102      search notes that the session keyring has auth key V in its bottom level.
106                                                   103 
107      This will permit it to then search the ke    104      This will permit it to then search the keyrings of process A with the
108      UID, GID, groups and security info of pro    105      UID, GID, groups and security info of process A as if it was process A,
109      and come up with key W.                      106      and come up with key W.
110                                                   107 
111   8) The program then does what it must to get    108   8) The program then does what it must to get the data with which to
112      instantiate key U, using key W as a refer    109      instantiate key U, using key W as a reference (perhaps it contacts a
113      Kerberos server using the TGT) and then i    110      Kerberos server using the TGT) and then instantiates key U.
114                                                   111 
115   9) Upon instantiating key U, auth key V is a    112   9) Upon instantiating key U, auth key V is automatically revoked so that it
116      may not be used again.                       113      may not be used again.
117                                                   114 
118   10) The program then exits 0 and request_key    115   10) The program then exits 0 and request_key() deletes key V and returns key
119       U to the caller.                            116       U to the caller.
120                                                   117 
121 This also extends further.  If key W (step 7 a    118 This also extends further.  If key W (step 7 above) didn't exist, key W would
122 be created uninstantiated, another auth key (X    119 be created uninstantiated, another auth key (X) would be created (as per step
123 3) and another copy of /sbin/request-key spawn    120 3) and another copy of /sbin/request-key spawned (as per step 4); but the
124 context specified by auth key X will still be     121 context specified by auth key X will still be process A, as it was in auth key
125 V.                                                122 V.
126                                                   123 
127 This is because process A's keyrings can't sim    124 This is because process A's keyrings can't simply be attached to
128 /sbin/request-key at the appropriate places be    125 /sbin/request-key at the appropriate places because (a) execve will discard two
129 of them, and (b) it requires the same UID/GID/    126 of them, and (b) it requires the same UID/GID/Groups all the way through.
130                                                   127 
131                                                   128 
132 Negative Instantiation And Rejection              129 Negative Instantiation And Rejection
133 ====================================              130 ====================================
134                                                   131 
135 Rather than instantiating a key, it is possibl    132 Rather than instantiating a key, it is possible for the possessor of an
136 authorisation key to negatively instantiate a     133 authorisation key to negatively instantiate a key that's under construction.
137 This is a short duration placeholder that caus    134 This is a short duration placeholder that causes any attempt at re-requesting
138 the key while it exists to fail with error ENO !! 135 the key whilst it exists to fail with error ENOKEY if negated or the specified
139 error if rejected.                                136 error if rejected.
140                                                   137 
141 This is provided to prevent excessive repeated    138 This is provided to prevent excessive repeated spawning of /sbin/request-key
142 processes for a key that will never be obtaina    139 processes for a key that will never be obtainable.
143                                                   140 
144 Should the /sbin/request-key process exit anyt    141 Should the /sbin/request-key process exit anything other than 0 or die on a
145 signal, the key under construction will be aut    142 signal, the key under construction will be automatically negatively
146 instantiated for a short amount of time.          143 instantiated for a short amount of time.
147                                                   144 
148                                                   145 
149 The Search Algorithm                              146 The Search Algorithm
150 ====================                              147 ====================
151                                                   148 
152 A search of any particular keyring proceeds in    149 A search of any particular keyring proceeds in the following fashion:
153                                                   150 
154   1) When the key management code searches for !! 151   1) When the key management code searches for a key (keyring_search_aux) it
155      firstly calls key_permission(SEARCH) on t    152      firstly calls key_permission(SEARCH) on the keyring it's starting with,
156      if this denies permission, it doesn't sea    153      if this denies permission, it doesn't search further.
157                                                   154 
158   2) It considers all the non-keyring keys wit    155   2) It considers all the non-keyring keys within that keyring and, if any key
159      matches the criteria specified, calls key    156      matches the criteria specified, calls key_permission(SEARCH) on it to see
160      if the key is allowed to be found.  If it    157      if the key is allowed to be found.  If it is, that key is returned; if
161      not, the search continues, and the error     158      not, the search continues, and the error code is retained if of higher
162      priority than the one currently set.         159      priority than the one currently set.
163                                                   160 
164   3) It then considers all the keyring-type ke    161   3) It then considers all the keyring-type keys in the keyring it's currently
165      searching.  It calls key_permission(SEARC    162      searching.  It calls key_permission(SEARCH) on each keyring, and if this
166      grants permission, it recurses, executing    163      grants permission, it recurses, executing steps (2) and (3) on that
167      keyring.                                     164      keyring.
168                                                   165 
169 The process stops immediately a valid key is f    166 The process stops immediately a valid key is found with permission granted to
170 use it.  Any error from a previous match attem    167 use it.  Any error from a previous match attempt is discarded and the key is
171 returned.                                         168 returned.
172                                                   169 
173 When request_key() is invoked, if CONFIG_KEYS_ << 
174 one-key cache is first checked for a match.    << 
175                                                << 
176 When search_process_keyrings() is invoked, it     170 When search_process_keyrings() is invoked, it performs the following searches
177 until one succeeds:                               171 until one succeeds:
178                                                   172 
179   1) If extant, the process's thread keyring i    173   1) If extant, the process's thread keyring is searched.
180                                                   174 
181   2) If extant, the process's process keyring     175   2) If extant, the process's process keyring is searched.
182                                                   176 
183   3) The process's session keyring is searched    177   3) The process's session keyring is searched.
184                                                   178 
185   4) If the process has assumed the authority     179   4) If the process has assumed the authority associated with a request_key()
186      authorisation key then:                      180      authorisation key then:
187                                                   181 
188       a) If extant, the calling process's thre    182       a) If extant, the calling process's thread keyring is searched.
189                                                   183 
190       b) If extant, the calling process's proc    184       b) If extant, the calling process's process keyring is searched.
191                                                   185 
192       c) The calling process's session keyring    186       c) The calling process's session keyring is searched.
193                                                   187 
194 The moment one succeeds, all pending errors ar    188 The moment one succeeds, all pending errors are discarded and the found key is
195 returned.  If CONFIG_KEYS_REQUEST_CACHE=y, the !! 189 returned.
196 per-task cache, displacing the previous key.   << 
197 just prior to resumption of userspace.         << 
198                                                   190 
199 Only if all these fail does the whole thing fa    191 Only if all these fail does the whole thing fail with the highest priority
200 error.  Note that several errors may have come    192 error.  Note that several errors may have come from LSM.
201                                                   193 
202 The error priority is::                           194 The error priority is::
203                                                   195 
204         EKEYREVOKED > EKEYEXPIRED > ENOKEY        196         EKEYREVOKED > EKEYEXPIRED > ENOKEY
205                                                   197 
206 EACCES/EPERM are only returned on a direct sea    198 EACCES/EPERM are only returned on a direct search of a specific keyring where
207 the basal keyring does not grant Search permis    199 the basal keyring does not grant Search permission.
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php