33 ===================
44
55The key request service is part of the key retention service (refer to
6- Documentation/keys.txt). This document explains more fully how that the
7- requesting algorithm works.
6+ Documentation/keys.txt). This document explains more fully how the requesting
7+ algorithm works.
88
99The process starts by either the kernel requesting a service by calling
10- request_key():
10+ request_key* ():
1111
1212 struct key *request_key(const struct key_type *type,
1313 const char *description,
1414 const char *callout_string);
1515
16+ or:
17+
18+ struct key *request_key_with_auxdata(const struct key_type *type,
19+ const char *description,
20+ const char *callout_string,
21+ void *aux);
22+
1623Or by userspace invoking the request_key system call:
1724
1825 key_serial_t request_key(const char *type,
1926 const char *description,
2027 const char *callout_info,
2128 key_serial_t dest_keyring);
2229
23- The main difference between the two access points is that the in-kernel
24- interface does not need to link the key to a keyring to prevent it from being
25- immediately destroyed. The kernel interface returns a pointer directly to the
26- key, and it's up to the caller to destroy the key.
30+ The main difference between the access points is that the in-kernel interface
31+ does not need to link the key to a keyring to prevent it from being immediately
32+ destroyed. The kernel interface returns a pointer directly to the key, and
33+ it's up to the caller to destroy the key.
34+
35+ The request_key_with_auxdata() call is like the in-kernel request_key() call,
36+ except that it permits auxiliary data to be passed to the upcaller (the default
37+ is NULL). This is only useful for those key types that define their own upcall
38+ mechanism rather than using /sbin/request-key.
2739
2840The userspace interface links the key to a keyring associated with the process
2941to prevent the key from going away, and returns the serial number of the key to
3042the caller.
3143
3244
45+ The following example assumes that the key types involved don't define their
46+ own upcall mechanisms. If they do, then those should be substituted for the
47+ forking and execution of /sbin/request-key.
48+
49+
3350===========
3451THE PROCESS
3552===========
@@ -40,8 +57,8 @@ A request proceeds in the following manner:
4057 interface].
4158
4259 (2) request_key() searches the process's subscribed keyrings to see if there's
43- a suitable key there. If there is, it returns the key. If there isn't, and
44- callout_info is not set, an error is returned. Otherwise the process
60+ a suitable key there. If there is, it returns the key. If there isn't,
61+ and callout_info is not set, an error is returned. Otherwise the process
4562 proceeds to the next step.
4663
4764 (3) request_key() sees that A doesn't have the desired key yet, so it creates
@@ -62,7 +79,7 @@ A request proceeds in the following manner:
6279 instantiation.
6380
6481 (7) The program may want to access another key from A's context (say a
65- Kerberos TGT key). It just requests the appropriate key, and the keyring
82+ Kerberos TGT key). It just requests the appropriate key, and the keyring
6683 search notes that the session keyring has auth key V in its bottom level.
6784
6885 This will permit it to then search the keyrings of process A with the
@@ -79,10 +96,11 @@ A request proceeds in the following manner:
7996(10) The program then exits 0 and request_key() deletes key V and returns key
8097 U to the caller.
8198
82- This also extends further. If key W (step 7 above) didn't exist, key W would be
83- created uninstantiated, another auth key (X) would be created (as per step 3)
84- and another copy of /sbin/request-key spawned (as per step 4); but the context
85- specified by auth key X will still be process A, as it was in auth key V.
99+ This also extends further. If key W (step 7 above) didn't exist, key W would
100+ be created uninstantiated, another auth key (X) would be created (as per step
101+ 3) and another copy of /sbin/request-key spawned (as per step 4); but the
102+ context specified by auth key X will still be process A, as it was in auth key
103+ V.
86104
87105This is because process A's keyrings can't simply be attached to
88106/sbin/request-key at the appropriate places because (a) execve will discard two
@@ -118,17 +136,17 @@ A search of any particular keyring proceeds in the following fashion:
118136
119137 (2) It considers all the non-keyring keys within that keyring and, if any key
120138 matches the criteria specified, calls key_permission(SEARCH) on it to see
121- if the key is allowed to be found. If it is, that key is returned; if
139+ if the key is allowed to be found. If it is, that key is returned; if
122140 not, the search continues, and the error code is retained if of higher
123141 priority than the one currently set.
124142
125143 (3) It then considers all the keyring-type keys in the keyring it's currently
126- searching. It calls key_permission(SEARCH) on each keyring, and if this
144+ searching. It calls key_permission(SEARCH) on each keyring, and if this
127145 grants permission, it recurses, executing steps (2) and (3) on that
128146 keyring.
129147
130148The process stops immediately a valid key is found with permission granted to
131- use it. Any error from a previous match attempt is discarded and the key is
149+ use it. Any error from a previous match attempt is discarded and the key is
132150returned.
133151
134152When search_process_keyrings() is invoked, it performs the following searches
@@ -153,7 +171,7 @@ The moment one succeeds, all pending errors are discarded and the found key is
153171returned.
154172
155173Only if all these fail does the whole thing fail with the highest priority
156- error. Note that several errors may have come from LSM.
174+ error. Note that several errors may have come from LSM.
157175
158176The error priority is:
159177
0 commit comments