diff options
Diffstat (limited to 'kernel/cred.c')
-rw-r--r-- | kernel/cred.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/kernel/cred.c b/kernel/cred.c index b8bd2f99d8ce..f3ca10660617 100644 --- a/kernel/cred.c +++ b/kernel/cred.c | |||
@@ -35,7 +35,7 @@ static struct thread_group_cred init_tgcred = { | |||
35 | * The initial credentials for the initial task | 35 | * The initial credentials for the initial task |
36 | */ | 36 | */ |
37 | struct cred init_cred = { | 37 | struct cred init_cred = { |
38 | .usage = ATOMIC_INIT(3), | 38 | .usage = ATOMIC_INIT(4), |
39 | .securebits = SECUREBITS_DEFAULT, | 39 | .securebits = SECUREBITS_DEFAULT, |
40 | .cap_inheritable = CAP_INIT_INH_SET, | 40 | .cap_inheritable = CAP_INIT_INH_SET, |
41 | .cap_permitted = CAP_FULL_SET, | 41 | .cap_permitted = CAP_FULL_SET, |
@@ -120,6 +120,8 @@ EXPORT_SYMBOL(__put_cred); | |||
120 | * prepare a new copy, which the caller then modifies and then commits by | 120 | * prepare a new copy, which the caller then modifies and then commits by |
121 | * calling commit_creds(). | 121 | * calling commit_creds(). |
122 | * | 122 | * |
123 | * Preparation involves making a copy of the objective creds for modification. | ||
124 | * | ||
123 | * Returns a pointer to the new creds-to-be if successful, NULL otherwise. | 125 | * Returns a pointer to the new creds-to-be if successful, NULL otherwise. |
124 | * | 126 | * |
125 | * Call commit_creds() or abort_creds() to clean up. | 127 | * Call commit_creds() or abort_creds() to clean up. |
@@ -130,7 +132,7 @@ struct cred *prepare_creds(void) | |||
130 | const struct cred *old; | 132 | const struct cred *old; |
131 | struct cred *new; | 133 | struct cred *new; |
132 | 134 | ||
133 | BUG_ON(atomic_read(&task->cred->usage) < 1); | 135 | BUG_ON(atomic_read(&task->real_cred->usage) < 1); |
134 | 136 | ||
135 | new = kmem_cache_alloc(cred_jar, GFP_KERNEL); | 137 | new = kmem_cache_alloc(cred_jar, GFP_KERNEL); |
136 | if (!new) | 138 | if (!new) |
@@ -262,6 +264,9 @@ error: | |||
262 | * | 264 | * |
263 | * We share if we can, but under some circumstances we have to generate a new | 265 | * We share if we can, but under some circumstances we have to generate a new |
264 | * set. | 266 | * set. |
267 | * | ||
268 | * The new process gets the current process's subjective credentials as its | ||
269 | * objective and subjective credentials | ||
265 | */ | 270 | */ |
266 | int copy_creds(struct task_struct *p, unsigned long clone_flags) | 271 | int copy_creds(struct task_struct *p, unsigned long clone_flags) |
267 | { | 272 | { |
@@ -278,6 +283,7 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags) | |||
278 | #endif | 283 | #endif |
279 | clone_flags & CLONE_THREAD | 284 | clone_flags & CLONE_THREAD |
280 | ) { | 285 | ) { |
286 | p->real_cred = get_cred(p->cred); | ||
281 | get_cred(p->cred); | 287 | get_cred(p->cred); |
282 | atomic_inc(&p->cred->user->processes); | 288 | atomic_inc(&p->cred->user->processes); |
283 | return 0; | 289 | return 0; |
@@ -317,7 +323,7 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags) | |||
317 | #endif | 323 | #endif |
318 | 324 | ||
319 | atomic_inc(&new->user->processes); | 325 | atomic_inc(&new->user->processes); |
320 | p->cred = new; | 326 | p->cred = p->real_cred = get_cred(new); |
321 | return 0; | 327 | return 0; |
322 | } | 328 | } |
323 | 329 | ||
@@ -326,7 +332,9 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags) | |||
326 | * @new: The credentials to be assigned | 332 | * @new: The credentials to be assigned |
327 | * | 333 | * |
328 | * Install a new set of credentials to the current task, using RCU to replace | 334 | * Install a new set of credentials to the current task, using RCU to replace |
329 | * the old set. | 335 | * the old set. Both the objective and the subjective credentials pointers are |
336 | * updated. This function may not be called if the subjective credentials are | ||
337 | * in an overridden state. | ||
330 | * | 338 | * |
331 | * This function eats the caller's reference to the new credentials. | 339 | * This function eats the caller's reference to the new credentials. |
332 | * | 340 | * |
@@ -338,12 +346,15 @@ int commit_creds(struct cred *new) | |||
338 | struct task_struct *task = current; | 346 | struct task_struct *task = current; |
339 | const struct cred *old; | 347 | const struct cred *old; |
340 | 348 | ||
349 | BUG_ON(task->cred != task->real_cred); | ||
350 | BUG_ON(atomic_read(&task->real_cred->usage) < 2); | ||
341 | BUG_ON(atomic_read(&new->usage) < 1); | 351 | BUG_ON(atomic_read(&new->usage) < 1); |
342 | BUG_ON(atomic_read(&task->cred->usage) < 1); | ||
343 | 352 | ||
344 | old = task->cred; | 353 | old = task->real_cred; |
345 | security_commit_creds(new, old); | 354 | security_commit_creds(new, old); |
346 | 355 | ||
356 | get_cred(new); /* we will require a ref for the subj creds too */ | ||
357 | |||
347 | /* dumpability changes */ | 358 | /* dumpability changes */ |
348 | if (old->euid != new->euid || | 359 | if (old->euid != new->euid || |
349 | old->egid != new->egid || | 360 | old->egid != new->egid || |
@@ -369,6 +380,7 @@ int commit_creds(struct cred *new) | |||
369 | */ | 380 | */ |
370 | if (new->user != old->user) | 381 | if (new->user != old->user) |
371 | atomic_inc(&new->user->processes); | 382 | atomic_inc(&new->user->processes); |
383 | rcu_assign_pointer(task->real_cred, new); | ||
372 | rcu_assign_pointer(task->cred, new); | 384 | rcu_assign_pointer(task->cred, new); |
373 | if (new->user != old->user) | 385 | if (new->user != old->user) |
374 | atomic_dec(&old->user->processes); | 386 | atomic_dec(&old->user->processes); |
@@ -388,6 +400,8 @@ int commit_creds(struct cred *new) | |||
388 | new->fsgid != old->fsgid) | 400 | new->fsgid != old->fsgid) |
389 | proc_id_connector(task, PROC_EVENT_GID); | 401 | proc_id_connector(task, PROC_EVENT_GID); |
390 | 402 | ||
403 | /* release the old obj and subj refs both */ | ||
404 | put_cred(old); | ||
391 | put_cred(old); | 405 | put_cred(old); |
392 | return 0; | 406 | return 0; |
393 | } | 407 | } |
@@ -408,11 +422,11 @@ void abort_creds(struct cred *new) | |||
408 | EXPORT_SYMBOL(abort_creds); | 422 | EXPORT_SYMBOL(abort_creds); |
409 | 423 | ||
410 | /** | 424 | /** |
411 | * override_creds - Temporarily override the current process's credentials | 425 | * override_creds - Override the current process's subjective credentials |
412 | * @new: The credentials to be assigned | 426 | * @new: The credentials to be assigned |
413 | * | 427 | * |
414 | * Install a set of temporary override credentials on the current process, | 428 | * Install a set of temporary override subjective credentials on the current |
415 | * returning the old set for later reversion. | 429 | * process, returning the old set for later reversion. |
416 | */ | 430 | */ |
417 | const struct cred *override_creds(const struct cred *new) | 431 | const struct cred *override_creds(const struct cred *new) |
418 | { | 432 | { |
@@ -424,11 +438,11 @@ const struct cred *override_creds(const struct cred *new) | |||
424 | EXPORT_SYMBOL(override_creds); | 438 | EXPORT_SYMBOL(override_creds); |
425 | 439 | ||
426 | /** | 440 | /** |
427 | * revert_creds - Revert a temporary credentials override | 441 | * revert_creds - Revert a temporary subjective credentials override |
428 | * @old: The credentials to be restored | 442 | * @old: The credentials to be restored |
429 | * | 443 | * |
430 | * Revert a temporary set of override credentials to an old set, discarding the | 444 | * Revert a temporary set of override subjective credentials to an old set, |
431 | * override set. | 445 | * discarding the override set. |
432 | */ | 446 | */ |
433 | void revert_creds(const struct cred *old) | 447 | void revert_creds(const struct cred *old) |
434 | { | 448 | { |