diff options
Diffstat (limited to 'kernel/cred.c')
| -rw-r--r-- | kernel/cred.c | 315 |
1 files changed, 308 insertions, 7 deletions
diff --git a/kernel/cred.c b/kernel/cred.c index 1bb4d7e5d616..dd76cfe5f5b0 100644 --- a/kernel/cred.c +++ b/kernel/cred.c | |||
| @@ -18,6 +18,18 @@ | |||
| 18 | #include <linux/cn_proc.h> | 18 | #include <linux/cn_proc.h> |
| 19 | #include "cred-internals.h" | 19 | #include "cred-internals.h" |
| 20 | 20 | ||
| 21 | #if 0 | ||
| 22 | #define kdebug(FMT, ...) \ | ||
| 23 | printk("[%-5.5s%5u] "FMT"\n", current->comm, current->pid ,##__VA_ARGS__) | ||
| 24 | #else | ||
| 25 | static inline __attribute__((format(printf, 1, 2))) | ||
| 26 | void no_printk(const char *fmt, ...) | ||
| 27 | { | ||
| 28 | } | ||
| 29 | #define kdebug(FMT, ...) \ | ||
| 30 | no_printk("[%-5.5s%5u] "FMT"\n", current->comm, current->pid ,##__VA_ARGS__) | ||
| 31 | #endif | ||
| 32 | |||
| 21 | static struct kmem_cache *cred_jar; | 33 | static struct kmem_cache *cred_jar; |
| 22 | 34 | ||
| 23 | /* | 35 | /* |
| @@ -36,6 +48,10 @@ static struct thread_group_cred init_tgcred = { | |||
| 36 | */ | 48 | */ |
| 37 | struct cred init_cred = { | 49 | struct cred init_cred = { |
| 38 | .usage = ATOMIC_INIT(4), | 50 | .usage = ATOMIC_INIT(4), |
| 51 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 52 | .subscribers = ATOMIC_INIT(2), | ||
| 53 | .magic = CRED_MAGIC, | ||
| 54 | #endif | ||
| 39 | .securebits = SECUREBITS_DEFAULT, | 55 | .securebits = SECUREBITS_DEFAULT, |
| 40 | .cap_inheritable = CAP_INIT_INH_SET, | 56 | .cap_inheritable = CAP_INIT_INH_SET, |
| 41 | .cap_permitted = CAP_FULL_SET, | 57 | .cap_permitted = CAP_FULL_SET, |
| @@ -48,6 +64,31 @@ struct cred init_cred = { | |||
| 48 | #endif | 64 | #endif |
| 49 | }; | 65 | }; |
| 50 | 66 | ||
| 67 | static inline void set_cred_subscribers(struct cred *cred, int n) | ||
| 68 | { | ||
| 69 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 70 | atomic_set(&cred->subscribers, n); | ||
| 71 | #endif | ||
| 72 | } | ||
| 73 | |||
| 74 | static inline int read_cred_subscribers(const struct cred *cred) | ||
| 75 | { | ||
| 76 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 77 | return atomic_read(&cred->subscribers); | ||
| 78 | #else | ||
| 79 | return 0; | ||
| 80 | #endif | ||
| 81 | } | ||
| 82 | |||
| 83 | static inline void alter_cred_subscribers(const struct cred *_cred, int n) | ||
| 84 | { | ||
| 85 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 86 | struct cred *cred = (struct cred *) _cred; | ||
| 87 | |||
| 88 | atomic_add(n, &cred->subscribers); | ||
| 89 | #endif | ||
| 90 | } | ||
| 91 | |||
| 51 | /* | 92 | /* |
| 52 | * Dispose of the shared task group credentials | 93 | * Dispose of the shared task group credentials |
| 53 | */ | 94 | */ |
| @@ -85,15 +126,29 @@ static void put_cred_rcu(struct rcu_head *rcu) | |||
| 85 | { | 126 | { |
| 86 | struct cred *cred = container_of(rcu, struct cred, rcu); | 127 | struct cred *cred = container_of(rcu, struct cred, rcu); |
| 87 | 128 | ||
| 129 | kdebug("put_cred_rcu(%p)", cred); | ||
| 130 | |||
| 131 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 132 | if (cred->magic != CRED_MAGIC_DEAD || | ||
| 133 | atomic_read(&cred->usage) != 0 || | ||
| 134 | read_cred_subscribers(cred) != 0) | ||
| 135 | panic("CRED: put_cred_rcu() sees %p with" | ||
| 136 | " mag %x, put %p, usage %d, subscr %d\n", | ||
| 137 | cred, cred->magic, cred->put_addr, | ||
| 138 | atomic_read(&cred->usage), | ||
| 139 | read_cred_subscribers(cred)); | ||
| 140 | #else | ||
| 88 | if (atomic_read(&cred->usage) != 0) | 141 | if (atomic_read(&cred->usage) != 0) |
| 89 | panic("CRED: put_cred_rcu() sees %p with usage %d\n", | 142 | panic("CRED: put_cred_rcu() sees %p with usage %d\n", |
| 90 | cred, atomic_read(&cred->usage)); | 143 | cred, atomic_read(&cred->usage)); |
| 144 | #endif | ||
| 91 | 145 | ||
| 92 | security_cred_free(cred); | 146 | security_cred_free(cred); |
| 93 | key_put(cred->thread_keyring); | 147 | key_put(cred->thread_keyring); |
| 94 | key_put(cred->request_key_auth); | 148 | key_put(cred->request_key_auth); |
| 95 | release_tgcred(cred); | 149 | release_tgcred(cred); |
| 96 | put_group_info(cred->group_info); | 150 | if (cred->group_info) |
| 151 | put_group_info(cred->group_info); | ||
| 97 | free_uid(cred->user); | 152 | free_uid(cred->user); |
| 98 | kmem_cache_free(cred_jar, cred); | 153 | kmem_cache_free(cred_jar, cred); |
| 99 | } | 154 | } |
| @@ -106,12 +161,90 @@ static void put_cred_rcu(struct rcu_head *rcu) | |||
| 106 | */ | 161 | */ |
| 107 | void __put_cred(struct cred *cred) | 162 | void __put_cred(struct cred *cred) |
| 108 | { | 163 | { |
| 164 | kdebug("__put_cred(%p{%d,%d})", cred, | ||
| 165 | atomic_read(&cred->usage), | ||
| 166 | read_cred_subscribers(cred)); | ||
| 167 | |||
| 109 | BUG_ON(atomic_read(&cred->usage) != 0); | 168 | BUG_ON(atomic_read(&cred->usage) != 0); |
| 169 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 170 | BUG_ON(read_cred_subscribers(cred) != 0); | ||
| 171 | cred->magic = CRED_MAGIC_DEAD; | ||
| 172 | cred->put_addr = __builtin_return_address(0); | ||
| 173 | #endif | ||
| 174 | BUG_ON(cred == current->cred); | ||
| 175 | BUG_ON(cred == current->real_cred); | ||
| 110 | 176 | ||
| 111 | call_rcu(&cred->rcu, put_cred_rcu); | 177 | call_rcu(&cred->rcu, put_cred_rcu); |
| 112 | } | 178 | } |
| 113 | EXPORT_SYMBOL(__put_cred); | 179 | EXPORT_SYMBOL(__put_cred); |
| 114 | 180 | ||
| 181 | /* | ||
| 182 | * Clean up a task's credentials when it exits | ||
| 183 | */ | ||
| 184 | void exit_creds(struct task_struct *tsk) | ||
| 185 | { | ||
| 186 | struct cred *cred; | ||
| 187 | |||
| 188 | kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred, | ||
| 189 | atomic_read(&tsk->cred->usage), | ||
| 190 | read_cred_subscribers(tsk->cred)); | ||
| 191 | |||
| 192 | cred = (struct cred *) tsk->real_cred; | ||
| 193 | tsk->real_cred = NULL; | ||
| 194 | validate_creds(cred); | ||
| 195 | alter_cred_subscribers(cred, -1); | ||
| 196 | put_cred(cred); | ||
| 197 | |||
| 198 | cred = (struct cred *) tsk->cred; | ||
| 199 | tsk->cred = NULL; | ||
| 200 | validate_creds(cred); | ||
| 201 | alter_cred_subscribers(cred, -1); | ||
| 202 | put_cred(cred); | ||
| 203 | |||
| 204 | cred = (struct cred *) tsk->replacement_session_keyring; | ||
| 205 | if (cred) { | ||
| 206 | tsk->replacement_session_keyring = NULL; | ||
| 207 | validate_creds(cred); | ||
| 208 | put_cred(cred); | ||
| 209 | } | ||
| 210 | } | ||
| 211 | |||
| 212 | /* | ||
| 213 | * Allocate blank credentials, such that the credentials can be filled in at a | ||
| 214 | * later date without risk of ENOMEM. | ||
| 215 | */ | ||
| 216 | struct cred *cred_alloc_blank(void) | ||
| 217 | { | ||
| 218 | struct cred *new; | ||
| 219 | |||
| 220 | new = kmem_cache_zalloc(cred_jar, GFP_KERNEL); | ||
| 221 | if (!new) | ||
| 222 | return NULL; | ||
| 223 | |||
| 224 | #ifdef CONFIG_KEYS | ||
| 225 | new->tgcred = kzalloc(sizeof(*new->tgcred), GFP_KERNEL); | ||
| 226 | if (!new->tgcred) { | ||
| 227 | kfree(new); | ||
| 228 | return NULL; | ||
| 229 | } | ||
| 230 | atomic_set(&new->tgcred->usage, 1); | ||
| 231 | #endif | ||
| 232 | |||
| 233 | atomic_set(&new->usage, 1); | ||
| 234 | |||
| 235 | if (security_cred_alloc_blank(new, GFP_KERNEL) < 0) | ||
| 236 | goto error; | ||
| 237 | |||
| 238 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 239 | new->magic = CRED_MAGIC; | ||
| 240 | #endif | ||
| 241 | return new; | ||
| 242 | |||
| 243 | error: | ||
| 244 | abort_creds(new); | ||
| 245 | return NULL; | ||
| 246 | } | ||
| 247 | |||
| 115 | /** | 248 | /** |
| 116 | * prepare_creds - Prepare a new set of credentials for modification | 249 | * prepare_creds - Prepare a new set of credentials for modification |
| 117 | * | 250 | * |
| @@ -132,16 +265,19 @@ struct cred *prepare_creds(void) | |||
| 132 | const struct cred *old; | 265 | const struct cred *old; |
| 133 | struct cred *new; | 266 | struct cred *new; |
| 134 | 267 | ||
| 135 | BUG_ON(atomic_read(&task->real_cred->usage) < 1); | 268 | validate_process_creds(); |
| 136 | 269 | ||
| 137 | new = kmem_cache_alloc(cred_jar, GFP_KERNEL); | 270 | new = kmem_cache_alloc(cred_jar, GFP_KERNEL); |
| 138 | if (!new) | 271 | if (!new) |
| 139 | return NULL; | 272 | return NULL; |
| 140 | 273 | ||
| 274 | kdebug("prepare_creds() alloc %p", new); | ||
| 275 | |||
| 141 | old = task->cred; | 276 | old = task->cred; |
| 142 | memcpy(new, old, sizeof(struct cred)); | 277 | memcpy(new, old, sizeof(struct cred)); |
| 143 | 278 | ||
| 144 | atomic_set(&new->usage, 1); | 279 | atomic_set(&new->usage, 1); |
| 280 | set_cred_subscribers(new, 0); | ||
| 145 | get_group_info(new->group_info); | 281 | get_group_info(new->group_info); |
| 146 | get_uid(new->user); | 282 | get_uid(new->user); |
| 147 | 283 | ||
| @@ -157,6 +293,7 @@ struct cred *prepare_creds(void) | |||
| 157 | 293 | ||
| 158 | if (security_prepare_creds(new, old, GFP_KERNEL) < 0) | 294 | if (security_prepare_creds(new, old, GFP_KERNEL) < 0) |
| 159 | goto error; | 295 | goto error; |
| 296 | validate_creds(new); | ||
| 160 | return new; | 297 | return new; |
| 161 | 298 | ||
| 162 | error: | 299 | error: |
| @@ -229,9 +366,12 @@ struct cred *prepare_usermodehelper_creds(void) | |||
| 229 | if (!new) | 366 | if (!new) |
| 230 | return NULL; | 367 | return NULL; |
| 231 | 368 | ||
| 369 | kdebug("prepare_usermodehelper_creds() alloc %p", new); | ||
| 370 | |||
| 232 | memcpy(new, &init_cred, sizeof(struct cred)); | 371 | memcpy(new, &init_cred, sizeof(struct cred)); |
| 233 | 372 | ||
| 234 | atomic_set(&new->usage, 1); | 373 | atomic_set(&new->usage, 1); |
| 374 | set_cred_subscribers(new, 0); | ||
| 235 | get_group_info(new->group_info); | 375 | get_group_info(new->group_info); |
| 236 | get_uid(new->user); | 376 | get_uid(new->user); |
| 237 | 377 | ||
| @@ -250,6 +390,7 @@ struct cred *prepare_usermodehelper_creds(void) | |||
| 250 | #endif | 390 | #endif |
| 251 | if (security_prepare_creds(new, &init_cred, GFP_ATOMIC) < 0) | 391 | if (security_prepare_creds(new, &init_cred, GFP_ATOMIC) < 0) |
| 252 | goto error; | 392 | goto error; |
| 393 | validate_creds(new); | ||
| 253 | 394 | ||
| 254 | BUG_ON(atomic_read(&new->usage) != 1); | 395 | BUG_ON(atomic_read(&new->usage) != 1); |
| 255 | return new; | 396 | return new; |
| @@ -286,6 +427,10 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags) | |||
| 286 | ) { | 427 | ) { |
| 287 | p->real_cred = get_cred(p->cred); | 428 | p->real_cred = get_cred(p->cred); |
| 288 | get_cred(p->cred); | 429 | get_cred(p->cred); |
| 430 | alter_cred_subscribers(p->cred, 2); | ||
| 431 | kdebug("share_creds(%p{%d,%d})", | ||
| 432 | p->cred, atomic_read(&p->cred->usage), | ||
| 433 | read_cred_subscribers(p->cred)); | ||
| 289 | atomic_inc(&p->cred->user->processes); | 434 | atomic_inc(&p->cred->user->processes); |
| 290 | return 0; | 435 | return 0; |
| 291 | } | 436 | } |
| @@ -331,6 +476,8 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags) | |||
| 331 | 476 | ||
| 332 | atomic_inc(&new->user->processes); | 477 | atomic_inc(&new->user->processes); |
| 333 | p->cred = p->real_cred = get_cred(new); | 478 | p->cred = p->real_cred = get_cred(new); |
| 479 | alter_cred_subscribers(new, 2); | ||
| 480 | validate_creds(new); | ||
| 334 | return 0; | 481 | return 0; |
| 335 | 482 | ||
| 336 | error_put: | 483 | error_put: |
| @@ -355,13 +502,20 @@ error_put: | |||
| 355 | int commit_creds(struct cred *new) | 502 | int commit_creds(struct cred *new) |
| 356 | { | 503 | { |
| 357 | struct task_struct *task = current; | 504 | struct task_struct *task = current; |
| 358 | const struct cred *old; | 505 | const struct cred *old = task->real_cred; |
| 506 | |||
| 507 | kdebug("commit_creds(%p{%d,%d})", new, | ||
| 508 | atomic_read(&new->usage), | ||
| 509 | read_cred_subscribers(new)); | ||
| 359 | 510 | ||
| 360 | BUG_ON(task->cred != task->real_cred); | 511 | BUG_ON(task->cred != old); |
| 361 | BUG_ON(atomic_read(&task->real_cred->usage) < 2); | 512 | #ifdef CONFIG_DEBUG_CREDENTIALS |
| 513 | BUG_ON(read_cred_subscribers(old) < 2); | ||
| 514 | validate_creds(old); | ||
| 515 | validate_creds(new); | ||
| 516 | #endif | ||
| 362 | BUG_ON(atomic_read(&new->usage) < 1); | 517 | BUG_ON(atomic_read(&new->usage) < 1); |
| 363 | 518 | ||
| 364 | old = task->real_cred; | ||
| 365 | security_commit_creds(new, old); | 519 | security_commit_creds(new, old); |
| 366 | 520 | ||
| 367 | get_cred(new); /* we will require a ref for the subj creds too */ | 521 | get_cred(new); /* we will require a ref for the subj creds too */ |
| @@ -390,12 +544,14 @@ int commit_creds(struct cred *new) | |||
| 390 | * cheaply with the new uid cache, so if it matters | 544 | * cheaply with the new uid cache, so if it matters |
| 391 | * we should be checking for it. -DaveM | 545 | * we should be checking for it. -DaveM |
| 392 | */ | 546 | */ |
| 547 | alter_cred_subscribers(new, 2); | ||
| 393 | if (new->user != old->user) | 548 | if (new->user != old->user) |
| 394 | atomic_inc(&new->user->processes); | 549 | atomic_inc(&new->user->processes); |
| 395 | rcu_assign_pointer(task->real_cred, new); | 550 | rcu_assign_pointer(task->real_cred, new); |
| 396 | rcu_assign_pointer(task->cred, new); | 551 | rcu_assign_pointer(task->cred, new); |
| 397 | if (new->user != old->user) | 552 | if (new->user != old->user) |
| 398 | atomic_dec(&old->user->processes); | 553 | atomic_dec(&old->user->processes); |
| 554 | alter_cred_subscribers(old, -2); | ||
| 399 | 555 | ||
| 400 | sched_switch_user(task); | 556 | sched_switch_user(task); |
| 401 | 557 | ||
| @@ -428,6 +584,13 @@ EXPORT_SYMBOL(commit_creds); | |||
| 428 | */ | 584 | */ |
| 429 | void abort_creds(struct cred *new) | 585 | void abort_creds(struct cred *new) |
| 430 | { | 586 | { |
| 587 | kdebug("abort_creds(%p{%d,%d})", new, | ||
| 588 | atomic_read(&new->usage), | ||
| 589 | read_cred_subscribers(new)); | ||
| 590 | |||
| 591 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 592 | BUG_ON(read_cred_subscribers(new) != 0); | ||
| 593 | #endif | ||
| 431 | BUG_ON(atomic_read(&new->usage) < 1); | 594 | BUG_ON(atomic_read(&new->usage) < 1); |
| 432 | put_cred(new); | 595 | put_cred(new); |
| 433 | } | 596 | } |
| @@ -444,7 +607,20 @@ const struct cred *override_creds(const struct cred *new) | |||
| 444 | { | 607 | { |
| 445 | const struct cred *old = current->cred; | 608 | const struct cred *old = current->cred; |
| 446 | 609 | ||
| 447 | rcu_assign_pointer(current->cred, get_cred(new)); | 610 | kdebug("override_creds(%p{%d,%d})", new, |
| 611 | atomic_read(&new->usage), | ||
| 612 | read_cred_subscribers(new)); | ||
| 613 | |||
| 614 | validate_creds(old); | ||
| 615 | validate_creds(new); | ||
| 616 | get_cred(new); | ||
| 617 | alter_cred_subscribers(new, 1); | ||
| 618 | rcu_assign_pointer(current->cred, new); | ||
| 619 | alter_cred_subscribers(old, -1); | ||
| 620 | |||
| 621 | kdebug("override_creds() = %p{%d,%d}", old, | ||
| 622 | atomic_read(&old->usage), | ||
| 623 | read_cred_subscribers(old)); | ||
| 448 | return old; | 624 | return old; |
| 449 | } | 625 | } |
| 450 | EXPORT_SYMBOL(override_creds); | 626 | EXPORT_SYMBOL(override_creds); |
| @@ -460,7 +636,15 @@ void revert_creds(const struct cred *old) | |||
| 460 | { | 636 | { |
| 461 | const struct cred *override = current->cred; | 637 | const struct cred *override = current->cred; |
| 462 | 638 | ||
| 639 | kdebug("revert_creds(%p{%d,%d})", old, | ||
| 640 | atomic_read(&old->usage), | ||
| 641 | read_cred_subscribers(old)); | ||
| 642 | |||
| 643 | validate_creds(old); | ||
| 644 | validate_creds(override); | ||
| 645 | alter_cred_subscribers(old, 1); | ||
| 463 | rcu_assign_pointer(current->cred, old); | 646 | rcu_assign_pointer(current->cred, old); |
| 647 | alter_cred_subscribers(override, -1); | ||
| 464 | put_cred(override); | 648 | put_cred(override); |
| 465 | } | 649 | } |
| 466 | EXPORT_SYMBOL(revert_creds); | 650 | EXPORT_SYMBOL(revert_creds); |
| @@ -502,11 +686,15 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon) | |||
| 502 | if (!new) | 686 | if (!new) |
| 503 | return NULL; | 687 | return NULL; |
| 504 | 688 | ||
| 689 | kdebug("prepare_kernel_cred() alloc %p", new); | ||
| 690 | |||
| 505 | if (daemon) | 691 | if (daemon) |
| 506 | old = get_task_cred(daemon); | 692 | old = get_task_cred(daemon); |
| 507 | else | 693 | else |
| 508 | old = get_cred(&init_cred); | 694 | old = get_cred(&init_cred); |
| 509 | 695 | ||
| 696 | validate_creds(old); | ||
| 697 | |||
| 510 | *new = *old; | 698 | *new = *old; |
| 511 | get_uid(new->user); | 699 | get_uid(new->user); |
| 512 | get_group_info(new->group_info); | 700 | get_group_info(new->group_info); |
| @@ -526,7 +714,9 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon) | |||
| 526 | goto error; | 714 | goto error; |
| 527 | 715 | ||
| 528 | atomic_set(&new->usage, 1); | 716 | atomic_set(&new->usage, 1); |
| 717 | set_cred_subscribers(new, 0); | ||
| 529 | put_cred(old); | 718 | put_cred(old); |
| 719 | validate_creds(new); | ||
| 530 | return new; | 720 | return new; |
| 531 | 721 | ||
| 532 | error: | 722 | error: |
| @@ -589,3 +779,114 @@ int set_create_files_as(struct cred *new, struct inode *inode) | |||
| 589 | return security_kernel_create_files_as(new, inode); | 779 | return security_kernel_create_files_as(new, inode); |
| 590 | } | 780 | } |
| 591 | EXPORT_SYMBOL(set_create_files_as); | 781 | EXPORT_SYMBOL(set_create_files_as); |
| 782 | |||
| 783 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 784 | |||
| 785 | bool creds_are_invalid(const struct cred *cred) | ||
| 786 | { | ||
| 787 | if (cred->magic != CRED_MAGIC) | ||
| 788 | return true; | ||
| 789 | if (atomic_read(&cred->usage) < atomic_read(&cred->subscribers)) | ||
| 790 | return true; | ||
| 791 | #ifdef CONFIG_SECURITY_SELINUX | ||
| 792 | if (selinux_is_enabled()) { | ||
| 793 | if ((unsigned long) cred->security < PAGE_SIZE) | ||
| 794 | return true; | ||
| 795 | if ((*(u32 *)cred->security & 0xffffff00) == | ||
| 796 | (POISON_FREE << 24 | POISON_FREE << 16 | POISON_FREE << 8)) | ||
| 797 | return true; | ||
| 798 | } | ||
| 799 | #endif | ||
| 800 | return false; | ||
| 801 | } | ||
| 802 | EXPORT_SYMBOL(creds_are_invalid); | ||
| 803 | |||
| 804 | /* | ||
| 805 | * dump invalid credentials | ||
| 806 | */ | ||
| 807 | static void dump_invalid_creds(const struct cred *cred, const char *label, | ||
| 808 | const struct task_struct *tsk) | ||
| 809 | { | ||
| 810 | printk(KERN_ERR "CRED: %s credentials: %p %s%s%s\n", | ||
| 811 | label, cred, | ||
| 812 | cred == &init_cred ? "[init]" : "", | ||
| 813 | cred == tsk->real_cred ? "[real]" : "", | ||
| 814 | cred == tsk->cred ? "[eff]" : ""); | ||
| 815 | printk(KERN_ERR "CRED: ->magic=%x, put_addr=%p\n", | ||
| 816 | cred->magic, cred->put_addr); | ||
| 817 | printk(KERN_ERR "CRED: ->usage=%d, subscr=%d\n", | ||
| 818 | atomic_read(&cred->usage), | ||
| 819 | read_cred_subscribers(cred)); | ||
| 820 | printk(KERN_ERR "CRED: ->*uid = { %d,%d,%d,%d }\n", | ||
| 821 | cred->uid, cred->euid, cred->suid, cred->fsuid); | ||
| 822 | printk(KERN_ERR "CRED: ->*gid = { %d,%d,%d,%d }\n", | ||
| 823 | cred->gid, cred->egid, cred->sgid, cred->fsgid); | ||
| 824 | #ifdef CONFIG_SECURITY | ||
| 825 | printk(KERN_ERR "CRED: ->security is %p\n", cred->security); | ||
| 826 | if ((unsigned long) cred->security >= PAGE_SIZE && | ||
| 827 | (((unsigned long) cred->security & 0xffffff00) != | ||
| 828 | (POISON_FREE << 24 | POISON_FREE << 16 | POISON_FREE << 8))) | ||
| 829 | printk(KERN_ERR "CRED: ->security {%x, %x}\n", | ||
| 830 | ((u32*)cred->security)[0], | ||
| 831 | ((u32*)cred->security)[1]); | ||
| 832 | #endif | ||
| 833 | } | ||
| 834 | |||
| 835 | /* | ||
| 836 | * report use of invalid credentials | ||
| 837 | */ | ||
| 838 | void __invalid_creds(const struct cred *cred, const char *file, unsigned line) | ||
| 839 | { | ||
| 840 | printk(KERN_ERR "CRED: Invalid credentials\n"); | ||
| 841 | printk(KERN_ERR "CRED: At %s:%u\n", file, line); | ||
| 842 | dump_invalid_creds(cred, "Specified", current); | ||
| 843 | BUG(); | ||
| 844 | } | ||
| 845 | EXPORT_SYMBOL(__invalid_creds); | ||
| 846 | |||
| 847 | /* | ||
| 848 | * check the credentials on a process | ||
| 849 | */ | ||
| 850 | void __validate_process_creds(struct task_struct *tsk, | ||
| 851 | const char *file, unsigned line) | ||
| 852 | { | ||
| 853 | if (tsk->cred == tsk->real_cred) { | ||
| 854 | if (unlikely(read_cred_subscribers(tsk->cred) < 2 || | ||
| 855 | creds_are_invalid(tsk->cred))) | ||
| 856 | goto invalid_creds; | ||
| 857 | } else { | ||
| 858 | if (unlikely(read_cred_subscribers(tsk->real_cred) < 1 || | ||
| 859 | read_cred_subscribers(tsk->cred) < 1 || | ||
| 860 | creds_are_invalid(tsk->real_cred) || | ||
| 861 | creds_are_invalid(tsk->cred))) | ||
| 862 | goto invalid_creds; | ||
| 863 | } | ||
| 864 | return; | ||
| 865 | |||
| 866 | invalid_creds: | ||
| 867 | printk(KERN_ERR "CRED: Invalid process credentials\n"); | ||
| 868 | printk(KERN_ERR "CRED: At %s:%u\n", file, line); | ||
| 869 | |||
| 870 | dump_invalid_creds(tsk->real_cred, "Real", tsk); | ||
| 871 | if (tsk->cred != tsk->real_cred) | ||
| 872 | dump_invalid_creds(tsk->cred, "Effective", tsk); | ||
| 873 | else | ||
| 874 | printk(KERN_ERR "CRED: Effective creds == Real creds\n"); | ||
| 875 | BUG(); | ||
| 876 | } | ||
| 877 | EXPORT_SYMBOL(__validate_process_creds); | ||
| 878 | |||
| 879 | /* | ||
| 880 | * check creds for do_exit() | ||
| 881 | */ | ||
| 882 | void validate_creds_for_do_exit(struct task_struct *tsk) | ||
| 883 | { | ||
| 884 | kdebug("validate_creds_for_do_exit(%p,%p{%d,%d})", | ||
| 885 | tsk->real_cred, tsk->cred, | ||
| 886 | atomic_read(&tsk->cred->usage), | ||
| 887 | read_cred_subscribers(tsk->cred)); | ||
| 888 | |||
| 889 | __validate_process_creds(tsk, __FILE__, __LINE__); | ||
| 890 | } | ||
| 891 | |||
| 892 | #endif /* CONFIG_DEBUG_CREDENTIALS */ | ||
