1 /* Common capabilities, needed by capability.o and root_plug.o
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
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
10 #include <linux/capability.h>
11 #include <linux/audit.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/security.h>
16 #include <linux/file.h>
18 #include <linux/mman.h>
19 #include <linux/pagemap.h>
20 #include <linux/swap.h>
21 #include <linux/skbuff.h>
22 #include <linux/netlink.h>
23 #include <linux/ptrace.h>
24 #include <linux/xattr.h>
25 #include <linux/hugetlb.h>
26 #include <linux/mount.h>
27 #include <linux/sched.h>
28 #include <linux/prctl.h>
29 #include <linux/securebits.h>
31 int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
33 NETLINK_CB(skb).eff_cap = current_cap();
37 int cap_netlink_recv(struct sk_buff *skb, int cap)
39 if (!cap_raised(NETLINK_CB(skb).eff_cap, cap))
43 EXPORT_SYMBOL(cap_netlink_recv);
46 * cap_capable - Determine whether current has a particular effective capability
47 * @cap: The capability to check for
48 * @audit: Whether to write an audit message or not
50 * Determine whether the nominated task has the specified capability amongst
51 * its effective set, returning 0 if it does, -ve if it does not. Note that
52 * this uses current's subjective/effective credentials.
54 * NOTE WELL: cap_capable() cannot be used like the kernel's capable()
55 * function. That is, it has the reverse semantics: cap_capable() returns 0
56 * when a task has a capability, but the kernel's capable() returns 1 for this
59 int cap_capable(int cap, int audit)
61 return cap_raised(current_cap(), cap) ? 0 : -EPERM;
65 * cap_has_capability - Determine whether a task has a particular effective capability
66 * @tsk: The task to query
67 * @cred: The credentials to use
68 * @cap: The capability to check for
69 * @audit: Whether to write an audit message or not
71 * Determine whether the nominated task has the specified capability amongst
72 * its effective set, returning 0 if it does, -ve if it does not. Note that
73 * this uses the task's objective/real credentials.
75 * NOTE WELL: cap_has_capability() cannot be used like the kernel's
76 * has_capability() function. That is, it has the reverse semantics:
77 * cap_has_capability() returns 0 when a task has a capability, but the
78 * kernel's has_capability() returns 1 for this case.
80 int cap_task_capable(struct task_struct *tsk, const struct cred *cred, int cap,
83 return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
87 * cap_settime - Determine whether the current process may set the system clock
88 * @ts: The time to set
89 * @tz: The timezone to set
91 * Determine whether the current process may set the system clock and timezone
92 * information, returning 0 if permission granted, -ve if denied.
94 int cap_settime(struct timespec *ts, struct timezone *tz)
96 if (!capable(CAP_SYS_TIME))
102 * cap_ptrace_may_access - Determine whether the current process may access
104 * @child: The process to be accessed
105 * @mode: The mode of attachment.
107 * Determine whether a process may access another, returning 0 if permission
108 * granted, -ve if denied.
110 int cap_ptrace_may_access(struct task_struct *child, unsigned int mode)
115 if (!cap_issubset(__task_cred(child)->cap_permitted,
116 current_cred()->cap_permitted) &&
117 !capable(CAP_SYS_PTRACE))
124 * cap_ptrace_traceme - Determine whether another process may trace the current
125 * @parent: The task proposed to be the tracer
127 * Determine whether the nominated task is permitted to trace the current
128 * process, returning 0 if permission is granted, -ve if denied.
130 int cap_ptrace_traceme(struct task_struct *parent)
135 if (!cap_issubset(current_cred()->cap_permitted,
136 __task_cred(parent)->cap_permitted) &&
137 !has_capability(parent, CAP_SYS_PTRACE))
144 * cap_capget - Retrieve a task's capability sets
145 * @target: The task from which to retrieve the capability sets
146 * @effective: The place to record the effective set
147 * @inheritable: The place to record the inheritable set
148 * @permitted: The place to record the permitted set
150 * This function retrieves the capabilities of the nominated task and returns
151 * them to the caller.
153 int cap_capget(struct task_struct *target, kernel_cap_t *effective,
154 kernel_cap_t *inheritable, kernel_cap_t *permitted)
156 const struct cred *cred;
158 /* Derived from kernel/capability.c:sys_capget. */
160 cred = __task_cred(target);
161 *effective = cred->cap_effective;
162 *inheritable = cred->cap_inheritable;
163 *permitted = cred->cap_permitted;
169 * Determine whether the inheritable capabilities are limited to the old
170 * permitted set. Returns 1 if they are limited, 0 if they are not.
172 static inline int cap_inh_is_capped(void)
174 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
176 /* they are so limited unless the current task has the CAP_SETPCAP
179 if (cap_capable(CAP_SETPCAP, SECURITY_CAP_AUDIT) == 0)
186 * cap_capset - Validate and apply proposed changes to current's capabilities
187 * @new: The proposed new credentials; alterations should be made here
188 * @old: The current task's current credentials
189 * @effective: A pointer to the proposed new effective capabilities set
190 * @inheritable: A pointer to the proposed new inheritable capabilities set
191 * @permitted: A pointer to the proposed new permitted capabilities set
193 * This function validates and applies a proposed mass change to the current
194 * process's capability sets. The changes are made to the proposed new
195 * credentials, and assuming no error, will be committed by the caller of LSM.
197 int cap_capset(struct cred *new,
198 const struct cred *old,
199 const kernel_cap_t *effective,
200 const kernel_cap_t *inheritable,
201 const kernel_cap_t *permitted)
203 if (cap_inh_is_capped() &&
204 !cap_issubset(*inheritable,
205 cap_combine(old->cap_inheritable,
206 old->cap_permitted)))
207 /* incapable of using this inheritable set */
210 if (!cap_issubset(*inheritable,
211 cap_combine(old->cap_inheritable,
213 /* no new pI capabilities outside bounding set */
216 /* verify restrictions on target's new Permitted set */
217 if (!cap_issubset(*permitted, old->cap_permitted))
220 /* verify the _new_Effective_ is a subset of the _new_Permitted_ */
221 if (!cap_issubset(*effective, *permitted))
224 new->cap_effective = *effective;
225 new->cap_inheritable = *inheritable;
226 new->cap_permitted = *permitted;
231 * Clear proposed capability sets for execve().
233 static inline void bprm_clear_caps(struct linux_binprm *bprm)
235 cap_clear(bprm->cred->cap_permitted);
236 bprm->cap_effective = false;
239 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
242 * cap_inode_need_killpriv - Determine if inode change affects privileges
243 * @dentry: The inode/dentry in being changed with change marked ATTR_KILL_PRIV
245 * Determine if an inode having a change applied that's marked ATTR_KILL_PRIV
246 * affects the security markings on that inode, and if it is, should
247 * inode_killpriv() be invoked or the change rejected?
249 * Returns 0 if granted; +ve if granted, but inode_killpriv() is required; and
250 * -ve to deny the change.
252 int cap_inode_need_killpriv(struct dentry *dentry)
254 struct inode *inode = dentry->d_inode;
257 if (!inode->i_op || !inode->i_op->getxattr)
260 error = inode->i_op->getxattr(dentry, XATTR_NAME_CAPS, NULL, 0);
267 * cap_inode_killpriv - Erase the security markings on an inode
268 * @dentry: The inode/dentry to alter
270 * Erase the privilege-enhancing security markings on an inode.
272 * Returns 0 if successful, -ve on error.
274 int cap_inode_killpriv(struct dentry *dentry)
276 struct inode *inode = dentry->d_inode;
278 if (!inode->i_op || !inode->i_op->removexattr)
281 return inode->i_op->removexattr(dentry, XATTR_NAME_CAPS);
285 * Calculate the new process capability sets from the capability sets attached
288 static inline int bprm_caps_from_vfs_caps(struct cpu_vfs_cap_data *caps,
289 struct linux_binprm *bprm,
292 struct cred *new = bprm->cred;
296 if (caps->magic_etc & VFS_CAP_FLAGS_EFFECTIVE)
299 CAP_FOR_EACH_U32(i) {
300 __u32 permitted = caps->permitted.cap[i];
301 __u32 inheritable = caps->inheritable.cap[i];
304 * pP' = (X & fP) | (pI & fI)
306 new->cap_permitted.cap[i] =
307 (new->cap_bset.cap[i] & permitted) |
308 (new->cap_inheritable.cap[i] & inheritable);
310 if (permitted & ~new->cap_permitted.cap[i])
311 /* insufficient to execute correctly */
316 * For legacy apps, with no internal support for recognizing they
317 * do not have enough capabilities, we return an error if they are
318 * missing some "forced" (aka file-permitted) capabilities.
320 return *effective ? ret : 0;
324 * Extract the on-exec-apply capability sets for an executable file.
326 int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps)
328 struct inode *inode = dentry->d_inode;
332 struct vfs_cap_data caps;
334 memset(cpu_caps, 0, sizeof(struct cpu_vfs_cap_data));
336 if (!inode || !inode->i_op || !inode->i_op->getxattr)
339 size = inode->i_op->getxattr((struct dentry *)dentry, XATTR_NAME_CAPS, &caps,
341 if (size == -ENODATA || size == -EOPNOTSUPP)
342 /* no data, that's ok */
347 if (size < sizeof(magic_etc))
350 cpu_caps->magic_etc = magic_etc = le32_to_cpu(caps.magic_etc);
352 switch (magic_etc & VFS_CAP_REVISION_MASK) {
353 case VFS_CAP_REVISION_1:
354 if (size != XATTR_CAPS_SZ_1)
356 tocopy = VFS_CAP_U32_1;
358 case VFS_CAP_REVISION_2:
359 if (size != XATTR_CAPS_SZ_2)
361 tocopy = VFS_CAP_U32_2;
367 CAP_FOR_EACH_U32(i) {
370 cpu_caps->permitted.cap[i] = le32_to_cpu(caps.data[i].permitted);
371 cpu_caps->inheritable.cap[i] = le32_to_cpu(caps.data[i].inheritable);
378 * Attempt to get the on-exec apply capability sets for an executable file from
379 * its xattrs and, if present, apply them to the proposed credentials being
380 * constructed by execve().
382 static int get_file_caps(struct linux_binprm *bprm, bool *effective)
384 struct dentry *dentry;
386 struct cpu_vfs_cap_data vcaps;
388 bprm_clear_caps(bprm);
390 if (!file_caps_enabled)
393 if (bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID)
396 dentry = dget(bprm->file->f_dentry);
398 rc = get_vfs_caps_from_disk(dentry, &vcaps);
401 printk(KERN_NOTICE "%s: get_vfs_caps_from_disk returned %d for %s\n",
402 __func__, rc, bprm->filename);
403 else if (rc == -ENODATA)
408 rc = bprm_caps_from_vfs_caps(&vcaps, bprm, effective);
410 printk(KERN_NOTICE "%s: cap_from_disk returned %d for %s\n",
411 __func__, rc, bprm->filename);
416 bprm_clear_caps(bprm);
422 int cap_inode_need_killpriv(struct dentry *dentry)
427 int cap_inode_killpriv(struct dentry *dentry)
432 int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps)
434 memset(cpu_caps, 0, sizeof(struct cpu_vfs_cap_data));
438 static inline int get_file_caps(struct linux_binprm *bprm, bool *effective)
440 bprm_clear_caps(bprm);
446 * Determine whether a exec'ing process's new permitted capabilities should be
447 * limited to just what it already has.
449 * This prevents processes that are being ptraced from gaining access to
450 * CAP_SETPCAP, unless the process they're tracing already has it, and the
451 * binary they're executing has filecaps that elevate it.
453 * Returns 1 if they should be limited, 0 if they are not.
455 static inline int cap_limit_ptraced_target(void)
457 #ifndef CONFIG_SECURITY_FILE_CAPABILITIES
458 if (capable(CAP_SETPCAP))
465 * cap_bprm_set_creds - Set up the proposed credentials for execve().
466 * @bprm: The execution parameters, including the proposed creds
468 * Set up the proposed credentials for a new execution context being
469 * constructed by execve(). The proposed creds in @bprm->cred is altered,
470 * which won't take effect immediately. Returns 0 if successful, -ve on error.
472 int cap_bprm_set_creds(struct linux_binprm *bprm)
474 const struct cred *old = current_cred();
475 struct cred *new = bprm->cred;
480 ret = get_file_caps(bprm, &effective);
484 if (!issecure(SECURE_NOROOT)) {
486 * To support inheritance of root-permissions and suid-root
487 * executables under compatibility mode, we override the
488 * capability sets for the file.
490 * If only the real uid is 0, we do not set the effective bit.
492 if (new->euid == 0 || new->uid == 0) {
493 /* pP' = (cap_bset & ~0) | (pI & ~0) */
494 new->cap_permitted = cap_combine(old->cap_bset,
495 old->cap_inheritable);
501 /* Don't let someone trace a set[ug]id/setpcap binary with the revised
502 * credentials unless they have the appropriate permit
504 if ((new->euid != old->uid ||
505 new->egid != old->gid ||
506 !cap_issubset(new->cap_permitted, old->cap_permitted)) &&
507 bprm->unsafe & ~LSM_UNSAFE_PTRACE_CAP) {
508 /* downgrade; they get no more than they had, and maybe less */
509 if (!capable(CAP_SETUID)) {
510 new->euid = new->uid;
511 new->egid = new->gid;
513 if (cap_limit_ptraced_target())
514 new->cap_permitted = cap_intersect(new->cap_permitted,
518 new->suid = new->fsuid = new->euid;
519 new->sgid = new->fsgid = new->egid;
521 /* For init, we want to retain the capabilities set in the initial
522 * task. Thus we skip the usual capability rules
524 if (!is_global_init(current)) {
526 new->cap_effective = new->cap_permitted;
528 cap_clear(new->cap_effective);
530 bprm->cap_effective = effective;
533 * Audit candidate if current->cap_effective is set
535 * We do not bother to audit if 3 things are true:
536 * 1) cap_effective has all caps
538 * 3) root is supposed to have all caps (SECURE_NOROOT)
539 * Since this is just a normal root execing a process.
541 * Number 1 above might fail if you don't have a full bset, but I think
542 * that is interesting information to audit.
544 if (!cap_isclear(new->cap_effective)) {
545 if (!cap_issubset(CAP_FULL_SET, new->cap_effective) ||
546 new->euid != 0 || new->uid != 0 ||
547 issecure(SECURE_NOROOT)) {
548 ret = audit_log_bprm_fcaps(bprm, new, old);
554 new->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);
559 * cap_bprm_secureexec - Determine whether a secure execution is required
560 * @bprm: The execution parameters
562 * Determine whether a secure execution is required, return 1 if it is, and 0
565 * The credentials have been committed by this point, and so are no longer
566 * available through @bprm->cred.
568 int cap_bprm_secureexec(struct linux_binprm *bprm)
570 const struct cred *cred = current_cred();
572 if (cred->uid != 0) {
573 if (bprm->cap_effective)
575 if (!cap_isclear(cred->cap_permitted))
579 return (cred->euid != cred->uid ||
580 cred->egid != cred->gid);
584 * cap_inode_setxattr - Determine whether an xattr may be altered
585 * @dentry: The inode/dentry being altered
586 * @name: The name of the xattr to be changed
587 * @value: The value that the xattr will be changed to
588 * @size: The size of value
589 * @flags: The replacement flag
591 * Determine whether an xattr may be altered or set on an inode, returning 0 if
592 * permission is granted, -ve if denied.
594 * This is used to make sure security xattrs don't get updated or set by those
595 * who aren't privileged to do so.
597 int cap_inode_setxattr(struct dentry *dentry, const char *name,
598 const void *value, size_t size, int flags)
600 if (!strcmp(name, XATTR_NAME_CAPS)) {
601 if (!capable(CAP_SETFCAP))
606 if (!strncmp(name, XATTR_SECURITY_PREFIX,
607 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
608 !capable(CAP_SYS_ADMIN))
614 * cap_inode_removexattr - Determine whether an xattr may be removed
615 * @dentry: The inode/dentry being altered
616 * @name: The name of the xattr to be changed
618 * Determine whether an xattr may be removed from an inode, returning 0 if
619 * permission is granted, -ve if denied.
621 * This is used to make sure security xattrs don't get removed by those who
622 * aren't privileged to remove them.
624 int cap_inode_removexattr(struct dentry *dentry, const char *name)
626 if (!strcmp(name, XATTR_NAME_CAPS)) {
627 if (!capable(CAP_SETFCAP))
632 if (!strncmp(name, XATTR_SECURITY_PREFIX,
633 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
634 !capable(CAP_SYS_ADMIN))
640 * cap_emulate_setxuid() fixes the effective / permitted capabilities of
641 * a process after a call to setuid, setreuid, or setresuid.
643 * 1) When set*uiding _from_ one of {r,e,s}uid == 0 _to_ all of
644 * {r,e,s}uid != 0, the permitted and effective capabilities are
647 * 2) When set*uiding _from_ euid == 0 _to_ euid != 0, the effective
648 * capabilities of the process are cleared.
650 * 3) When set*uiding _from_ euid != 0 _to_ euid == 0, the effective
651 * capabilities are set to the permitted capabilities.
653 * fsuid is handled elsewhere. fsuid == 0 and {r,e,s}uid!= 0 should
658 * cevans - New behaviour, Oct '99
659 * A process may, via prctl(), elect to keep its capabilities when it
660 * calls setuid() and switches away from uid==0. Both permitted and
661 * effective sets will be retained.
662 * Without this change, it was impossible for a daemon to drop only some
663 * of its privilege. The call to setuid(!=0) would drop all privileges!
664 * Keeping uid 0 is not an option because uid 0 owns too many vital
666 * Thanks to Olaf Kirch and Peter Benie for spotting this.
668 static inline void cap_emulate_setxuid(struct cred *new, const struct cred *old)
670 if ((old->uid == 0 || old->euid == 0 || old->suid == 0) &&
671 (new->uid != 0 && new->euid != 0 && new->suid != 0) &&
672 !issecure(SECURE_KEEP_CAPS)) {
673 cap_clear(new->cap_permitted);
674 cap_clear(new->cap_effective);
676 if (old->euid == 0 && new->euid != 0)
677 cap_clear(new->cap_effective);
678 if (old->euid != 0 && new->euid == 0)
679 new->cap_effective = new->cap_permitted;
683 * cap_task_fix_setuid - Fix up the results of setuid() call
684 * @new: The proposed credentials
685 * @old: The current task's current credentials
686 * @flags: Indications of what has changed
688 * Fix up the results of setuid() call before the credential changes are
689 * actually applied, returning 0 to grant the changes, -ve to deny them.
691 int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags)
697 /* juggle the capabilities to follow [RES]UID changes unless
698 * otherwise suppressed */
699 if (!issecure(SECURE_NO_SETUID_FIXUP))
700 cap_emulate_setxuid(new, old);
704 /* juggle the capabilties to follow FSUID changes, unless
705 * otherwise suppressed
707 * FIXME - is fsuser used for all CAP_FS_MASK capabilities?
708 * if not, we might be a bit too harsh here.
710 if (!issecure(SECURE_NO_SETUID_FIXUP)) {
711 if (old->fsuid == 0 && new->fsuid != 0)
713 cap_drop_fs_set(new->cap_effective);
715 if (old->fsuid != 0 && new->fsuid == 0)
717 cap_raise_fs_set(new->cap_effective,
729 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
731 * Rationale: code calling task_setscheduler, task_setioprio, and
732 * task_setnice, assumes that
733 * . if capable(cap_sys_nice), then those actions should be allowed
734 * . if not capable(cap_sys_nice), but acting on your own processes,
735 * then those actions should be allowed
736 * This is insufficient now since you can call code without suid, but
737 * yet with increased caps.
738 * So we check for increased caps on the target process.
740 static int cap_safe_nice(struct task_struct *p)
745 is_subset = cap_issubset(__task_cred(p)->cap_permitted,
746 current_cred()->cap_permitted);
749 if (!is_subset && !capable(CAP_SYS_NICE))
755 * cap_task_setscheduler - Detemine if scheduler policy change is permitted
756 * @p: The task to affect
757 * @policy: The policy to effect
758 * @lp: The parameters to the scheduling policy
760 * Detemine if the requested scheduler policy change is permitted for the
761 * specified task, returning 0 if permission is granted, -ve if denied.
763 int cap_task_setscheduler(struct task_struct *p, int policy,
764 struct sched_param *lp)
766 return cap_safe_nice(p);
770 * cap_task_ioprio - Detemine if I/O priority change is permitted
771 * @p: The task to affect
772 * @ioprio: The I/O priority to set
774 * Detemine if the requested I/O priority change is permitted for the specified
775 * task, returning 0 if permission is granted, -ve if denied.
777 int cap_task_setioprio(struct task_struct *p, int ioprio)
779 return cap_safe_nice(p);
783 * cap_task_ioprio - Detemine if task priority change is permitted
784 * @p: The task to affect
785 * @nice: The nice value to set
787 * Detemine if the requested task priority change is permitted for the
788 * specified task, returning 0 if permission is granted, -ve if denied.
790 int cap_task_setnice(struct task_struct *p, int nice)
792 return cap_safe_nice(p);
796 * Implement PR_CAPBSET_DROP. Attempt to remove the specified capability from
797 * the current task's bounding set. Returns 0 on success, -ve on error.
799 static long cap_prctl_drop(struct cred *new, unsigned long cap)
801 if (!capable(CAP_SETPCAP))
806 cap_lower(new->cap_bset, cap);
811 int cap_task_setscheduler (struct task_struct *p, int policy,
812 struct sched_param *lp)
816 int cap_task_setioprio (struct task_struct *p, int ioprio)
820 int cap_task_setnice (struct task_struct *p, int nice)
827 * cap_task_prctl - Implement process control functions for this security module
828 * @option: The process control function requested
829 * @arg2, @arg3, @arg4, @arg5: The argument data for this function
831 * Allow process control functions (sys_prctl()) to alter capabilities; may
832 * also deny access to other functions not otherwise implemented here.
834 * Returns 0 or +ve on success, -ENOSYS if this function is not implemented
835 * here, other -ve on error. If -ENOSYS is returned, sys_prctl() and other LSM
836 * modules will consider performing the function.
838 int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
839 unsigned long arg4, unsigned long arg5)
844 new = prepare_creds();
849 case PR_CAPBSET_READ:
851 if (!cap_valid(arg2))
853 error = !!cap_raised(new->cap_bset, arg2);
856 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
857 case PR_CAPBSET_DROP:
858 error = cap_prctl_drop(new, arg2);
864 * The next four prctl's remain to assist with transitioning a
865 * system from legacy UID=0 based privilege (when filesystem
866 * capabilities are not in use) to a system using filesystem
867 * capabilities only - as the POSIX.1e draft intended.
871 * PR_SET_SECUREBITS =
872 * issecure_mask(SECURE_KEEP_CAPS_LOCKED)
873 * | issecure_mask(SECURE_NOROOT)
874 * | issecure_mask(SECURE_NOROOT_LOCKED)
875 * | issecure_mask(SECURE_NO_SETUID_FIXUP)
876 * | issecure_mask(SECURE_NO_SETUID_FIXUP_LOCKED)
878 * will ensure that the current process and all of its
879 * children will be locked into a pure
880 * capability-based-privilege environment.
882 case PR_SET_SECUREBITS:
884 if ((((new->securebits & SECURE_ALL_LOCKS) >> 1)
885 & (new->securebits ^ arg2)) /*[1]*/
886 || ((new->securebits & SECURE_ALL_LOCKS & ~arg2)) /*[2]*/
887 || (arg2 & ~(SECURE_ALL_LOCKS | SECURE_ALL_BITS)) /*[3]*/
888 || (cap_capable(CAP_SETPCAP, SECURITY_CAP_AUDIT) != 0) /*[4]*/
890 * [1] no changing of bits that are locked
891 * [2] no unlocking of locks
892 * [3] no setting of unsupported bits
893 * [4] doing anything requires privilege (go read about
894 * the "sendmail capabilities bug")
897 /* cannot change a locked bit */
899 new->securebits = arg2;
902 case PR_GET_SECUREBITS:
903 error = new->securebits;
906 #endif /* def CONFIG_SECURITY_FILE_CAPABILITIES */
908 case PR_GET_KEEPCAPS:
909 if (issecure(SECURE_KEEP_CAPS))
913 case PR_SET_KEEPCAPS:
915 if (arg2 > 1) /* Note, we rely on arg2 being unsigned here */
918 if (issecure(SECURE_KEEP_CAPS_LOCKED))
921 new->securebits |= issecure_mask(SECURE_KEEP_CAPS);
923 new->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);
927 /* No functionality available - continue with default */
932 /* Functionality provided */
934 return commit_creds(new);
944 * cap_syslog - Determine whether syslog function is permitted
945 * @type: Function requested
947 * Determine whether the current process is permitted to use a particular
948 * syslog function, returning 0 if permission is granted, -ve if not.
950 int cap_syslog(int type)
952 if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
958 * cap_vm_enough_memory - Determine whether a new virtual mapping is permitted
959 * @mm: The VM space in which the new mapping is to be made
960 * @pages: The size of the mapping
962 * Determine whether the allocation of a new virtual mapping by the current
963 * task is permitted, returning 0 if permission is granted, -ve if not.
965 int cap_vm_enough_memory(struct mm_struct *mm, long pages)
967 int cap_sys_admin = 0;
969 if (cap_capable(CAP_SYS_ADMIN, SECURITY_CAP_NOAUDIT) == 0)
971 return __vm_enough_memory(mm, pages, cap_sys_admin);