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 #ifdef CONFIG_ANDROID_PARANOID_NETWORK
32 #include <linux/android_aid.h>
36 * If a non-root user executes a setuid-root binary in
37 * !secure(SECURE_NOROOT) mode, then we raise capabilities.
38 * However if fE is also set, then the intent is for only
39 * the file capabilities to be applied, and the setuid-root
40 * bit is left on either to change the uid (plausible) or
41 * to get full privilege on a kernel without file capabilities
42 * support. So in that case we do not raise capabilities.
44 * Warn if that happens, once per boot.
46 static void warn_setuid_and_fcaps_mixed(char *fname
)
50 printk(KERN_INFO
"warning: `%s' has both setuid-root and"
51 " effective capabilities. Therefore not raising all"
52 " capabilities.\n", fname
);
57 int cap_netlink_send(struct sock
*sk
, struct sk_buff
*skb
)
59 NETLINK_CB(skb
).eff_cap
= current_cap();
63 int cap_netlink_recv(struct sk_buff
*skb
, int cap
)
65 if (!cap_raised(NETLINK_CB(skb
).eff_cap
, cap
))
69 EXPORT_SYMBOL(cap_netlink_recv
);
72 * cap_capable - Determine whether a task has a particular effective capability
73 * @tsk: The task to query
74 * @cred: The credentials to use
75 * @cap: The capability to check for
76 * @audit: Whether to write an audit message or not
78 * Determine whether the nominated task has the specified capability amongst
79 * its effective set, returning 0 if it does, -ve if it does not.
81 * NOTE WELL: cap_has_capability() cannot be used like the kernel's capable()
82 * and has_capability() functions. That is, it has the reverse semantics:
83 * cap_has_capability() returns 0 when a task has a capability, but the
84 * kernel's capable() and has_capability() returns 1 for this case.
86 int cap_capable(struct task_struct
*tsk
, const struct cred
*cred
, int cap
,
89 #ifdef CONFIG_ANDROID_PARANOID_NETWORK
90 if (cap
== CAP_NET_RAW
&& in_egroup_p(AID_NET_RAW
))
92 if (cap
== CAP_NET_ADMIN
&& in_egroup_p(AID_NET_ADMIN
))
95 return cap_raised(cred
->cap_effective
, cap
) ? 0 : -EPERM
;
99 * cap_settime - Determine whether the current process may set the system clock
100 * @ts: The time to set
101 * @tz: The timezone to set
103 * Determine whether the current process may set the system clock and timezone
104 * information, returning 0 if permission granted, -ve if denied.
106 int cap_settime(struct timespec
*ts
, struct timezone
*tz
)
108 if (!capable(CAP_SYS_TIME
))
114 * cap_ptrace_access_check - Determine whether the current process may access
116 * @child: The process to be accessed
117 * @mode: The mode of attachment.
119 * Determine whether a process may access another, returning 0 if permission
120 * granted, -ve if denied.
122 int cap_ptrace_access_check(struct task_struct
*child
, unsigned int mode
)
127 if (!cap_issubset(__task_cred(child
)->cap_permitted
,
128 current_cred()->cap_permitted
) &&
129 !capable(CAP_SYS_PTRACE
))
136 * cap_ptrace_traceme - Determine whether another process may trace the current
137 * @parent: The task proposed to be the tracer
139 * Determine whether the nominated task is permitted to trace the current
140 * process, returning 0 if permission is granted, -ve if denied.
142 int cap_ptrace_traceme(struct task_struct
*parent
)
147 if (!cap_issubset(current_cred()->cap_permitted
,
148 __task_cred(parent
)->cap_permitted
) &&
149 !has_capability(parent
, CAP_SYS_PTRACE
))
156 * cap_capget - Retrieve a task's capability sets
157 * @target: The task from which to retrieve the capability sets
158 * @effective: The place to record the effective set
159 * @inheritable: The place to record the inheritable set
160 * @permitted: The place to record the permitted set
162 * This function retrieves the capabilities of the nominated task and returns
163 * them to the caller.
165 int cap_capget(struct task_struct
*target
, kernel_cap_t
*effective
,
166 kernel_cap_t
*inheritable
, kernel_cap_t
*permitted
)
168 const struct cred
*cred
;
170 /* Derived from kernel/capability.c:sys_capget. */
172 cred
= __task_cred(target
);
173 *effective
= cred
->cap_effective
;
174 *inheritable
= cred
->cap_inheritable
;
175 *permitted
= cred
->cap_permitted
;
181 * Determine whether the inheritable capabilities are limited to the old
182 * permitted set. Returns 1 if they are limited, 0 if they are not.
184 static inline int cap_inh_is_capped(void)
186 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
188 /* they are so limited unless the current task has the CAP_SETPCAP
191 if (cap_capable(current
, current_cred(), CAP_SETPCAP
,
192 SECURITY_CAP_AUDIT
) == 0)
199 * cap_capset - Validate and apply proposed changes to current's capabilities
200 * @new: The proposed new credentials; alterations should be made here
201 * @old: The current task's current credentials
202 * @effective: A pointer to the proposed new effective capabilities set
203 * @inheritable: A pointer to the proposed new inheritable capabilities set
204 * @permitted: A pointer to the proposed new permitted capabilities set
206 * This function validates and applies a proposed mass change to the current
207 * process's capability sets. The changes are made to the proposed new
208 * credentials, and assuming no error, will be committed by the caller of LSM.
210 int cap_capset(struct cred
*new,
211 const struct cred
*old
,
212 const kernel_cap_t
*effective
,
213 const kernel_cap_t
*inheritable
,
214 const kernel_cap_t
*permitted
)
216 if (cap_inh_is_capped() &&
217 !cap_issubset(*inheritable
,
218 cap_combine(old
->cap_inheritable
,
219 old
->cap_permitted
)))
220 /* incapable of using this inheritable set */
223 if (!cap_issubset(*inheritable
,
224 cap_combine(old
->cap_inheritable
,
226 /* no new pI capabilities outside bounding set */
229 /* verify restrictions on target's new Permitted set */
230 if (!cap_issubset(*permitted
, old
->cap_permitted
))
233 /* verify the _new_Effective_ is a subset of the _new_Permitted_ */
234 if (!cap_issubset(*effective
, *permitted
))
237 new->cap_effective
= *effective
;
238 new->cap_inheritable
= *inheritable
;
239 new->cap_permitted
= *permitted
;
244 * Clear proposed capability sets for execve().
246 static inline void bprm_clear_caps(struct linux_binprm
*bprm
)
248 cap_clear(bprm
->cred
->cap_permitted
);
249 bprm
->cap_effective
= false;
252 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
255 * cap_inode_need_killpriv - Determine if inode change affects privileges
256 * @dentry: The inode/dentry in being changed with change marked ATTR_KILL_PRIV
258 * Determine if an inode having a change applied that's marked ATTR_KILL_PRIV
259 * affects the security markings on that inode, and if it is, should
260 * inode_killpriv() be invoked or the change rejected?
262 * Returns 0 if granted; +ve if granted, but inode_killpriv() is required; and
263 * -ve to deny the change.
265 int cap_inode_need_killpriv(struct dentry
*dentry
)
267 struct inode
*inode
= dentry
->d_inode
;
270 if (!inode
->i_op
->getxattr
)
273 error
= inode
->i_op
->getxattr(dentry
, XATTR_NAME_CAPS
, NULL
, 0);
280 * cap_inode_killpriv - Erase the security markings on an inode
281 * @dentry: The inode/dentry to alter
283 * Erase the privilege-enhancing security markings on an inode.
285 * Returns 0 if successful, -ve on error.
287 int cap_inode_killpriv(struct dentry
*dentry
)
289 struct inode
*inode
= dentry
->d_inode
;
291 if (!inode
->i_op
->removexattr
)
294 return inode
->i_op
->removexattr(dentry
, XATTR_NAME_CAPS
);
298 * Calculate the new process capability sets from the capability sets attached
301 static inline int bprm_caps_from_vfs_caps(struct cpu_vfs_cap_data
*caps
,
302 struct linux_binprm
*bprm
,
305 struct cred
*new = bprm
->cred
;
309 if (caps
->magic_etc
& VFS_CAP_FLAGS_EFFECTIVE
)
312 CAP_FOR_EACH_U32(i
) {
313 __u32 permitted
= caps
->permitted
.cap
[i
];
314 __u32 inheritable
= caps
->inheritable
.cap
[i
];
317 * pP' = (X & fP) | (pI & fI)
319 new->cap_permitted
.cap
[i
] =
320 (new->cap_bset
.cap
[i
] & permitted
) |
321 (new->cap_inheritable
.cap
[i
] & inheritable
);
323 if (permitted
& ~new->cap_permitted
.cap
[i
])
324 /* insufficient to execute correctly */
329 * For legacy apps, with no internal support for recognizing they
330 * do not have enough capabilities, we return an error if they are
331 * missing some "forced" (aka file-permitted) capabilities.
333 return *effective
? ret
: 0;
337 * Extract the on-exec-apply capability sets for an executable file.
339 int get_vfs_caps_from_disk(const struct dentry
*dentry
, struct cpu_vfs_cap_data
*cpu_caps
)
341 struct inode
*inode
= dentry
->d_inode
;
345 struct vfs_cap_data caps
;
347 memset(cpu_caps
, 0, sizeof(struct cpu_vfs_cap_data
));
349 if (!inode
|| !inode
->i_op
->getxattr
)
352 size
= inode
->i_op
->getxattr((struct dentry
*)dentry
, XATTR_NAME_CAPS
, &caps
,
354 if (size
== -ENODATA
|| size
== -EOPNOTSUPP
)
355 /* no data, that's ok */
360 if (size
< sizeof(magic_etc
))
363 cpu_caps
->magic_etc
= magic_etc
= le32_to_cpu(caps
.magic_etc
);
365 switch (magic_etc
& VFS_CAP_REVISION_MASK
) {
366 case VFS_CAP_REVISION_1
:
367 if (size
!= XATTR_CAPS_SZ_1
)
369 tocopy
= VFS_CAP_U32_1
;
371 case VFS_CAP_REVISION_2
:
372 if (size
!= XATTR_CAPS_SZ_2
)
374 tocopy
= VFS_CAP_U32_2
;
380 CAP_FOR_EACH_U32(i
) {
383 cpu_caps
->permitted
.cap
[i
] = le32_to_cpu(caps
.data
[i
].permitted
);
384 cpu_caps
->inheritable
.cap
[i
] = le32_to_cpu(caps
.data
[i
].inheritable
);
391 * Attempt to get the on-exec apply capability sets for an executable file from
392 * its xattrs and, if present, apply them to the proposed credentials being
393 * constructed by execve().
395 static int get_file_caps(struct linux_binprm
*bprm
, bool *effective
)
397 struct dentry
*dentry
;
399 struct cpu_vfs_cap_data vcaps
;
401 bprm_clear_caps(bprm
);
403 if (!file_caps_enabled
)
406 if (bprm
->file
->f_vfsmnt
->mnt_flags
& MNT_NOSUID
)
409 dentry
= dget(bprm
->file
->f_dentry
);
411 rc
= get_vfs_caps_from_disk(dentry
, &vcaps
);
414 printk(KERN_NOTICE
"%s: get_vfs_caps_from_disk returned %d for %s\n",
415 __func__
, rc
, bprm
->filename
);
416 else if (rc
== -ENODATA
)
421 rc
= bprm_caps_from_vfs_caps(&vcaps
, bprm
, effective
);
423 printk(KERN_NOTICE
"%s: cap_from_disk returned %d for %s\n",
424 __func__
, rc
, bprm
->filename
);
429 bprm_clear_caps(bprm
);
435 int cap_inode_need_killpriv(struct dentry
*dentry
)
440 int cap_inode_killpriv(struct dentry
*dentry
)
445 int get_vfs_caps_from_disk(const struct dentry
*dentry
, struct cpu_vfs_cap_data
*cpu_caps
)
447 memset(cpu_caps
, 0, sizeof(struct cpu_vfs_cap_data
));
451 static inline int get_file_caps(struct linux_binprm
*bprm
, bool *effective
)
453 bprm_clear_caps(bprm
);
459 * Determine whether a exec'ing process's new permitted capabilities should be
460 * limited to just what it already has.
462 * This prevents processes that are being ptraced from gaining access to
463 * CAP_SETPCAP, unless the process they're tracing already has it, and the
464 * binary they're executing has filecaps that elevate it.
466 * Returns 1 if they should be limited, 0 if they are not.
468 static inline int cap_limit_ptraced_target(void)
470 #ifndef CONFIG_SECURITY_FILE_CAPABILITIES
471 if (capable(CAP_SETPCAP
))
478 * cap_bprm_set_creds - Set up the proposed credentials for execve().
479 * @bprm: The execution parameters, including the proposed creds
481 * Set up the proposed credentials for a new execution context being
482 * constructed by execve(). The proposed creds in @bprm->cred is altered,
483 * which won't take effect immediately. Returns 0 if successful, -ve on error.
485 int cap_bprm_set_creds(struct linux_binprm
*bprm
)
487 const struct cred
*old
= current_cred();
488 struct cred
*new = bprm
->cred
;
493 ret
= get_file_caps(bprm
, &effective
);
497 if (!issecure(SECURE_NOROOT
)) {
499 * If the legacy file capability is set, then don't set privs
500 * for a setuid root binary run by a non-root user. Do set it
501 * for a root user just to cause least surprise to an admin.
503 if (effective
&& new->uid
!= 0 && new->euid
== 0) {
504 warn_setuid_and_fcaps_mixed(bprm
->filename
);
508 * To support inheritance of root-permissions and suid-root
509 * executables under compatibility mode, we override the
510 * capability sets for the file.
512 * If only the real uid is 0, we do not set the effective bit.
514 if (new->euid
== 0 || new->uid
== 0) {
515 /* pP' = (cap_bset & ~0) | (pI & ~0) */
516 new->cap_permitted
= cap_combine(old
->cap_bset
,
517 old
->cap_inheritable
);
524 /* Don't let someone trace a set[ug]id/setpcap binary with the revised
525 * credentials unless they have the appropriate permit
527 if ((new->euid
!= old
->uid
||
528 new->egid
!= old
->gid
||
529 !cap_issubset(new->cap_permitted
, old
->cap_permitted
)) &&
530 bprm
->unsafe
& ~LSM_UNSAFE_PTRACE_CAP
) {
531 /* downgrade; they get no more than they had, and maybe less */
532 if (!capable(CAP_SETUID
)) {
533 new->euid
= new->uid
;
534 new->egid
= new->gid
;
536 if (cap_limit_ptraced_target())
537 new->cap_permitted
= cap_intersect(new->cap_permitted
,
541 new->suid
= new->fsuid
= new->euid
;
542 new->sgid
= new->fsgid
= new->egid
;
544 /* For init, we want to retain the capabilities set in the initial
545 * task. Thus we skip the usual capability rules
547 if (!is_global_init(current
)) {
549 new->cap_effective
= new->cap_permitted
;
551 cap_clear(new->cap_effective
);
553 bprm
->cap_effective
= effective
;
556 * Audit candidate if current->cap_effective is set
558 * We do not bother to audit if 3 things are true:
559 * 1) cap_effective has all caps
561 * 3) root is supposed to have all caps (SECURE_NOROOT)
562 * Since this is just a normal root execing a process.
564 * Number 1 above might fail if you don't have a full bset, but I think
565 * that is interesting information to audit.
567 if (!cap_isclear(new->cap_effective
)) {
568 if (!cap_issubset(CAP_FULL_SET
, new->cap_effective
) ||
569 new->euid
!= 0 || new->uid
!= 0 ||
570 issecure(SECURE_NOROOT
)) {
571 ret
= audit_log_bprm_fcaps(bprm
, new, old
);
577 new->securebits
&= ~issecure_mask(SECURE_KEEP_CAPS
);
582 * cap_bprm_secureexec - Determine whether a secure execution is required
583 * @bprm: The execution parameters
585 * Determine whether a secure execution is required, return 1 if it is, and 0
588 * The credentials have been committed by this point, and so are no longer
589 * available through @bprm->cred.
591 int cap_bprm_secureexec(struct linux_binprm
*bprm
)
593 const struct cred
*cred
= current_cred();
595 if (cred
->uid
!= 0) {
596 if (bprm
->cap_effective
)
598 if (!cap_isclear(cred
->cap_permitted
))
602 return (cred
->euid
!= cred
->uid
||
603 cred
->egid
!= cred
->gid
);
607 * cap_inode_setxattr - Determine whether an xattr may be altered
608 * @dentry: The inode/dentry being altered
609 * @name: The name of the xattr to be changed
610 * @value: The value that the xattr will be changed to
611 * @size: The size of value
612 * @flags: The replacement flag
614 * Determine whether an xattr may be altered or set on an inode, returning 0 if
615 * permission is granted, -ve if denied.
617 * This is used to make sure security xattrs don't get updated or set by those
618 * who aren't privileged to do so.
620 int cap_inode_setxattr(struct dentry
*dentry
, const char *name
,
621 const void *value
, size_t size
, int flags
)
623 if (!strcmp(name
, XATTR_NAME_CAPS
)) {
624 if (!capable(CAP_SETFCAP
))
629 if (!strncmp(name
, XATTR_SECURITY_PREFIX
,
630 sizeof(XATTR_SECURITY_PREFIX
) - 1) &&
631 !capable(CAP_SYS_ADMIN
))
637 * cap_inode_removexattr - Determine whether an xattr may be removed
638 * @dentry: The inode/dentry being altered
639 * @name: The name of the xattr to be changed
641 * Determine whether an xattr may be removed from an inode, returning 0 if
642 * permission is granted, -ve if denied.
644 * This is used to make sure security xattrs don't get removed by those who
645 * aren't privileged to remove them.
647 int cap_inode_removexattr(struct dentry
*dentry
, const char *name
)
649 if (!strcmp(name
, XATTR_NAME_CAPS
)) {
650 if (!capable(CAP_SETFCAP
))
655 if (!strncmp(name
, XATTR_SECURITY_PREFIX
,
656 sizeof(XATTR_SECURITY_PREFIX
) - 1) &&
657 !capable(CAP_SYS_ADMIN
))
663 * cap_emulate_setxuid() fixes the effective / permitted capabilities of
664 * a process after a call to setuid, setreuid, or setresuid.
666 * 1) When set*uiding _from_ one of {r,e,s}uid == 0 _to_ all of
667 * {r,e,s}uid != 0, the permitted and effective capabilities are
670 * 2) When set*uiding _from_ euid == 0 _to_ euid != 0, the effective
671 * capabilities of the process are cleared.
673 * 3) When set*uiding _from_ euid != 0 _to_ euid == 0, the effective
674 * capabilities are set to the permitted capabilities.
676 * fsuid is handled elsewhere. fsuid == 0 and {r,e,s}uid!= 0 should
681 * cevans - New behaviour, Oct '99
682 * A process may, via prctl(), elect to keep its capabilities when it
683 * calls setuid() and switches away from uid==0. Both permitted and
684 * effective sets will be retained.
685 * Without this change, it was impossible for a daemon to drop only some
686 * of its privilege. The call to setuid(!=0) would drop all privileges!
687 * Keeping uid 0 is not an option because uid 0 owns too many vital
689 * Thanks to Olaf Kirch and Peter Benie for spotting this.
691 static inline void cap_emulate_setxuid(struct cred
*new, const struct cred
*old
)
693 if ((old
->uid
== 0 || old
->euid
== 0 || old
->suid
== 0) &&
694 (new->uid
!= 0 && new->euid
!= 0 && new->suid
!= 0) &&
695 !issecure(SECURE_KEEP_CAPS
)) {
696 cap_clear(new->cap_permitted
);
697 cap_clear(new->cap_effective
);
699 if (old
->euid
== 0 && new->euid
!= 0)
700 cap_clear(new->cap_effective
);
701 if (old
->euid
!= 0 && new->euid
== 0)
702 new->cap_effective
= new->cap_permitted
;
706 * cap_task_fix_setuid - Fix up the results of setuid() call
707 * @new: The proposed credentials
708 * @old: The current task's current credentials
709 * @flags: Indications of what has changed
711 * Fix up the results of setuid() call before the credential changes are
712 * actually applied, returning 0 to grant the changes, -ve to deny them.
714 int cap_task_fix_setuid(struct cred
*new, const struct cred
*old
, int flags
)
720 /* juggle the capabilities to follow [RES]UID changes unless
721 * otherwise suppressed */
722 if (!issecure(SECURE_NO_SETUID_FIXUP
))
723 cap_emulate_setxuid(new, old
);
727 /* juggle the capabilties to follow FSUID changes, unless
728 * otherwise suppressed
730 * FIXME - is fsuser used for all CAP_FS_MASK capabilities?
731 * if not, we might be a bit too harsh here.
733 if (!issecure(SECURE_NO_SETUID_FIXUP
)) {
734 if (old
->fsuid
== 0 && new->fsuid
!= 0)
736 cap_drop_fs_set(new->cap_effective
);
738 if (old
->fsuid
!= 0 && new->fsuid
== 0)
740 cap_raise_fs_set(new->cap_effective
,
752 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
754 * Rationale: code calling task_setscheduler, task_setioprio, and
755 * task_setnice, assumes that
756 * . if capable(cap_sys_nice), then those actions should be allowed
757 * . if not capable(cap_sys_nice), but acting on your own processes,
758 * then those actions should be allowed
759 * This is insufficient now since you can call code without suid, but
760 * yet with increased caps.
761 * So we check for increased caps on the target process.
763 static int cap_safe_nice(struct task_struct
*p
)
768 is_subset
= cap_issubset(__task_cred(p
)->cap_permitted
,
769 current_cred()->cap_permitted
);
772 if (!is_subset
&& !capable(CAP_SYS_NICE
))
778 * cap_task_setscheduler - Detemine if scheduler policy change is permitted
779 * @p: The task to affect
780 * @policy: The policy to effect
781 * @lp: The parameters to the scheduling policy
783 * Detemine if the requested scheduler policy change is permitted for the
784 * specified task, returning 0 if permission is granted, -ve if denied.
786 int cap_task_setscheduler(struct task_struct
*p
, int policy
,
787 struct sched_param
*lp
)
789 return cap_safe_nice(p
);
793 * cap_task_ioprio - Detemine if I/O priority change is permitted
794 * @p: The task to affect
795 * @ioprio: The I/O priority to set
797 * Detemine if the requested I/O priority change is permitted for the specified
798 * task, returning 0 if permission is granted, -ve if denied.
800 int cap_task_setioprio(struct task_struct
*p
, int ioprio
)
802 return cap_safe_nice(p
);
806 * cap_task_ioprio - Detemine if task priority change is permitted
807 * @p: The task to affect
808 * @nice: The nice value to set
810 * Detemine if the requested task priority change is permitted for the
811 * specified task, returning 0 if permission is granted, -ve if denied.
813 int cap_task_setnice(struct task_struct
*p
, int nice
)
815 return cap_safe_nice(p
);
819 * Implement PR_CAPBSET_DROP. Attempt to remove the specified capability from
820 * the current task's bounding set. Returns 0 on success, -ve on error.
822 static long cap_prctl_drop(struct cred
*new, unsigned long cap
)
824 if (!capable(CAP_SETPCAP
))
829 cap_lower(new->cap_bset
, cap
);
834 int cap_task_setscheduler (struct task_struct
*p
, int policy
,
835 struct sched_param
*lp
)
839 int cap_task_setioprio (struct task_struct
*p
, int ioprio
)
843 int cap_task_setnice (struct task_struct
*p
, int nice
)
850 * cap_task_prctl - Implement process control functions for this security module
851 * @option: The process control function requested
852 * @arg2, @arg3, @arg4, @arg5: The argument data for this function
854 * Allow process control functions (sys_prctl()) to alter capabilities; may
855 * also deny access to other functions not otherwise implemented here.
857 * Returns 0 or +ve on success, -ENOSYS if this function is not implemented
858 * here, other -ve on error. If -ENOSYS is returned, sys_prctl() and other LSM
859 * modules will consider performing the function.
861 int cap_task_prctl(int option
, unsigned long arg2
, unsigned long arg3
,
862 unsigned long arg4
, unsigned long arg5
)
867 new = prepare_creds();
872 case PR_CAPBSET_READ
:
874 if (!cap_valid(arg2
))
876 error
= !!cap_raised(new->cap_bset
, arg2
);
879 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
880 case PR_CAPBSET_DROP
:
881 error
= cap_prctl_drop(new, arg2
);
887 * The next four prctl's remain to assist with transitioning a
888 * system from legacy UID=0 based privilege (when filesystem
889 * capabilities are not in use) to a system using filesystem
890 * capabilities only - as the POSIX.1e draft intended.
894 * PR_SET_SECUREBITS =
895 * issecure_mask(SECURE_KEEP_CAPS_LOCKED)
896 * | issecure_mask(SECURE_NOROOT)
897 * | issecure_mask(SECURE_NOROOT_LOCKED)
898 * | issecure_mask(SECURE_NO_SETUID_FIXUP)
899 * | issecure_mask(SECURE_NO_SETUID_FIXUP_LOCKED)
901 * will ensure that the current process and all of its
902 * children will be locked into a pure
903 * capability-based-privilege environment.
905 case PR_SET_SECUREBITS
:
907 if ((((new->securebits
& SECURE_ALL_LOCKS
) >> 1)
908 & (new->securebits
^ arg2
)) /*[1]*/
909 || ((new->securebits
& SECURE_ALL_LOCKS
& ~arg2
)) /*[2]*/
910 || (arg2
& ~(SECURE_ALL_LOCKS
| SECURE_ALL_BITS
)) /*[3]*/
911 || (cap_capable(current
, current_cred(), CAP_SETPCAP
,
912 SECURITY_CAP_AUDIT
) != 0) /*[4]*/
914 * [1] no changing of bits that are locked
915 * [2] no unlocking of locks
916 * [3] no setting of unsupported bits
917 * [4] doing anything requires privilege (go read about
918 * the "sendmail capabilities bug")
921 /* cannot change a locked bit */
923 new->securebits
= arg2
;
926 case PR_GET_SECUREBITS
:
927 error
= new->securebits
;
930 #endif /* def CONFIG_SECURITY_FILE_CAPABILITIES */
932 case PR_GET_KEEPCAPS
:
933 if (issecure(SECURE_KEEP_CAPS
))
937 case PR_SET_KEEPCAPS
:
939 if (arg2
> 1) /* Note, we rely on arg2 being unsigned here */
942 if (issecure(SECURE_KEEP_CAPS_LOCKED
))
945 new->securebits
|= issecure_mask(SECURE_KEEP_CAPS
);
947 new->securebits
&= ~issecure_mask(SECURE_KEEP_CAPS
);
951 /* No functionality available - continue with default */
956 /* Functionality provided */
958 return commit_creds(new);
967 * cap_syslog - Determine whether syslog function is permitted
968 * @type: Function requested
970 * Determine whether the current process is permitted to use a particular
971 * syslog function, returning 0 if permission is granted, -ve if not.
973 int cap_syslog(int type
)
975 if ((type
!= 3 && type
!= 10) && !capable(CAP_SYS_ADMIN
))
981 * cap_vm_enough_memory - Determine whether a new virtual mapping is permitted
982 * @mm: The VM space in which the new mapping is to be made
983 * @pages: The size of the mapping
985 * Determine whether the allocation of a new virtual mapping by the current
986 * task is permitted, returning 0 if permission is granted, -ve if not.
988 int cap_vm_enough_memory(struct mm_struct
*mm
, long pages
)
990 int cap_sys_admin
= 0;
992 if (cap_capable(current
, current_cred(), CAP_SYS_ADMIN
,
993 SECURITY_CAP_NOAUDIT
) == 0)
995 return __vm_enough_memory(mm
, pages
, cap_sys_admin
);
999 * cap_file_mmap - check if able to map given addr
1004 * @addr: address attempting to be mapped
1005 * @addr_only: unused
1007 * If the process is attempting to map memory below mmap_min_addr they need
1008 * CAP_SYS_RAWIO. The other parameters to this function are unused by the
1009 * capability security module. Returns 0 if this mapping should be allowed
1012 int cap_file_mmap(struct file
*file
, unsigned long reqprot
,
1013 unsigned long prot
, unsigned long flags
,
1014 unsigned long addr
, unsigned long addr_only
)
1018 if (addr
< dac_mmap_min_addr
) {
1019 ret
= cap_capable(current
, current_cred(), CAP_SYS_RAWIO
,
1020 SECURITY_CAP_AUDIT
);
1021 /* set PF_SUPERPRIV if it turns out we allow the low mmap */
1023 current
->flags
|= PF_SUPERPRIV
;