aboutsummaryrefslogtreecommitdiffstats
path: root/security/commoncap.c
diff options
context:
space:
mode:
Diffstat (limited to 'security/commoncap.c')
-rw-r--r--security/commoncap.c83
1 files changed, 10 insertions, 73 deletions
diff --git a/security/commoncap.c b/security/commoncap.c
index fe30751a6cd9..61669730da98 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -1,4 +1,4 @@
1/* Common capabilities, needed by capability.o and root_plug.o 1/* Common capabilities, needed by capability.o.
2 * 2 *
3 * This program is free software; you can redistribute it and/or modify 3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by 4 * it under the terms of the GNU General Public License as published by
@@ -27,6 +27,7 @@
27#include <linux/sched.h> 27#include <linux/sched.h>
28#include <linux/prctl.h> 28#include <linux/prctl.h>
29#include <linux/securebits.h> 29#include <linux/securebits.h>
30#include <linux/syslog.h>
30 31
31/* 32/*
32 * If a non-root user executes a setuid-root binary in 33 * If a non-root user executes a setuid-root binary in
@@ -173,7 +174,6 @@ int cap_capget(struct task_struct *target, kernel_cap_t *effective,
173 */ 174 */
174static inline int cap_inh_is_capped(void) 175static inline int cap_inh_is_capped(void)
175{ 176{
176#ifdef CONFIG_SECURITY_FILE_CAPABILITIES
177 177
178 /* they are so limited unless the current task has the CAP_SETPCAP 178 /* they are so limited unless the current task has the CAP_SETPCAP
179 * capability 179 * capability
@@ -181,7 +181,6 @@ static inline int cap_inh_is_capped(void)
181 if (cap_capable(current, current_cred(), CAP_SETPCAP, 181 if (cap_capable(current, current_cred(), CAP_SETPCAP,
182 SECURITY_CAP_AUDIT) == 0) 182 SECURITY_CAP_AUDIT) == 0)
183 return 0; 183 return 0;
184#endif
185 return 1; 184 return 1;
186} 185}
187 186
@@ -239,8 +238,6 @@ static inline void bprm_clear_caps(struct linux_binprm *bprm)
239 bprm->cap_effective = false; 238 bprm->cap_effective = false;
240} 239}
241 240
242#ifdef CONFIG_SECURITY_FILE_CAPABILITIES
243
244/** 241/**
245 * cap_inode_need_killpriv - Determine if inode change affects privileges 242 * cap_inode_need_killpriv - Determine if inode change affects privileges
246 * @dentry: The inode/dentry in being changed with change marked ATTR_KILL_PRIV 243 * @dentry: The inode/dentry in being changed with change marked ATTR_KILL_PRIV
@@ -421,49 +418,6 @@ out:
421 return rc; 418 return rc;
422} 419}
423 420
424#else
425int cap_inode_need_killpriv(struct dentry *dentry)
426{
427 return 0;
428}
429
430int cap_inode_killpriv(struct dentry *dentry)
431{
432 return 0;
433}
434
435int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps)
436{
437 memset(cpu_caps, 0, sizeof(struct cpu_vfs_cap_data));
438 return -ENODATA;
439}
440
441static inline int get_file_caps(struct linux_binprm *bprm, bool *effective)
442{
443 bprm_clear_caps(bprm);
444 return 0;
445}
446#endif
447
448/*
449 * Determine whether a exec'ing process's new permitted capabilities should be
450 * limited to just what it already has.
451 *
452 * This prevents processes that are being ptraced from gaining access to
453 * CAP_SETPCAP, unless the process they're tracing already has it, and the
454 * binary they're executing has filecaps that elevate it.
455 *
456 * Returns 1 if they should be limited, 0 if they are not.
457 */
458static inline int cap_limit_ptraced_target(void)
459{
460#ifndef CONFIG_SECURITY_FILE_CAPABILITIES
461 if (capable(CAP_SETPCAP))
462 return 0;
463#endif
464 return 1;
465}
466
467/** 421/**
468 * cap_bprm_set_creds - Set up the proposed credentials for execve(). 422 * cap_bprm_set_creds - Set up the proposed credentials for execve().
469 * @bprm: The execution parameters, including the proposed creds 423 * @bprm: The execution parameters, including the proposed creds
@@ -523,9 +477,8 @@ skip:
523 new->euid = new->uid; 477 new->euid = new->uid;
524 new->egid = new->gid; 478 new->egid = new->gid;
525 } 479 }
526 if (cap_limit_ptraced_target()) 480 new->cap_permitted = cap_intersect(new->cap_permitted,
527 new->cap_permitted = cap_intersect(new->cap_permitted, 481 old->cap_permitted);
528 old->cap_permitted);
529 } 482 }
530 483
531 new->suid = new->fsuid = new->euid; 484 new->suid = new->fsuid = new->euid;
@@ -739,7 +692,6 @@ int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags)
739 return 0; 692 return 0;
740} 693}
741 694
742#ifdef CONFIG_SECURITY_FILE_CAPABILITIES
743/* 695/*
744 * Rationale: code calling task_setscheduler, task_setioprio, and 696 * Rationale: code calling task_setscheduler, task_setioprio, and
745 * task_setnice, assumes that 697 * task_setnice, assumes that
@@ -820,22 +772,6 @@ static long cap_prctl_drop(struct cred *new, unsigned long cap)
820 return 0; 772 return 0;
821} 773}
822 774
823#else
824int cap_task_setscheduler (struct task_struct *p, int policy,
825 struct sched_param *lp)
826{
827 return 0;
828}
829int cap_task_setioprio (struct task_struct *p, int ioprio)
830{
831 return 0;
832}
833int cap_task_setnice (struct task_struct *p, int nice)
834{
835 return 0;
836}
837#endif
838
839/** 775/**
840 * cap_task_prctl - Implement process control functions for this security module 776 * cap_task_prctl - Implement process control functions for this security module
841 * @option: The process control function requested 777 * @option: The process control function requested
@@ -866,7 +802,6 @@ int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
866 error = !!cap_raised(new->cap_bset, arg2); 802 error = !!cap_raised(new->cap_bset, arg2);
867 goto no_change; 803 goto no_change;
868 804
869#ifdef CONFIG_SECURITY_FILE_CAPABILITIES
870 case PR_CAPBSET_DROP: 805 case PR_CAPBSET_DROP:
871 error = cap_prctl_drop(new, arg2); 806 error = cap_prctl_drop(new, arg2);
872 if (error < 0) 807 if (error < 0)
@@ -917,8 +852,6 @@ int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
917 error = new->securebits; 852 error = new->securebits;
918 goto no_change; 853 goto no_change;
919 854
920#endif /* def CONFIG_SECURITY_FILE_CAPABILITIES */
921
922 case PR_GET_KEEPCAPS: 855 case PR_GET_KEEPCAPS:
923 if (issecure(SECURE_KEEP_CAPS)) 856 if (issecure(SECURE_KEEP_CAPS))
924 error = 1; 857 error = 1;
@@ -956,13 +889,17 @@ error:
956/** 889/**
957 * cap_syslog - Determine whether syslog function is permitted 890 * cap_syslog - Determine whether syslog function is permitted
958 * @type: Function requested 891 * @type: Function requested
892 * @from_file: Whether this request came from an open file (i.e. /proc)
959 * 893 *
960 * Determine whether the current process is permitted to use a particular 894 * Determine whether the current process is permitted to use a particular
961 * syslog function, returning 0 if permission is granted, -ve if not. 895 * syslog function, returning 0 if permission is granted, -ve if not.
962 */ 896 */
963int cap_syslog(int type) 897int cap_syslog(int type, bool from_file)
964{ 898{
965 if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN)) 899 if (type != SYSLOG_ACTION_OPEN && from_file)
900 return 0;
901 if ((type != SYSLOG_ACTION_READ_ALL &&
902 type != SYSLOG_ACTION_SIZE_BUFFER) && !capable(CAP_SYS_ADMIN))
966 return -EPERM; 903 return -EPERM;
967 return 0; 904 return 0;
968} 905}