Skip to content

Commit 8bbf497

Browse files
dhowellsxjamesmorris
authored andcommitted
KEYS: Alter use of key instantiation link-to-keyring argument
Alter the use of the key instantiation and negation functions' link-to-keyring arguments. Currently this specifies a keyring in the target process to link the key into, creating the keyring if it doesn't exist. This, however, can be a problem for copy-on-write credentials as it means that the instantiating process can alter the credentials of the requesting process. This patch alters the behaviour such that: (1) If keyctl_instantiate_key() or keyctl_negate_key() are given a specific keyring by ID (ringid >= 0), then that keyring will be used. (2) If keyctl_instantiate_key() or keyctl_negate_key() are given one of the special constants that refer to the requesting process's keyrings (KEY_SPEC_*_KEYRING, all <= 0), then: (a) If sys_request_key() was given a keyring to use (destringid) then the key will be attached to that keyring. (b) If sys_request_key() was given a NULL keyring, then the key being instantiated will be attached to the default keyring as set by keyctl_set_reqkey_keyring(). (3) No extra link will be made. Decision point (1) follows current behaviour, and allows those instantiators who've searched for a specifically named keyring in the requestor's keyring so as to partition the keys by type to still have their named keyrings. Decision point (2) allows the requestor to make sure that the key or keys that get produced by request_key() go where they want, whilst allowing the instantiator to request that the key is retained. This is mainly useful for situations where the instantiator makes a secondary request, the key for which should be retained by the initial requestor: +-----------+ +--------------+ +--------------+ | | | | | | | Requestor |------->| Instantiator |------->| Instantiator | | | | | | | +-----------+ +--------------+ +--------------+ request_key() request_key() This might be useful, for example, in Kerberos, where the requestor requests a ticket, and then the ticket instantiator requests the TGT, which someone else then has to go and fetch. The TGT, however, should be retained in the keyrings of the requestor, not the first instantiator. To make this explict an extra special keyring constant is also added. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: James Morris <jmorris@namei.org> Signed-off-by: James Morris <jmorris@namei.org>
1 parent e9e349b commit 8bbf497

8 files changed

Lines changed: 199 additions & 121 deletions

File tree

‎include/linux/key.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,11 @@ extern void key_fsuid_changed(struct task_struct *tsk);
287287
extern void key_fsgid_changed(struct task_struct *tsk);
288288
extern void key_init(void);
289289

290-
#define __install_session_keyring(tsk, keyring) \
291-
({ \
292-
struct key *old_session = tsk->signal->session_keyring; \
293-
tsk->signal->session_keyring = keyring; \
294-
old_session; \
290+
#define __install_session_keyring(keyring) \
291+
({ \
292+
struct key *old_session = current->signal->session_keyring; \
293+
current->signal->session_keyring = keyring; \
294+
old_session; \
295295
})
296296

297297
#else /* CONFIG_KEYS */
@@ -302,11 +302,11 @@ extern void key_init(void);
302302
#define key_revoke(k) do { } while(0)
303303
#define key_put(k) do { } while(0)
304304
#define key_ref_put(k) do { } while(0)
305-
#define make_key_ref(k, p) ({ NULL; })
306-
#define key_ref_to_ptr(k) ({ NULL; })
305+
#define make_key_ref(k, p) NULL
306+
#define key_ref_to_ptr(k) NULL
307307
#define is_key_possessed(k) 0
308308
#define switch_uid_keyring(u) do { } while(0)
309-
#define __install_session_keyring(t, k) ({ NULL; })
309+
#define __install_session_keyring(k) ({ NULL; })
310310
#define copy_keys(f,t) 0
311311
#define copy_thread_group_keys(t) 0
312312
#define exit_keys(t) do { } while(0)

‎include/linux/keyctl.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* keyctl.h: keyctl command IDs
22
*
3-
* Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
3+
* Copyright (C) 2004, 2008 Red Hat, Inc. All Rights Reserved.
44
* Written by David Howells (dhowells@redhat.com)
55
*
66
* This program is free software; you can redistribute it and/or
@@ -20,6 +20,7 @@
2020
#define KEY_SPEC_USER_SESSION_KEYRING -5 /* - key ID for UID-session keyring */
2121
#define KEY_SPEC_GROUP_KEYRING -6 /* - key ID for GID-specific keyring */
2222
#define KEY_SPEC_REQKEY_AUTH_KEY -7 /* - key ID for assumed request_key auth key */
23+
#define KEY_SPEC_REQUESTOR_KEYRING -8 /* - key ID for request_key() dest keyring */
2324

2425
/* request-key default keyrings */
2526
#define KEY_REQKEY_DEFL_NO_CHANGE -1
@@ -30,6 +31,7 @@
3031
#define KEY_REQKEY_DEFL_USER_KEYRING 4
3132
#define KEY_REQKEY_DEFL_USER_SESSION_KEYRING 5
3233
#define KEY_REQKEY_DEFL_GROUP_KEYRING 6
34+
#define KEY_REQKEY_DEFL_REQUESTOR_KEYRING 7
3335

3436
/* keyctl commands */
3537
#define KEYCTL_GET_KEYRING_ID 0 /* ask for a keyring's ID */

‎kernel/kmod.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static int ____call_usermodehelper(void *data)
140140
/* Unblock all signals and set the session keyring. */
141141
new_session = key_get(sub_info->ring);
142142
spin_lock_irq(&current->sighand->siglock);
143-
old_session = __install_session_keyring(current, new_session);
143+
old_session = __install_session_keyring(new_session);
144144
flush_signal_handlers(current, 1);
145145
sigemptyset(&current->blocked);
146146
recalc_sigpending();

‎security/keys/internal.h‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ extern key_ref_t search_process_keyrings(struct key_type *type,
109109

110110
extern struct key *find_keyring_by_name(const char *name, bool skip_perm_check);
111111

112-
extern int install_thread_keyring(struct task_struct *tsk);
113-
extern int install_process_keyring(struct task_struct *tsk);
112+
extern int install_user_keyrings(void);
113+
extern int install_thread_keyring(void);
114+
extern int install_process_keyring(void);
114115

115116
extern struct key *request_key_and_link(struct key_type *type,
116117
const char *description,
@@ -120,8 +121,7 @@ extern struct key *request_key_and_link(struct key_type *type,
120121
struct key *dest_keyring,
121122
unsigned long flags);
122123

123-
extern key_ref_t lookup_user_key(struct task_struct *context,
124-
key_serial_t id, int create, int partial,
124+
extern key_ref_t lookup_user_key(key_serial_t id, int create, int partial,
125125
key_perm_t perm);
126126

127127
extern long join_session_keyring(const char *name);
@@ -152,6 +152,7 @@ static inline int key_permission(const key_ref_t key_ref, key_perm_t perm)
152152
*/
153153
struct request_key_auth {
154154
struct key *target_key;
155+
struct key *dest_keyring;
155156
struct task_struct *context;
156157
void *callout_info;
157158
size_t callout_len;
@@ -161,7 +162,8 @@ struct request_key_auth {
161162
extern struct key_type key_type_request_key_auth;
162163
extern struct key *request_key_auth_new(struct key *target,
163164
const void *callout_info,
164-
size_t callout_len);
165+
size_t callout_len,
166+
struct key *dest_keyring);
165167

166168
extern struct key *key_get_instantiation_authkey(key_serial_t target_id);
167169

0 commit comments

Comments
 (0)