diff options
Diffstat (limited to 'security/commoncap.c')
-rw-r--r-- | security/commoncap.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/security/commoncap.c b/security/commoncap.c index dc06c0086b55..8283271f0768 100644 --- a/security/commoncap.c +++ b/security/commoncap.c | |||
@@ -362,7 +362,7 @@ int cap_bprm_set_security (struct linux_binprm *bprm) | |||
362 | * If only the real uid is 0, we do not set the effective | 362 | * If only the real uid is 0, we do not set the effective |
363 | * bit. | 363 | * bit. |
364 | */ | 364 | */ |
365 | if (bprm->e_uid == 0 || current->uid == 0) { | 365 | if (bprm->e_uid == 0 || current_uid() == 0) { |
366 | /* pP' = (cap_bset & ~0) | (pI & ~0) */ | 366 | /* pP' = (cap_bset & ~0) | (pI & ~0) */ |
367 | bprm->cap_post_exec_permitted = cap_combine( | 367 | bprm->cap_post_exec_permitted = cap_combine( |
368 | current->cap_bset, current->cap_inheritable | 368 | current->cap_bset, current->cap_inheritable |
@@ -379,8 +379,12 @@ void cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe) | |||
379 | { | 379 | { |
380 | kernel_cap_t pP = current->cap_permitted; | 380 | kernel_cap_t pP = current->cap_permitted; |
381 | kernel_cap_t pE = current->cap_effective; | 381 | kernel_cap_t pE = current->cap_effective; |
382 | uid_t uid; | ||
383 | gid_t gid; | ||
382 | 384 | ||
383 | if (bprm->e_uid != current->uid || bprm->e_gid != current->gid || | 385 | current_uid_gid(&uid, &gid); |
386 | |||
387 | if (bprm->e_uid != uid || bprm->e_gid != gid || | ||
384 | !cap_issubset(bprm->cap_post_exec_permitted, | 388 | !cap_issubset(bprm->cap_post_exec_permitted, |
385 | current->cap_permitted)) { | 389 | current->cap_permitted)) { |
386 | set_dumpable(current->mm, suid_dumpable); | 390 | set_dumpable(current->mm, suid_dumpable); |
@@ -388,8 +392,8 @@ void cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe) | |||
388 | 392 | ||
389 | if (unsafe & ~LSM_UNSAFE_PTRACE_CAP) { | 393 | if (unsafe & ~LSM_UNSAFE_PTRACE_CAP) { |
390 | if (!capable(CAP_SETUID)) { | 394 | if (!capable(CAP_SETUID)) { |
391 | bprm->e_uid = current->uid; | 395 | bprm->e_uid = uid; |
392 | bprm->e_gid = current->gid; | 396 | bprm->e_gid = gid; |
393 | } | 397 | } |
394 | if (cap_limit_ptraced_target()) { | 398 | if (cap_limit_ptraced_target()) { |
395 | bprm->cap_post_exec_permitted = cap_intersect( | 399 | bprm->cap_post_exec_permitted = cap_intersect( |
@@ -437,15 +441,15 @@ void cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe) | |||
437 | 441 | ||
438 | int cap_bprm_secureexec (struct linux_binprm *bprm) | 442 | int cap_bprm_secureexec (struct linux_binprm *bprm) |
439 | { | 443 | { |
440 | if (current->uid != 0) { | 444 | if (current_uid() != 0) { |
441 | if (bprm->cap_effective) | 445 | if (bprm->cap_effective) |
442 | return 1; | 446 | return 1; |
443 | if (!cap_isclear(bprm->cap_post_exec_permitted)) | 447 | if (!cap_isclear(bprm->cap_post_exec_permitted)) |
444 | return 1; | 448 | return 1; |
445 | } | 449 | } |
446 | 450 | ||
447 | return (current->euid != current->uid || | 451 | return (current_euid() != current_uid() || |
448 | current->egid != current->gid); | 452 | current_egid() != current_gid()); |
449 | } | 453 | } |
450 | 454 | ||
451 | int cap_inode_setxattr(struct dentry *dentry, const char *name, | 455 | int cap_inode_setxattr(struct dentry *dentry, const char *name, |
@@ -508,16 +512,18 @@ int cap_inode_removexattr(struct dentry *dentry, const char *name) | |||
508 | static inline void cap_emulate_setxuid (int old_ruid, int old_euid, | 512 | static inline void cap_emulate_setxuid (int old_ruid, int old_euid, |
509 | int old_suid) | 513 | int old_suid) |
510 | { | 514 | { |
515 | uid_t euid = current_euid(); | ||
516 | |||
511 | if ((old_ruid == 0 || old_euid == 0 || old_suid == 0) && | 517 | if ((old_ruid == 0 || old_euid == 0 || old_suid == 0) && |
512 | (current->uid != 0 && current->euid != 0 && current->suid != 0) && | 518 | (current_uid() != 0 && euid != 0 && current_suid() != 0) && |
513 | !issecure(SECURE_KEEP_CAPS)) { | 519 | !issecure(SECURE_KEEP_CAPS)) { |
514 | cap_clear (current->cap_permitted); | 520 | cap_clear (current->cap_permitted); |
515 | cap_clear (current->cap_effective); | 521 | cap_clear (current->cap_effective); |
516 | } | 522 | } |
517 | if (old_euid == 0 && current->euid != 0) { | 523 | if (old_euid == 0 && euid != 0) { |
518 | cap_clear (current->cap_effective); | 524 | cap_clear (current->cap_effective); |
519 | } | 525 | } |
520 | if (old_euid != 0 && current->euid == 0) { | 526 | if (old_euid != 0 && euid == 0) { |
521 | current->cap_effective = current->cap_permitted; | 527 | current->cap_effective = current->cap_permitted; |
522 | } | 528 | } |
523 | } | 529 | } |
@@ -546,12 +552,12 @@ int cap_task_post_setuid (uid_t old_ruid, uid_t old_euid, uid_t old_suid, | |||
546 | */ | 552 | */ |
547 | 553 | ||
548 | if (!issecure (SECURE_NO_SETUID_FIXUP)) { | 554 | if (!issecure (SECURE_NO_SETUID_FIXUP)) { |
549 | if (old_fsuid == 0 && current->fsuid != 0) { | 555 | if (old_fsuid == 0 && current_fsuid() != 0) { |
550 | current->cap_effective = | 556 | current->cap_effective = |
551 | cap_drop_fs_set( | 557 | cap_drop_fs_set( |
552 | current->cap_effective); | 558 | current->cap_effective); |
553 | } | 559 | } |
554 | if (old_fsuid != 0 && current->fsuid == 0) { | 560 | if (old_fsuid != 0 && current_fsuid() == 0) { |
555 | current->cap_effective = | 561 | current->cap_effective = |
556 | cap_raise_fs_set( | 562 | cap_raise_fs_set( |
557 | current->cap_effective, | 563 | current->cap_effective, |