aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cred.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/cred.c')
-rw-r--r--kernel/cred.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/kernel/cred.c b/kernel/cred.c
index cb6b5eda978d..e6fcdd67b2ec 100644
--- a/kernel/cred.c
+++ b/kernel/cred.c
@@ -68,7 +68,7 @@ static void release_tgcred_rcu(struct rcu_head *rcu)
68/* 68/*
69 * Release a set of thread group credentials. 69 * Release a set of thread group credentials.
70 */ 70 */
71void release_tgcred(struct cred *cred) 71static void release_tgcred(struct cred *cred)
72{ 72{
73#ifdef CONFIG_KEYS 73#ifdef CONFIG_KEYS
74 struct thread_group_cred *tgcred = cred->tgcred; 74 struct thread_group_cred *tgcred = cred->tgcred;
@@ -164,6 +164,50 @@ error:
164EXPORT_SYMBOL(prepare_creds); 164EXPORT_SYMBOL(prepare_creds);
165 165
166/* 166/*
167 * Prepare credentials for current to perform an execve()
168 * - The caller must hold current->cred_exec_mutex
169 */
170struct cred *prepare_exec_creds(void)
171{
172 struct thread_group_cred *tgcred = NULL;
173 struct cred *new;
174
175#ifdef CONFIG_KEYS
176 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
177 if (!tgcred)
178 return NULL;
179#endif
180
181 new = prepare_creds();
182 if (!new) {
183 kfree(tgcred);
184 return new;
185 }
186
187#ifdef CONFIG_KEYS
188 /* newly exec'd tasks don't get a thread keyring */
189 key_put(new->thread_keyring);
190 new->thread_keyring = NULL;
191
192 /* create a new per-thread-group creds for all this set of threads to
193 * share */
194 memcpy(tgcred, new->tgcred, sizeof(struct thread_group_cred));
195
196 atomic_set(&tgcred->usage, 1);
197 spin_lock_init(&tgcred->lock);
198
199 /* inherit the session keyring; new process keyring */
200 key_get(tgcred->session_keyring);
201 tgcred->process_keyring = NULL;
202
203 release_tgcred(new);
204 new->tgcred = tgcred;
205#endif
206
207 return new;
208}
209
210/*
167 * prepare new credentials for the usermode helper dispatcher 211 * prepare new credentials for the usermode helper dispatcher
168 */ 212 */
169struct cred *prepare_usermodehelper_creds(void) 213struct cred *prepare_usermodehelper_creds(void)