| @@ -31,6 +31,7 @@ typedef int32_t key_serial_t; · 30 unmodified lines |
| 31 | typedef uint32_t key_perm_t; | 31 | typedef uint32_t key_perm_t; |
| 32 | | 32 | |
| 33 | struct key; | 33 | struct key; |
| | 34 | struct net; |
| 34 | | 35 | |
| 35 | #ifdef CONFIG_KEYS | 36 | #ifdef CONFIG_KEYS |
| 36 | | 37 | |
| @@ -77,13 +78,34 @@ struct cred; · 40 unmodified lines |
| 77 | | 78 | |
| 78 | struct key_type; | 79 | struct key_type; |
| 79 | struct key_owner; | 80 | struct key_owner; |
| | 81 | struct key_tag; |
| 80 | struct keyring_list; | 82 | struct keyring_list; |
| 81 | struct keyring_name; | 83 | struct keyring_name; |
| 82 | | 84 | |
| | 85 | struct key_tag { |
| | 86 | struct rcu_head rcu; |
| | 87 | refcount_t usage; |
| | 88 | bool removed; /* T when subject removed */ |
| | 89 | }; |
| | 90 | |
| 83 | struct keyring_index_key { | 91 | struct keyring_index_key { |
| | 92 | /* [!] If this structure is altered, the union in struct key must change too! */ |
| | 93 | unsigned long hash; /* Hash value */ |
| | 94 | union { |
| | 95 | struct { |
| | 96 | #ifdef __LITTLE_ENDIAN /* Put desc_len at the LSB of x */ |
| | 97 | u8 desc_len; |
| | 98 | char desc[sizeof(long) - 1]; /* First few chars of description */ |
| | 99 | #else |
| | 100 | char desc[sizeof(long) - 1]; /* First few chars of description */ |
| | 101 | u8 desc_len; |
| | 102 | #endif |
| | 103 | }; |
| | 104 | unsigned long x; |
| | 105 | }; |
| 84 | struct key_type *type; | 106 | struct key_type *type; |
| | 107 | struct key_tag *domain_tag; /* Domain of operation */ |
| 85 | const char *description; | 108 | const char *description; |
| 86 | size_t desc_len; | | |
| 87 | }; | 109 | }; |
| 88 | | 110 | |
| 89 | union key_payload { | 111 | union key_payload { |
| @@ -197,7 +219,10 @@ struct key { · 107 unmodified lines |
| 197 | union { | 219 | union { |
| 198 | struct keyring_index_key index_key; | 220 | struct keyring_index_key index_key; |
| 199 | struct { | 221 | struct { |
| | 222 | unsigned long hash; |
| | 223 | unsigned long len_desc; |
| 200 | struct key_type *type; /* type of key */ | 224 | struct key_type *type; /* type of key */ |
| | 225 | struct key_tag *domain_tag; /* Domain of operation */ |
| 201 | char *description; | 226 | char *description; |
| 202 | }; | 227 | }; |
| 203 | }; | 228 | }; |
| @@ -248,6 +273,8 @@ extern struct key *key_alloc(struct key_type *type, · 44 unmodified lines |
| 248 | extern void key_revoke(struct key *key); | 273 | extern void key_revoke(struct key *key); |
| 249 | extern void key_invalidate(struct key *key); | 274 | extern void key_invalidate(struct key *key); |
| 250 | extern void key_put(struct key *key); | 275 | extern void key_put(struct key *key); |
| | 276 | extern bool key_put_tag(struct key_tag *tag); |
| | 277 | extern void key_remove_domain(struct key_tag *domain_tag); |
| 251 | | 278 | |
| 252 | static inline struct key *__key_get(struct key *key) | 279 | static inline struct key *__key_get(struct key *key) |
| 253 | { | 280 | { |
| @@ -265,19 +292,57 @@ static inline void key_ref_put(key_ref_t key_ref) · 11 unmodified lines |
| 265 | key_put(key_ref_to_ptr(key_ref)); | 292 | key_put(key_ref_to_ptr(key_ref)); |
| 266 | } | 293 | } |
| 267 | | 294 | |
| 268 | extern struct key *request_key(struct key_type *type, | 295 | extern struct key *request_key_tag(struct key_type *type, |
| 269 | const char *description, | 296 | const char *description, |
| 270 | const char *callout_info); | 297 | struct key_tag *domain_tag, |
| | 298 | const char *callout_info); |
| 271 | | 299 | |
| 272 | extern struct key *request_key_rcu(struct key_type *type, | 300 | extern struct key *request_key_rcu(struct key_type *type, |
| 273 | const char *description); | 301 | const char *description, |
| | 302 | struct key_tag *domain_tag); |
| 274 | | 303 | |
| 275 | extern struct key *request_key_with_auxdata(struct key_type *type, | 304 | extern struct key *request_key_with_auxdata(struct key_type *type, |
| 276 | const char *description, | 305 | const char *description, |
| | 306 | struct key_tag *domain_tag, |
| 277 | const void *callout_info, | 307 | const void *callout_info, |
| 278 | size_t callout_len, | 308 | size_t callout_len, |
| 279 | void *aux); | 309 | void *aux); |
| 280 | | 310 | |
| | 311 | /** |
| | 312 | * request_key - Request a key and wait for construction |
| | 313 | * @type: Type of key. |
| | 314 | * @description: The searchable description of the key. |
| | 315 | * @callout_info: The data to pass to the instantiation upcall (or NULL). |
| | 316 | * |
| | 317 | * As for request_key_tag(), but with the default global domain tag. |
| | 318 | */ |
| | 319 | static inline struct key *request_key(struct key_type *type, |
| | 320 | const char *description, |
| | 321 | const char *callout_info) |
| | 322 | { |
| | 323 | return request_key_tag(type, description, NULL, callout_info); |
| | 324 | } |
| | 325 | |
| | 326 | #ifdef CONFIG_NET |
| | 327 | /* |
| | 328 | * request_key_net - Request a key for a net namespace and wait for construction |
| | 329 | * @type: Type of key. |
| | 330 | * @description: The searchable description of the key. |
| | 331 | * @net: The network namespace that is the key's domain of operation. |
| | 332 | * @callout_info: The data to pass to the instantiation upcall (or NULL). |
| | 333 | * |
| | 334 | * As for request_key() except that it does not add the returned key to a |
| | 335 | * keyring if found, new keys are always allocated in the user's quota, the |
| | 336 | * callout_info must be a NUL-terminated string and no auxiliary data can be |
| | 337 | * passed. Only keys that operate the specified network namespace are used. |
| | 338 | * |
| | 339 | * Furthermore, it then works as wait_for_key_construction() to wait for the |
| | 340 | * completion of keys undergoing construction with a non-interruptible wait. |
| | 341 | */ |
| | 342 | #define request_key_net(type, description, net, callout_info) \ |
| | 343 | request_key_tag(type, description, net->key_domain, callout_info); |
| | 344 | #endif /* CONFIG_NET */ |
| | 345 | |
| 281 | extern int wait_for_key_construction(struct key *key, bool intr); | 346 | extern int wait_for_key_construction(struct key *key, bool intr); |
| 282 | | 347 | |
| 283 | extern int key_validate(const struct key *key); | 348 | extern int key_validate(const struct key *key); |
| @@ -321,7 +386,8 @@ extern int keyring_clear(struct key *keyring); · 37 unmodified lines |
| 321 | | 386 | |
| 322 | extern key_ref_t keyring_search(key_ref_t keyring, | 387 | extern key_ref_t keyring_search(key_ref_t keyring, |
| 323 | struct key_type *type, | 388 | struct key_type *type, |
| 324 | const char *description); | 389 | const char *description, |
| | 390 | bool recurse); |
| 325 | | 391 | |
| 326 | extern int keyring_add_key(struct key *keyring, | 392 | extern int keyring_add_key(struct key *keyring, |
| 327 | struct key *key); | 393 | struct key *key); |
| @@ -340,6 +406,7 @@ extern void key_set_timeout(struct key *, unsigned); · 12 unmodified lines |
| 340 | | 406 | |
| 341 | extern key_ref_t lookup_user_key(key_serial_t id, unsigned long flags, | 407 | extern key_ref_t lookup_user_key(key_serial_t id, unsigned long flags, |
| 342 | key_perm_t perm); | 408 | key_perm_t perm); |
| | 409 | extern void key_free_user_ns(struct user_namespace *); |
| 343 | | 410 | |
| 344 | /* | 411 | /* |
| 345 | * The permissions required on a key that we're looking up. | 412 | * The permissions required on a key that we're looking up. |
| @@ -413,6 +480,8 @@ extern void key_init(void); · 67 unmodified lines |
| 413 | #define key_fsuid_changed(c) do { } while(0) | 480 | #define key_fsuid_changed(c) do { } while(0) |
| 414 | #define key_fsgid_changed(c) do { } while(0) | 481 | #define key_fsgid_changed(c) do { } while(0) |
| 415 | #define key_init() do { } while(0) | 482 | #define key_init() do { } while(0) |
| | 483 | #define key_free_user_ns(ns) do { } while(0) |
| | 484 | #define key_remove_domain(d) do { } while(0) |
| 416 | | 485 | |
| 417 | #endif /* CONFIG_KEYS */ | 486 | #endif /* CONFIG_KEYS */ |
| 418 | #endif /* __KERNEL__ */ | 487 | #endif /* __KERNEL__ */ |