hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/security/keys/internal.h
....@@ -1,12 +1,8 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 /* Authentication token and access key management internal defs
23 *
34 * Copyright (C) 2003-5, 2007 Red Hat, Inc. All Rights Reserved.
45 * Written by David Howells (dhowells@redhat.com)
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License
8
- * as published by the Free Software Foundation; either version
9
- * 2 of the License, or (at your option) any later version.
106 */
117
128 #ifndef _INTERNAL_H
....@@ -19,6 +15,7 @@
1915 #include <linux/task_work.h>
2016 #include <linux/keyctl.h>
2117 #include <linux/refcount.h>
18
+#include <linux/watch_queue.h>
2219 #include <linux/compat.h>
2320 #include <linux/mm.h>
2421 #include <linux/vmalloc.h>
....@@ -91,15 +88,20 @@
9188 extern struct mutex key_construction_mutex;
9289 extern wait_queue_head_t request_key_conswq;
9390
94
-
91
+extern void key_set_index_key(struct keyring_index_key *index_key);
9592 extern struct key_type *key_type_lookup(const char *type);
9693 extern void key_type_put(struct key_type *ktype);
9794
95
+extern int __key_link_lock(struct key *keyring,
96
+ const struct keyring_index_key *index_key);
97
+extern int __key_move_lock(struct key *l_keyring, struct key *u_keyring,
98
+ const struct keyring_index_key *index_key);
9899 extern int __key_link_begin(struct key *keyring,
99100 const struct keyring_index_key *index_key,
100101 struct assoc_array_edit **_edit);
101102 extern int __key_link_check_live_key(struct key *keyring, struct key *key);
102
-extern void __key_link(struct key *key, struct assoc_array_edit **_edit);
103
+extern void __key_link(struct key *keyring, struct key *key,
104
+ struct assoc_array_edit **_edit);
103105 extern void __key_link_end(struct key *keyring,
104106 const struct keyring_index_key *index_key,
105107 struct assoc_array_edit *edit);
....@@ -125,6 +127,7 @@
125127 #define KEYRING_SEARCH_NO_CHECK_PERM 0x0008 /* Don't check permissions */
126128 #define KEYRING_SEARCH_DETECT_TOO_DEEP 0x0010 /* Give an error on excessive depth */
127129 #define KEYRING_SEARCH_SKIP_EXPIRED 0x0020 /* Ignore expired keys (intention to replace) */
130
+#define KEYRING_SEARCH_RECURSE 0x0040 /* Search child keyrings also */
128131
129132 int (*iterator)(const void *object, void *iterator_data);
130133
....@@ -137,21 +140,23 @@
137140
138141 extern bool key_default_cmp(const struct key *key,
139142 const struct key_match_data *match_data);
140
-extern key_ref_t keyring_search_aux(key_ref_t keyring_ref,
143
+extern key_ref_t keyring_search_rcu(key_ref_t keyring_ref,
141144 struct keyring_search_context *ctx);
142145
143
-extern key_ref_t search_my_process_keyrings(struct keyring_search_context *ctx);
144
-extern key_ref_t search_process_keyrings(struct keyring_search_context *ctx);
146
+extern key_ref_t search_cred_keyrings_rcu(struct keyring_search_context *ctx);
147
+extern key_ref_t search_process_keyrings_rcu(struct keyring_search_context *ctx);
145148
146149 extern struct key *find_keyring_by_name(const char *name, bool uid_keyring);
147150
148
-extern int install_user_keyrings(void);
151
+extern int look_up_user_keyrings(struct key **, struct key **);
152
+extern struct key *get_user_session_keyring_rcu(const struct cred *);
149153 extern int install_thread_keyring_to_cred(struct cred *);
150154 extern int install_process_keyring_to_cred(struct cred *);
151155 extern int install_session_keyring_to_cred(struct cred *, struct key *);
152156
153157 extern struct key *request_key_and_link(struct key_type *type,
154158 const char *description,
159
+ struct key_tag *domain_tag,
155160 const void *callout_info,
156161 size_t callout_len,
157162 void *aux,
....@@ -162,7 +167,6 @@
162167 const struct key_match_data *match_data);
163168 #define KEY_LOOKUP_CREATE 0x01
164169 #define KEY_LOOKUP_PARTIAL 0x02
165
-#define KEY_LOOKUP_FOR_UNLINK 0x04
166170
167171 extern long join_session_keyring(const char *name);
168172 extern void key_change_session_keyring(struct callback_head *twork);
....@@ -178,14 +182,32 @@
178182
179183 extern int key_task_permission(const key_ref_t key_ref,
180184 const struct cred *cred,
181
- key_perm_t perm);
185
+ enum key_need_perm need_perm);
186
+
187
+static inline void notify_key(struct key *key,
188
+ enum key_notification_subtype subtype, u32 aux)
189
+{
190
+#ifdef CONFIG_KEY_NOTIFICATIONS
191
+ struct key_notification n = {
192
+ .watch.type = WATCH_TYPE_KEY_NOTIFY,
193
+ .watch.subtype = subtype,
194
+ .watch.info = watch_sizeof(n),
195
+ .key_id = key_serial(key),
196
+ .aux = aux,
197
+ };
198
+
199
+ post_watch_notification(key->watchers, &n.watch, current_cred(),
200
+ n.key_id);
201
+#endif
202
+}
182203
183204 /*
184205 * Check to see whether permission is granted to use a key in the desired way.
185206 */
186
-static inline int key_permission(const key_ref_t key_ref, unsigned perm)
207
+static inline int key_permission(const key_ref_t key_ref,
208
+ enum key_need_perm need_perm)
187209 {
188
- return key_task_permission(key_ref, current_cred(), perm);
210
+ return key_task_permission(key_ref, current_cred(), need_perm);
189211 }
190212
191213 extern struct key_type key_type_request_key_auth;
....@@ -205,7 +227,8 @@
205227 return
206228 key->flags & ((1 << KEY_FLAG_DEAD) |
207229 (1 << KEY_FLAG_INVALIDATED)) ||
208
- (key->expiry > 0 && key->expiry <= limit);
230
+ (key->expiry > 0 && key->expiry <= limit) ||
231
+ key->domain_tag->removed;
209232 }
210233
211234 /*
....@@ -217,6 +240,7 @@
217240 extern long keyctl_revoke_key(key_serial_t);
218241 extern long keyctl_keyring_clear(key_serial_t);
219242 extern long keyctl_keyring_link(key_serial_t, key_serial_t);
243
+extern long keyctl_keyring_move(key_serial_t, key_serial_t, key_serial_t, unsigned int);
220244 extern long keyctl_keyring_unlink(key_serial_t, key_serial_t);
221245 extern long keyctl_describe_key(key_serial_t, char __user *, size_t);
222246 extern long keyctl_keyring_search(key_serial_t, const char __user *,
....@@ -238,11 +262,6 @@
238262 const struct iovec __user *,
239263 unsigned, key_serial_t);
240264 extern long keyctl_invalidate_key(key_serial_t);
241
-
242
-struct iov_iter;
243
-extern long keyctl_instantiate_key_common(key_serial_t,
244
- struct iov_iter *,
245
- key_serial_t);
246265 extern long keyctl_restrict_keyring(key_serial_t id,
247266 const char __user *_type,
248267 const char __user *_restriction);
....@@ -261,7 +280,7 @@
261280 size_t, struct keyctl_kdf_params __user *);
262281 extern long __keyctl_dh_compute(struct keyctl_dh_params __user *, char __user *,
263282 size_t, struct keyctl_kdf_params *);
264
-#ifdef CONFIG_KEYS_COMPAT
283
+#ifdef CONFIG_COMPAT
265284 extern long compat_keyctl_dh_compute(struct keyctl_dh_params __user *params,
266285 char __user *buffer, size_t buflen,
267286 struct compat_keyctl_kdf_params __user *kdf);
....@@ -276,7 +295,7 @@
276295 return -EOPNOTSUPP;
277296 }
278297
279
-#ifdef CONFIG_KEYS_COMPAT
298
+#ifdef CONFIG_COMPAT
280299 static inline long compat_keyctl_dh_compute(
281300 struct keyctl_dh_params __user *params,
282301 char __user *buffer, size_t buflen,
....@@ -287,6 +306,56 @@
287306 #endif
288307 #endif
289308
309
+#ifdef CONFIG_ASYMMETRIC_KEY_TYPE
310
+extern long keyctl_pkey_query(key_serial_t,
311
+ const char __user *,
312
+ struct keyctl_pkey_query __user *);
313
+
314
+extern long keyctl_pkey_verify(const struct keyctl_pkey_params __user *,
315
+ const char __user *,
316
+ const void __user *, const void __user *);
317
+
318
+extern long keyctl_pkey_e_d_s(int,
319
+ const struct keyctl_pkey_params __user *,
320
+ const char __user *,
321
+ const void __user *, void __user *);
322
+#else
323
+static inline long keyctl_pkey_query(key_serial_t id,
324
+ const char __user *_info,
325
+ struct keyctl_pkey_query __user *_res)
326
+{
327
+ return -EOPNOTSUPP;
328
+}
329
+
330
+static inline long keyctl_pkey_verify(const struct keyctl_pkey_params __user *params,
331
+ const char __user *_info,
332
+ const void __user *_in,
333
+ const void __user *_in2)
334
+{
335
+ return -EOPNOTSUPP;
336
+}
337
+
338
+static inline long keyctl_pkey_e_d_s(int op,
339
+ const struct keyctl_pkey_params __user *params,
340
+ const char __user *_info,
341
+ const void __user *_in,
342
+ void __user *_out)
343
+{
344
+ return -EOPNOTSUPP;
345
+}
346
+#endif
347
+
348
+extern long keyctl_capabilities(unsigned char __user *_buffer, size_t buflen);
349
+
350
+#ifdef CONFIG_KEY_NOTIFICATIONS
351
+extern long keyctl_watch_key(key_serial_t, int, int);
352
+#else
353
+static inline long keyctl_watch_key(key_serial_t key_id, int watch_fd, int watch_id)
354
+{
355
+ return -EOPNOTSUPP;
356
+}
357
+#endif
358
+
290359 /*
291360 * Debugging key validation
292361 */