// SPDX-License-Identifier: GPL-2.0-or-later1/* Common capabilities, needed by capability.o.2*/34#include <linux/capability.h>5#include <linux/audit.h>6#include <linux/init.h>7#include <linux/kernel.h>8#include <linux/lsm_hooks.h>9#include <linux/file.h>10#include <linux/mm.h>11#include <linux/mman.h>12#include <linux/pagemap.h>13#include <linux/swap.h>14#include <linux/skbuff.h>15#include <linux/netlink.h>16#include <linux/ptrace.h>17#include <linux/xattr.h>18#include <linux/hugetlb.h>19#include <linux/mount.h>20#include <linux/sched.h>21#include <linux/prctl.h>22#include <linux/securebits.h>23#include <linux/user_namespace.h>24#include <linux/binfmts.h>25#include <linux/personality.h>26#include <linux/mnt_idmapping.h>27#include <uapi/linux/lsm.h>2829#define CREATE_TRACE_POINTS30#include <trace/events/capability.h>3132/*33* If a non-root user executes a setuid-root binary in34* !secure(SECURE_NOROOT) mode, then we raise capabilities.35* However if fE is also set, then the intent is for only36* the file capabilities to be applied, and the setuid-root37* bit is left on either to change the uid (plausible) or38* to get full privilege on a kernel without file capabilities39* support. So in that case we do not raise capabilities.40*41* Warn if that happens, once per boot.42*/43static void warn_setuid_and_fcaps_mixed(const char *fname)44{45static int warned;46if (!warned) {47printk(KERN_INFO "warning: `%s' has both setuid-root and"48" effective capabilities. Therefore not raising all"49" capabilities.\n", fname);50warned = 1;51}52}5354/**55* cap_capable_helper - Determine whether a task has a particular effective56* capability.57* @cred: The credentials to use58* @target_ns: The user namespace of the resource being accessed59* @cred_ns: The user namespace of the credentials60* @cap: The capability to check for61*62* Determine whether the nominated task has the specified capability amongst63* its effective set, returning 0 if it does, -ve if it does not.64*65* See cap_capable for more details.66*/67static inline int cap_capable_helper(const struct cred *cred,68struct user_namespace *target_ns,69const struct user_namespace *cred_ns,70int cap)71{72struct user_namespace *ns = target_ns;7374/* See if cred has the capability in the target user namespace75* by examining the target user namespace and all of the target76* user namespace's parents.77*/78for (;;) {79/* Do we have the necessary capabilities? */80if (likely(ns == cred_ns))81return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;8283/*84* If we're already at a lower level than we're looking for,85* we're done searching.86*/87if (ns->level <= cred_ns->level)88return -EPERM;8990/*91* The owner of the user namespace in the parent of the92* user namespace has all caps.93*/94if ((ns->parent == cred_ns) && uid_eq(ns->owner, cred->euid))95return 0;9697/*98* If you have a capability in a parent user ns, then you have99* it over all children user namespaces as well.100*/101ns = ns->parent;102}103104/* We never get here */105}106107/**108* cap_capable - Determine whether a task has a particular effective capability109* @cred: The credentials to use110* @target_ns: The user namespace of the resource being accessed111* @cap: The capability to check for112* @opts: Bitmask of options defined in include/linux/security.h (unused)113*114* Determine whether the nominated task has the specified capability amongst115* its effective set, returning 0 if it does, -ve if it does not.116*117* NOTE WELL: cap_capable() has reverse semantics to the capable() call118* and friends. That is cap_capable() returns an int 0 when a task has119* a capability, while the kernel's capable(), has_ns_capability(),120* has_ns_capability_noaudit(), and has_capability_noaudit() return a121* bool true (1) for this case.122*/123int cap_capable(const struct cred *cred, struct user_namespace *target_ns,124int cap, unsigned int opts)125{126const struct user_namespace *cred_ns = cred->user_ns;127int ret = cap_capable_helper(cred, target_ns, cred_ns, cap);128129trace_cap_capable(cred, target_ns, cred_ns, cap, ret);130return ret;131}132133/**134* cap_settime - Determine whether the current process may set the system clock135* @ts: The time to set136* @tz: The timezone to set137*138* Determine whether the current process may set the system clock and timezone139* information, returning 0 if permission granted, -ve if denied.140*/141int cap_settime(const struct timespec64 *ts, const struct timezone *tz)142{143if (!capable(CAP_SYS_TIME))144return -EPERM;145return 0;146}147148/**149* cap_ptrace_access_check - Determine whether the current process may access150* another151* @child: The process to be accessed152* @mode: The mode of attachment.153*154* If we are in the same or an ancestor user_ns and have all the target155* task's capabilities, then ptrace access is allowed.156* If we have the ptrace capability to the target user_ns, then ptrace157* access is allowed.158* Else denied.159*160* Determine whether a process may access another, returning 0 if permission161* granted, -ve if denied.162*/163int cap_ptrace_access_check(struct task_struct *child, unsigned int mode)164{165int ret = 0;166const struct cred *cred, *child_cred;167const kernel_cap_t *caller_caps;168169rcu_read_lock();170cred = current_cred();171child_cred = __task_cred(child);172if (mode & PTRACE_MODE_FSCREDS)173caller_caps = &cred->cap_effective;174else175caller_caps = &cred->cap_permitted;176if (cred->user_ns == child_cred->user_ns &&177cap_issubset(child_cred->cap_permitted, *caller_caps))178goto out;179if (ns_capable(child_cred->user_ns, CAP_SYS_PTRACE))180goto out;181ret = -EPERM;182out:183rcu_read_unlock();184return ret;185}186187/**188* cap_ptrace_traceme - Determine whether another process may trace the current189* @parent: The task proposed to be the tracer190*191* If parent is in the same or an ancestor user_ns and has all current's192* capabilities, then ptrace access is allowed.193* If parent has the ptrace capability to current's user_ns, then ptrace194* access is allowed.195* Else denied.196*197* Determine whether the nominated task is permitted to trace the current198* process, returning 0 if permission is granted, -ve if denied.199*/200int cap_ptrace_traceme(struct task_struct *parent)201{202int ret = 0;203const struct cred *cred, *child_cred;204205rcu_read_lock();206cred = __task_cred(parent);207child_cred = current_cred();208if (cred->user_ns == child_cred->user_ns &&209cap_issubset(child_cred->cap_permitted, cred->cap_permitted))210goto out;211if (has_ns_capability(parent, child_cred->user_ns, CAP_SYS_PTRACE))212goto out;213ret = -EPERM;214out:215rcu_read_unlock();216return ret;217}218219/**220* cap_capget - Retrieve a task's capability sets221* @target: The task from which to retrieve the capability sets222* @effective: The place to record the effective set223* @inheritable: The place to record the inheritable set224* @permitted: The place to record the permitted set225*226* This function retrieves the capabilities of the nominated task and returns227* them to the caller.228*/229int cap_capget(const struct task_struct *target, kernel_cap_t *effective,230kernel_cap_t *inheritable, kernel_cap_t *permitted)231{232const struct cred *cred;233234/* Derived from kernel/capability.c:sys_capget. */235rcu_read_lock();236cred = __task_cred(target);237*effective = cred->cap_effective;238*inheritable = cred->cap_inheritable;239*permitted = cred->cap_permitted;240rcu_read_unlock();241return 0;242}243244/*245* Determine whether the inheritable capabilities are limited to the old246* permitted set. Returns 1 if they are limited, 0 if they are not.247*/248static inline int cap_inh_is_capped(void)249{250/* they are so limited unless the current task has the CAP_SETPCAP251* capability252*/253if (cap_capable(current_cred(), current_cred()->user_ns,254CAP_SETPCAP, CAP_OPT_NONE) == 0)255return 0;256return 1;257}258259/**260* cap_capset - Validate and apply proposed changes to current's capabilities261* @new: The proposed new credentials; alterations should be made here262* @old: The current task's current credentials263* @effective: A pointer to the proposed new effective capabilities set264* @inheritable: A pointer to the proposed new inheritable capabilities set265* @permitted: A pointer to the proposed new permitted capabilities set266*267* This function validates and applies a proposed mass change to the current268* process's capability sets. The changes are made to the proposed new269* credentials, and assuming no error, will be committed by the caller of LSM.270*/271int cap_capset(struct cred *new,272const struct cred *old,273const kernel_cap_t *effective,274const kernel_cap_t *inheritable,275const kernel_cap_t *permitted)276{277if (cap_inh_is_capped() &&278!cap_issubset(*inheritable,279cap_combine(old->cap_inheritable,280old->cap_permitted)))281/* incapable of using this inheritable set */282return -EPERM;283284if (!cap_issubset(*inheritable,285cap_combine(old->cap_inheritable,286old->cap_bset)))287/* no new pI capabilities outside bounding set */288return -EPERM;289290/* verify restrictions on target's new Permitted set */291if (!cap_issubset(*permitted, old->cap_permitted))292return -EPERM;293294/* verify the _new_Effective_ is a subset of the _new_Permitted_ */295if (!cap_issubset(*effective, *permitted))296return -EPERM;297298new->cap_effective = *effective;299new->cap_inheritable = *inheritable;300new->cap_permitted = *permitted;301302/*303* Mask off ambient bits that are no longer both permitted and304* inheritable.305*/306new->cap_ambient = cap_intersect(new->cap_ambient,307cap_intersect(*permitted,308*inheritable));309if (WARN_ON(!cap_ambient_invariant_ok(new)))310return -EINVAL;311return 0;312}313314/**315* cap_inode_need_killpriv - Determine if inode change affects privileges316* @dentry: The inode/dentry in being changed with change marked ATTR_KILL_PRIV317*318* Determine if an inode having a change applied that's marked ATTR_KILL_PRIV319* affects the security markings on that inode, and if it is, should320* inode_killpriv() be invoked or the change rejected.321*322* Return: 1 if security.capability has a value, meaning inode_killpriv()323* is required, 0 otherwise, meaning inode_killpriv() is not required.324*/325int cap_inode_need_killpriv(struct dentry *dentry)326{327struct inode *inode = d_backing_inode(dentry);328int error;329330error = __vfs_getxattr(dentry, inode, XATTR_NAME_CAPS, NULL, 0);331return error > 0;332}333334/**335* cap_inode_killpriv - Erase the security markings on an inode336*337* @idmap: idmap of the mount the inode was found from338* @dentry: The inode/dentry to alter339*340* Erase the privilege-enhancing security markings on an inode.341*342* If the inode has been found through an idmapped mount the idmap of343* the vfsmount must be passed through @idmap. This function will then344* take care to map the inode according to @idmap before checking345* permissions. On non-idmapped mounts or if permission checking is to be346* performed on the raw inode simply pass @nop_mnt_idmap.347*348* Return: 0 if successful, -ve on error.349*/350int cap_inode_killpriv(struct mnt_idmap *idmap, struct dentry *dentry)351{352int error;353354error = __vfs_removexattr(idmap, dentry, XATTR_NAME_CAPS);355if (error == -EOPNOTSUPP)356error = 0;357return error;358}359360static bool rootid_owns_currentns(vfsuid_t rootvfsuid)361{362struct user_namespace *ns;363kuid_t kroot;364365if (!vfsuid_valid(rootvfsuid))366return false;367368kroot = vfsuid_into_kuid(rootvfsuid);369for (ns = current_user_ns();; ns = ns->parent) {370if (from_kuid(ns, kroot) == 0)371return true;372if (ns == &init_user_ns)373break;374}375376return false;377}378379static __u32 sansflags(__u32 m)380{381return m & ~VFS_CAP_FLAGS_EFFECTIVE;382}383384static bool is_v2header(int size, const struct vfs_cap_data *cap)385{386if (size != XATTR_CAPS_SZ_2)387return false;388return sansflags(le32_to_cpu(cap->magic_etc)) == VFS_CAP_REVISION_2;389}390391static bool is_v3header(int size, const struct vfs_cap_data *cap)392{393if (size != XATTR_CAPS_SZ_3)394return false;395return sansflags(le32_to_cpu(cap->magic_etc)) == VFS_CAP_REVISION_3;396}397398/*399* getsecurity: We are called for security.* before any attempt to read the400* xattr from the inode itself.401*402* This gives us a chance to read the on-disk value and convert it. If we403* return -EOPNOTSUPP, then vfs_getxattr() will call the i_op handler.404*405* Note we are not called by vfs_getxattr_alloc(), but that is only called406* by the integrity subsystem, which really wants the unconverted values -407* so that's good.408*/409int cap_inode_getsecurity(struct mnt_idmap *idmap,410struct inode *inode, const char *name, void **buffer,411bool alloc)412{413int size;414kuid_t kroot;415vfsuid_t vfsroot;416u32 nsmagic, magic;417uid_t root, mappedroot;418char *tmpbuf = NULL;419struct vfs_cap_data *cap;420struct vfs_ns_cap_data *nscap = NULL;421struct dentry *dentry;422struct user_namespace *fs_ns;423424if (strcmp(name, "capability") != 0)425return -EOPNOTSUPP;426427dentry = d_find_any_alias(inode);428if (!dentry)429return -EINVAL;430size = vfs_getxattr_alloc(idmap, dentry, XATTR_NAME_CAPS, &tmpbuf,431sizeof(struct vfs_ns_cap_data), GFP_NOFS);432dput(dentry);433/* gcc11 complains if we don't check for !tmpbuf */434if (size < 0 || !tmpbuf)435goto out_free;436437fs_ns = inode->i_sb->s_user_ns;438cap = (struct vfs_cap_data *) tmpbuf;439if (is_v2header(size, cap)) {440root = 0;441} else if (is_v3header(size, cap)) {442nscap = (struct vfs_ns_cap_data *) tmpbuf;443root = le32_to_cpu(nscap->rootid);444} else {445size = -EINVAL;446goto out_free;447}448449kroot = make_kuid(fs_ns, root);450451/* If this is an idmapped mount shift the kuid. */452vfsroot = make_vfsuid(idmap, fs_ns, kroot);453454/* If the root kuid maps to a valid uid in current ns, then return455* this as a nscap. */456mappedroot = from_kuid(current_user_ns(), vfsuid_into_kuid(vfsroot));457if (mappedroot != (uid_t)-1 && mappedroot != (uid_t)0) {458size = sizeof(struct vfs_ns_cap_data);459if (alloc) {460if (!nscap) {461/* v2 -> v3 conversion */462nscap = kzalloc(size, GFP_ATOMIC);463if (!nscap) {464size = -ENOMEM;465goto out_free;466}467nsmagic = VFS_CAP_REVISION_3;468magic = le32_to_cpu(cap->magic_etc);469if (magic & VFS_CAP_FLAGS_EFFECTIVE)470nsmagic |= VFS_CAP_FLAGS_EFFECTIVE;471memcpy(&nscap->data, &cap->data, sizeof(__le32) * 2 * VFS_CAP_U32);472nscap->magic_etc = cpu_to_le32(nsmagic);473} else {474/* use allocated v3 buffer */475tmpbuf = NULL;476}477nscap->rootid = cpu_to_le32(mappedroot);478*buffer = nscap;479}480goto out_free;481}482483if (!rootid_owns_currentns(vfsroot)) {484size = -EOVERFLOW;485goto out_free;486}487488/* This comes from a parent namespace. Return as a v2 capability */489size = sizeof(struct vfs_cap_data);490if (alloc) {491if (nscap) {492/* v3 -> v2 conversion */493cap = kzalloc(size, GFP_ATOMIC);494if (!cap) {495size = -ENOMEM;496goto out_free;497}498magic = VFS_CAP_REVISION_2;499nsmagic = le32_to_cpu(nscap->magic_etc);500if (nsmagic & VFS_CAP_FLAGS_EFFECTIVE)501magic |= VFS_CAP_FLAGS_EFFECTIVE;502memcpy(&cap->data, &nscap->data, sizeof(__le32) * 2 * VFS_CAP_U32);503cap->magic_etc = cpu_to_le32(magic);504} else {505/* use unconverted v2 */506tmpbuf = NULL;507}508*buffer = cap;509}510out_free:511kfree(tmpbuf);512return size;513}514515/**516* rootid_from_xattr - translate root uid of vfs caps517*518* @value: vfs caps value which may be modified by this function519* @size: size of @ivalue520* @task_ns: user namespace of the caller521*/522static vfsuid_t rootid_from_xattr(const void *value, size_t size,523struct user_namespace *task_ns)524{525const struct vfs_ns_cap_data *nscap = value;526uid_t rootid = 0;527528if (size == XATTR_CAPS_SZ_3)529rootid = le32_to_cpu(nscap->rootid);530531return VFSUIDT_INIT(make_kuid(task_ns, rootid));532}533534static bool validheader(size_t size, const struct vfs_cap_data *cap)535{536return is_v2header(size, cap) || is_v3header(size, cap);537}538539/**540* cap_convert_nscap - check vfs caps541*542* @idmap: idmap of the mount the inode was found from543* @dentry: used to retrieve inode to check permissions on544* @ivalue: vfs caps value which may be modified by this function545* @size: size of @ivalue546*547* User requested a write of security.capability. If needed, update the548* xattr to change from v2 to v3, or to fixup the v3 rootid.549*550* If the inode has been found through an idmapped mount the idmap of551* the vfsmount must be passed through @idmap. This function will then552* take care to map the inode according to @idmap before checking553* permissions. On non-idmapped mounts or if permission checking is to be554* performed on the raw inode simply pass @nop_mnt_idmap.555*556* Return: On success, return the new size; on error, return < 0.557*/558int cap_convert_nscap(struct mnt_idmap *idmap, struct dentry *dentry,559const void **ivalue, size_t size)560{561struct vfs_ns_cap_data *nscap;562uid_t nsrootid;563const struct vfs_cap_data *cap = *ivalue;564__u32 magic, nsmagic;565struct inode *inode = d_backing_inode(dentry);566struct user_namespace *task_ns = current_user_ns(),567*fs_ns = inode->i_sb->s_user_ns;568kuid_t rootid;569vfsuid_t vfsrootid;570size_t newsize;571572if (!*ivalue)573return -EINVAL;574if (!validheader(size, cap))575return -EINVAL;576if (!capable_wrt_inode_uidgid(idmap, inode, CAP_SETFCAP))577return -EPERM;578if (size == XATTR_CAPS_SZ_2 && (idmap == &nop_mnt_idmap))579if (ns_capable(inode->i_sb->s_user_ns, CAP_SETFCAP))580/* user is privileged, just write the v2 */581return size;582583vfsrootid = rootid_from_xattr(*ivalue, size, task_ns);584if (!vfsuid_valid(vfsrootid))585return -EINVAL;586587rootid = from_vfsuid(idmap, fs_ns, vfsrootid);588if (!uid_valid(rootid))589return -EINVAL;590591nsrootid = from_kuid(fs_ns, rootid);592if (nsrootid == -1)593return -EINVAL;594595newsize = sizeof(struct vfs_ns_cap_data);596nscap = kmalloc(newsize, GFP_ATOMIC);597if (!nscap)598return -ENOMEM;599nscap->rootid = cpu_to_le32(nsrootid);600nsmagic = VFS_CAP_REVISION_3;601magic = le32_to_cpu(cap->magic_etc);602if (magic & VFS_CAP_FLAGS_EFFECTIVE)603nsmagic |= VFS_CAP_FLAGS_EFFECTIVE;604nscap->magic_etc = cpu_to_le32(nsmagic);605memcpy(&nscap->data, &cap->data, sizeof(__le32) * 2 * VFS_CAP_U32);606607*ivalue = nscap;608return newsize;609}610611/*612* Calculate the new process capability sets from the capability sets attached613* to a file.614*/615static inline int bprm_caps_from_vfs_caps(struct cpu_vfs_cap_data *caps,616struct linux_binprm *bprm,617bool *effective,618bool *has_fcap)619{620struct cred *new = bprm->cred;621int ret = 0;622623if (caps->magic_etc & VFS_CAP_FLAGS_EFFECTIVE)624*effective = true;625626if (caps->magic_etc & VFS_CAP_REVISION_MASK)627*has_fcap = true;628629/*630* pP' = (X & fP) | (pI & fI)631* The addition of pA' is handled later.632*/633new->cap_permitted.val =634(new->cap_bset.val & caps->permitted.val) |635(new->cap_inheritable.val & caps->inheritable.val);636637if (caps->permitted.val & ~new->cap_permitted.val)638/* insufficient to execute correctly */639ret = -EPERM;640641/*642* For legacy apps, with no internal support for recognizing they643* do not have enough capabilities, we return an error if they are644* missing some "forced" (aka file-permitted) capabilities.645*/646return *effective ? ret : 0;647}648649/**650* get_vfs_caps_from_disk - retrieve vfs caps from disk651*652* @idmap: idmap of the mount the inode was found from653* @dentry: dentry from which @inode is retrieved654* @cpu_caps: vfs capabilities655*656* Extract the on-exec-apply capability sets for an executable file.657*658* If the inode has been found through an idmapped mount the idmap of659* the vfsmount must be passed through @idmap. This function will then660* take care to map the inode according to @idmap before checking661* permissions. On non-idmapped mounts or if permission checking is to be662* performed on the raw inode simply pass @nop_mnt_idmap.663*/664int get_vfs_caps_from_disk(struct mnt_idmap *idmap,665const struct dentry *dentry,666struct cpu_vfs_cap_data *cpu_caps)667{668struct inode *inode = d_backing_inode(dentry);669__u32 magic_etc;670int size;671struct vfs_ns_cap_data data, *nscaps = &data;672struct vfs_cap_data *caps = (struct vfs_cap_data *) &data;673kuid_t rootkuid;674vfsuid_t rootvfsuid;675struct user_namespace *fs_ns;676677memset(cpu_caps, 0, sizeof(struct cpu_vfs_cap_data));678679if (!inode)680return -ENODATA;681682fs_ns = inode->i_sb->s_user_ns;683size = __vfs_getxattr((struct dentry *)dentry, inode,684XATTR_NAME_CAPS, &data, XATTR_CAPS_SZ);685if (size == -ENODATA || size == -EOPNOTSUPP)686/* no data, that's ok */687return -ENODATA;688689if (size < 0)690return size;691692if (size < sizeof(magic_etc))693return -EINVAL;694695cpu_caps->magic_etc = magic_etc = le32_to_cpu(caps->magic_etc);696697rootkuid = make_kuid(fs_ns, 0);698switch (magic_etc & VFS_CAP_REVISION_MASK) {699case VFS_CAP_REVISION_1:700if (size != XATTR_CAPS_SZ_1)701return -EINVAL;702break;703case VFS_CAP_REVISION_2:704if (size != XATTR_CAPS_SZ_2)705return -EINVAL;706break;707case VFS_CAP_REVISION_3:708if (size != XATTR_CAPS_SZ_3)709return -EINVAL;710rootkuid = make_kuid(fs_ns, le32_to_cpu(nscaps->rootid));711break;712713default:714return -EINVAL;715}716717rootvfsuid = make_vfsuid(idmap, fs_ns, rootkuid);718if (!vfsuid_valid(rootvfsuid))719return -ENODATA;720721/* Limit the caps to the mounter of the filesystem722* or the more limited uid specified in the xattr.723*/724if (!rootid_owns_currentns(rootvfsuid))725return -ENODATA;726727cpu_caps->permitted.val = le32_to_cpu(caps->data[0].permitted);728cpu_caps->inheritable.val = le32_to_cpu(caps->data[0].inheritable);729730/*731* Rev1 had just a single 32-bit word, later expanded732* to a second one for the high bits733*/734if ((magic_etc & VFS_CAP_REVISION_MASK) != VFS_CAP_REVISION_1) {735cpu_caps->permitted.val += (u64)le32_to_cpu(caps->data[1].permitted) << 32;736cpu_caps->inheritable.val += (u64)le32_to_cpu(caps->data[1].inheritable) << 32;737}738739cpu_caps->permitted.val &= CAP_VALID_MASK;740cpu_caps->inheritable.val &= CAP_VALID_MASK;741742cpu_caps->rootid = vfsuid_into_kuid(rootvfsuid);743744return 0;745}746747/*748* Attempt to get the on-exec apply capability sets for an executable file from749* its xattrs and, if present, apply them to the proposed credentials being750* constructed by execve().751*/752static int get_file_caps(struct linux_binprm *bprm, const struct file *file,753bool *effective, bool *has_fcap)754{755int rc = 0;756struct cpu_vfs_cap_data vcaps;757758cap_clear(bprm->cred->cap_permitted);759760if (!file_caps_enabled)761return 0;762763if (!mnt_may_suid(file->f_path.mnt))764return 0;765766/*767* This check is redundant with mnt_may_suid() but is kept to make768* explicit that capability bits are limited to s_user_ns and its769* descendants.770*/771if (!current_in_userns(file->f_path.mnt->mnt_sb->s_user_ns))772return 0;773774rc = get_vfs_caps_from_disk(file_mnt_idmap(file),775file->f_path.dentry, &vcaps);776if (rc < 0) {777if (rc == -EINVAL)778printk(KERN_NOTICE "Invalid argument reading file caps for %s\n",779bprm->filename);780else if (rc == -ENODATA)781rc = 0;782goto out;783}784785rc = bprm_caps_from_vfs_caps(&vcaps, bprm, effective, has_fcap);786787out:788if (rc)789cap_clear(bprm->cred->cap_permitted);790791return rc;792}793794static inline bool root_privileged(void) { return !issecure(SECURE_NOROOT); }795796static inline bool __is_real(kuid_t uid, struct cred *cred)797{ return uid_eq(cred->uid, uid); }798799static inline bool __is_eff(kuid_t uid, struct cred *cred)800{ return uid_eq(cred->euid, uid); }801802static inline bool __is_suid(kuid_t uid, struct cred *cred)803{ return !__is_real(uid, cred) && __is_eff(uid, cred); }804805/*806* handle_privileged_root - Handle case of privileged root807* @bprm: The execution parameters, including the proposed creds808* @has_fcap: Are any file capabilities set?809* @effective: Do we have effective root privilege?810* @root_uid: This namespace' root UID WRT initial USER namespace811*812* Handle the case where root is privileged and hasn't been neutered by813* SECURE_NOROOT. If file capabilities are set, they won't be combined with814* set UID root and nothing is changed. If we are root, cap_permitted is815* updated. If we have become set UID root, the effective bit is set.816*/817static void handle_privileged_root(struct linux_binprm *bprm, bool has_fcap,818bool *effective, kuid_t root_uid)819{820const struct cred *old = current_cred();821struct cred *new = bprm->cred;822823if (!root_privileged())824return;825/*826* If the legacy file capability is set, then don't set privs827* for a setuid root binary run by a non-root user. Do set it828* for a root user just to cause least surprise to an admin.829*/830if (has_fcap && __is_suid(root_uid, new)) {831warn_setuid_and_fcaps_mixed(bprm->filename);832return;833}834/*835* To support inheritance of root-permissions and suid-root836* executables under compatibility mode, we override the837* capability sets for the file.838*/839if (__is_eff(root_uid, new) || __is_real(root_uid, new)) {840/* pP' = (cap_bset & ~0) | (pI & ~0) */841new->cap_permitted = cap_combine(old->cap_bset,842old->cap_inheritable);843}844/*845* If only the real uid is 0, we do not set the effective bit.846*/847if (__is_eff(root_uid, new))848*effective = true;849}850851#define __cap_gained(field, target, source) \852!cap_issubset(target->cap_##field, source->cap_##field)853#define __cap_grew(target, source, cred) \854!cap_issubset(cred->cap_##target, cred->cap_##source)855#define __cap_full(field, cred) \856cap_issubset(CAP_FULL_SET, cred->cap_##field)857858/*859* 1) Audit candidate if current->cap_effective is set860*861* We do not bother to audit if 3 things are true:862* 1) cap_effective has all caps863* 2) we became root *OR* are were already root864* 3) root is supposed to have all caps (SECURE_NOROOT)865* Since this is just a normal root execing a process.866*867* Number 1 above might fail if you don't have a full bset, but I think868* that is interesting information to audit.869*870* A number of other conditions require logging:871* 2) something prevented setuid root getting all caps872* 3) non-setuid root gets fcaps873* 4) non-setuid root gets ambient874*/875static inline bool nonroot_raised_pE(struct cred *new, const struct cred *old,876kuid_t root, bool has_fcap)877{878bool ret = false;879880if ((__cap_grew(effective, ambient, new) &&881!(__cap_full(effective, new) &&882(__is_eff(root, new) || __is_real(root, new)) &&883root_privileged())) ||884(root_privileged() &&885__is_suid(root, new) &&886!__cap_full(effective, new)) ||887(uid_eq(new->euid, old->euid) &&888((has_fcap &&889__cap_gained(permitted, new, old)) ||890__cap_gained(ambient, new, old))))891892ret = true;893894return ret;895}896897/**898* cap_bprm_creds_from_file - Set up the proposed credentials for execve().899* @bprm: The execution parameters, including the proposed creds900* @file: The file to pull the credentials from901*902* Set up the proposed credentials for a new execution context being903* constructed by execve(). The proposed creds in @bprm->cred is altered,904* which won't take effect immediately.905*906* Return: 0 if successful, -ve on error.907*/908int cap_bprm_creds_from_file(struct linux_binprm *bprm, const struct file *file)909{910/* Process setpcap binaries and capabilities for uid 0 */911const struct cred *old = current_cred();912struct cred *new = bprm->cred;913bool effective = false, has_fcap = false, id_changed;914int ret;915kuid_t root_uid;916917if (WARN_ON(!cap_ambient_invariant_ok(old)))918return -EPERM;919920ret = get_file_caps(bprm, file, &effective, &has_fcap);921if (ret < 0)922return ret;923924root_uid = make_kuid(new->user_ns, 0);925926handle_privileged_root(bprm, has_fcap, &effective, root_uid);927928/* if we have fs caps, clear dangerous personality flags */929if (__cap_gained(permitted, new, old))930bprm->per_clear |= PER_CLEAR_ON_SETID;931932/* Don't let someone trace a set[ug]id/setpcap binary with the revised933* credentials unless they have the appropriate permit.934*935* In addition, if NO_NEW_PRIVS, then ensure we get no new privs.936*/937id_changed = !uid_eq(new->euid, old->euid) || !in_group_p(new->egid);938939if ((id_changed || __cap_gained(permitted, new, old)) &&940((bprm->unsafe & ~LSM_UNSAFE_PTRACE) ||941!ptracer_capable(current, new->user_ns))) {942/* downgrade; they get no more than they had, and maybe less */943if (!ns_capable(new->user_ns, CAP_SETUID) ||944(bprm->unsafe & LSM_UNSAFE_NO_NEW_PRIVS)) {945new->euid = new->uid;946new->egid = new->gid;947}948new->cap_permitted = cap_intersect(new->cap_permitted,949old->cap_permitted);950}951952new->suid = new->fsuid = new->euid;953new->sgid = new->fsgid = new->egid;954955/* File caps or setid cancels ambient. */956if (has_fcap || id_changed)957cap_clear(new->cap_ambient);958959/*960* Now that we've computed pA', update pP' to give:961* pP' = (X & fP) | (pI & fI) | pA'962*/963new->cap_permitted = cap_combine(new->cap_permitted, new->cap_ambient);964965/*966* Set pE' = (fE ? pP' : pA'). Because pA' is zero if fE is set,967* this is the same as pE' = (fE ? pP' : 0) | pA'.968*/969if (effective)970new->cap_effective = new->cap_permitted;971else972new->cap_effective = new->cap_ambient;973974if (WARN_ON(!cap_ambient_invariant_ok(new)))975return -EPERM;976977if (nonroot_raised_pE(new, old, root_uid, has_fcap)) {978ret = audit_log_bprm_fcaps(bprm, new, old);979if (ret < 0)980return ret;981}982983new->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);984985if (WARN_ON(!cap_ambient_invariant_ok(new)))986return -EPERM;987988/* Check for privilege-elevated exec. */989if (id_changed ||990!uid_eq(new->euid, old->uid) ||991!gid_eq(new->egid, old->gid) ||992(!__is_real(root_uid, new) &&993(effective ||994__cap_grew(permitted, ambient, new))))995bprm->secureexec = 1;996997return 0;998}9991000/**1001* cap_inode_setxattr - Determine whether an xattr may be altered1002* @dentry: The inode/dentry being altered1003* @name: The name of the xattr to be changed1004* @value: The value that the xattr will be changed to1005* @size: The size of value1006* @flags: The replacement flag1007*1008* Determine whether an xattr may be altered or set on an inode, returning 0 if1009* permission is granted, -ve if denied.1010*1011* This is used to make sure security xattrs don't get updated or set by those1012* who aren't privileged to do so.1013*/1014int cap_inode_setxattr(struct dentry *dentry, const char *name,1015const void *value, size_t size, int flags)1016{1017struct user_namespace *user_ns = dentry->d_sb->s_user_ns;10181019/* Ignore non-security xattrs */1020if (strncmp(name, XATTR_SECURITY_PREFIX,1021XATTR_SECURITY_PREFIX_LEN) != 0)1022return 0;10231024/*1025* For XATTR_NAME_CAPS the check will be done in1026* cap_convert_nscap(), called by setxattr()1027*/1028if (strcmp(name, XATTR_NAME_CAPS) == 0)1029return 0;10301031if (!ns_capable(user_ns, CAP_SYS_ADMIN))1032return -EPERM;1033return 0;1034}10351036/**1037* cap_inode_removexattr - Determine whether an xattr may be removed1038*1039* @idmap: idmap of the mount the inode was found from1040* @dentry: The inode/dentry being altered1041* @name: The name of the xattr to be changed1042*1043* Determine whether an xattr may be removed from an inode, returning 0 if1044* permission is granted, -ve if denied.1045*1046* If the inode has been found through an idmapped mount the idmap of1047* the vfsmount must be passed through @idmap. This function will then1048* take care to map the inode according to @idmap before checking1049* permissions. On non-idmapped mounts or if permission checking is to be1050* performed on the raw inode simply pass @nop_mnt_idmap.1051*1052* This is used to make sure security xattrs don't get removed by those who1053* aren't privileged to remove them.1054*/1055int cap_inode_removexattr(struct mnt_idmap *idmap,1056struct dentry *dentry, const char *name)1057{1058struct user_namespace *user_ns = dentry->d_sb->s_user_ns;10591060/* Ignore non-security xattrs */1061if (strncmp(name, XATTR_SECURITY_PREFIX,1062XATTR_SECURITY_PREFIX_LEN) != 0)1063return 0;10641065if (strcmp(name, XATTR_NAME_CAPS) == 0) {1066/* security.capability gets namespaced */1067struct inode *inode = d_backing_inode(dentry);1068if (!inode)1069return -EINVAL;1070if (!capable_wrt_inode_uidgid(idmap, inode, CAP_SETFCAP))1071return -EPERM;1072return 0;1073}10741075if (!ns_capable(user_ns, CAP_SYS_ADMIN))1076return -EPERM;1077return 0;1078}10791080/*1081* cap_emulate_setxuid() fixes the effective / permitted capabilities of1082* a process after a call to setuid, setreuid, or setresuid.1083*1084* 1) When set*uiding _from_ one of {r,e,s}uid == 0 _to_ all of1085* {r,e,s}uid != 0, the permitted and effective capabilities are1086* cleared.1087*1088* 2) When set*uiding _from_ euid == 0 _to_ euid != 0, the effective1089* capabilities of the process are cleared.1090*1091* 3) When set*uiding _from_ euid != 0 _to_ euid == 0, the effective1092* capabilities are set to the permitted capabilities.1093*1094* fsuid is handled elsewhere. fsuid == 0 and {r,e,s}uid!= 0 should1095* never happen.1096*1097* -astor1098*1099* cevans - New behaviour, Oct '991100* A process may, via prctl(), elect to keep its capabilities when it1101* calls setuid() and switches away from uid==0. Both permitted and1102* effective sets will be retained.1103* Without this change, it was impossible for a daemon to drop only some1104* of its privilege. The call to setuid(!=0) would drop all privileges!1105* Keeping uid 0 is not an option because uid 0 owns too many vital1106* files..1107* Thanks to Olaf Kirch and Peter Benie for spotting this.1108*/1109static inline void cap_emulate_setxuid(struct cred *new, const struct cred *old)1110{1111kuid_t root_uid = make_kuid(old->user_ns, 0);11121113if ((uid_eq(old->uid, root_uid) ||1114uid_eq(old->euid, root_uid) ||1115uid_eq(old->suid, root_uid)) &&1116(!uid_eq(new->uid, root_uid) &&1117!uid_eq(new->euid, root_uid) &&1118!uid_eq(new->suid, root_uid))) {1119if (!issecure(SECURE_KEEP_CAPS)) {1120cap_clear(new->cap_permitted);1121cap_clear(new->cap_effective);1122}11231124/*1125* Pre-ambient programs expect setresuid to nonroot followed1126* by exec to drop capabilities. We should make sure that1127* this remains the case.1128*/1129cap_clear(new->cap_ambient);1130}1131if (uid_eq(old->euid, root_uid) && !uid_eq(new->euid, root_uid))1132cap_clear(new->cap_effective);1133if (!uid_eq(old->euid, root_uid) && uid_eq(new->euid, root_uid))1134new->cap_effective = new->cap_permitted;1135}11361137/**1138* cap_task_fix_setuid - Fix up the results of setuid() call1139* @new: The proposed credentials1140* @old: The current task's current credentials1141* @flags: Indications of what has changed1142*1143* Fix up the results of setuid() call before the credential changes are1144* actually applied.1145*1146* Return: 0 to grant the changes, -ve to deny them.1147*/1148int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags)1149{1150switch (flags) {1151case LSM_SETID_RE:1152case LSM_SETID_ID:1153case LSM_SETID_RES:1154/* juggle the capabilities to follow [RES]UID changes unless1155* otherwise suppressed */1156if (!issecure(SECURE_NO_SETUID_FIXUP))1157cap_emulate_setxuid(new, old);1158break;11591160case LSM_SETID_FS:1161/* juggle the capabilities to follow FSUID changes, unless1162* otherwise suppressed1163*1164* FIXME - is fsuser used for all CAP_FS_MASK capabilities?1165* if not, we might be a bit too harsh here.1166*/1167if (!issecure(SECURE_NO_SETUID_FIXUP)) {1168kuid_t root_uid = make_kuid(old->user_ns, 0);1169if (uid_eq(old->fsuid, root_uid) && !uid_eq(new->fsuid, root_uid))1170new->cap_effective =1171cap_drop_fs_set(new->cap_effective);11721173if (!uid_eq(old->fsuid, root_uid) && uid_eq(new->fsuid, root_uid))1174new->cap_effective =1175cap_raise_fs_set(new->cap_effective,1176new->cap_permitted);1177}1178break;11791180default:1181return -EINVAL;1182}11831184return 0;1185}11861187/*1188* Rationale: code calling task_setscheduler, task_setioprio, and1189* task_setnice, assumes that1190* . if capable(cap_sys_nice), then those actions should be allowed1191* . if not capable(cap_sys_nice), but acting on your own processes,1192* then those actions should be allowed1193* This is insufficient now since you can call code without suid, but1194* yet with increased caps.1195* So we check for increased caps on the target process.1196*/1197static int cap_safe_nice(struct task_struct *p)1198{1199int is_subset, ret = 0;12001201rcu_read_lock();1202is_subset = cap_issubset(__task_cred(p)->cap_permitted,1203current_cred()->cap_permitted);1204if (!is_subset && !ns_capable(__task_cred(p)->user_ns, CAP_SYS_NICE))1205ret = -EPERM;1206rcu_read_unlock();12071208return ret;1209}12101211/**1212* cap_task_setscheduler - Determine if scheduler policy change is permitted1213* @p: The task to affect1214*1215* Determine if the requested scheduler policy change is permitted for the1216* specified task.1217*1218* Return: 0 if permission is granted, -ve if denied.1219*/1220int cap_task_setscheduler(struct task_struct *p)1221{1222return cap_safe_nice(p);1223}12241225/**1226* cap_task_setioprio - Determine if I/O priority change is permitted1227* @p: The task to affect1228* @ioprio: The I/O priority to set1229*1230* Determine if the requested I/O priority change is permitted for the specified1231* task.1232*1233* Return: 0 if permission is granted, -ve if denied.1234*/1235int cap_task_setioprio(struct task_struct *p, int ioprio)1236{1237return cap_safe_nice(p);1238}12391240/**1241* cap_task_setnice - Determine if task priority change is permitted1242* @p: The task to affect1243* @nice: The nice value to set1244*1245* Determine if the requested task priority change is permitted for the1246* specified task.1247*1248* Return: 0 if permission is granted, -ve if denied.1249*/1250int cap_task_setnice(struct task_struct *p, int nice)1251{1252return cap_safe_nice(p);1253}12541255/*1256* Implement PR_CAPBSET_DROP. Attempt to remove the specified capability from1257* the current task's bounding set. Returns 0 on success, -ve on error.1258*/1259static int cap_prctl_drop(unsigned long cap)1260{1261struct cred *new;12621263if (!ns_capable(current_user_ns(), CAP_SETPCAP))1264return -EPERM;1265if (!cap_valid(cap))1266return -EINVAL;12671268new = prepare_creds();1269if (!new)1270return -ENOMEM;1271cap_lower(new->cap_bset, cap);1272return commit_creds(new);1273}12741275/**1276* cap_task_prctl - Implement process control functions for this security module1277* @option: The process control function requested1278* @arg2: The argument data for this function1279* @arg3: The argument data for this function1280* @arg4: The argument data for this function1281* @arg5: The argument data for this function1282*1283* Allow process control functions (sys_prctl()) to alter capabilities; may1284* also deny access to other functions not otherwise implemented here.1285*1286* Return: 0 or +ve on success, -ENOSYS if this function is not implemented1287* here, other -ve on error. If -ENOSYS is returned, sys_prctl() and other LSM1288* modules will consider performing the function.1289*/1290int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,1291unsigned long arg4, unsigned long arg5)1292{1293const struct cred *old = current_cred();1294struct cred *new;12951296switch (option) {1297case PR_CAPBSET_READ:1298if (!cap_valid(arg2))1299return -EINVAL;1300return !!cap_raised(old->cap_bset, arg2);13011302case PR_CAPBSET_DROP:1303return cap_prctl_drop(arg2);13041305/*1306* The next four prctl's remain to assist with transitioning a1307* system from legacy UID=0 based privilege (when filesystem1308* capabilities are not in use) to a system using filesystem1309* capabilities only - as the POSIX.1e draft intended.1310*1311* Note:1312*1313* PR_SET_SECUREBITS =1314* issecure_mask(SECURE_KEEP_CAPS_LOCKED)1315* | issecure_mask(SECURE_NOROOT)1316* | issecure_mask(SECURE_NOROOT_LOCKED)1317* | issecure_mask(SECURE_NO_SETUID_FIXUP)1318* | issecure_mask(SECURE_NO_SETUID_FIXUP_LOCKED)1319*1320* will ensure that the current process and all of its1321* children will be locked into a pure1322* capability-based-privilege environment.1323*/1324case PR_SET_SECUREBITS:1325if ((((old->securebits & SECURE_ALL_LOCKS) >> 1)1326& (old->securebits ^ arg2)) /*[1]*/1327|| ((old->securebits & SECURE_ALL_LOCKS & ~arg2)) /*[2]*/1328|| (arg2 & ~(SECURE_ALL_LOCKS | SECURE_ALL_BITS)) /*[3]*/1329/*1330* [1] no changing of bits that are locked1331* [2] no unlocking of locks1332* [3] no setting of unsupported bits1333*/1334)1335/* cannot change a locked bit */1336return -EPERM;13371338/*1339* Doing anything requires privilege (go read about the1340* "sendmail capabilities bug"), except for unprivileged bits.1341* Indeed, the SECURE_ALL_UNPRIVILEGED bits are not1342* restrictions enforced by the kernel but by user space on1343* itself.1344*/1345if (cap_capable(current_cred(), current_cred()->user_ns,1346CAP_SETPCAP, CAP_OPT_NONE) != 0) {1347const unsigned long unpriv_and_locks =1348SECURE_ALL_UNPRIVILEGED |1349SECURE_ALL_UNPRIVILEGED << 1;1350const unsigned long changed = old->securebits ^ arg2;13511352/* For legacy reason, denies non-change. */1353if (!changed)1354return -EPERM;13551356/* Denies privileged changes. */1357if (changed & ~unpriv_and_locks)1358return -EPERM;1359}13601361new = prepare_creds();1362if (!new)1363return -ENOMEM;1364new->securebits = arg2;1365return commit_creds(new);13661367case PR_GET_SECUREBITS:1368return old->securebits;13691370case PR_GET_KEEPCAPS:1371return !!issecure(SECURE_KEEP_CAPS);13721373case PR_SET_KEEPCAPS:1374if (arg2 > 1) /* Note, we rely on arg2 being unsigned here */1375return -EINVAL;1376if (issecure(SECURE_KEEP_CAPS_LOCKED))1377return -EPERM;13781379new = prepare_creds();1380if (!new)1381return -ENOMEM;1382if (arg2)1383new->securebits |= issecure_mask(SECURE_KEEP_CAPS);1384else1385new->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);1386return commit_creds(new);13871388case PR_CAP_AMBIENT:1389if (arg2 == PR_CAP_AMBIENT_CLEAR_ALL) {1390if (arg3 | arg4 | arg5)1391return -EINVAL;13921393new = prepare_creds();1394if (!new)1395return -ENOMEM;1396cap_clear(new->cap_ambient);1397return commit_creds(new);1398}13991400if (((!cap_valid(arg3)) | arg4 | arg5))1401return -EINVAL;14021403if (arg2 == PR_CAP_AMBIENT_IS_SET) {1404return !!cap_raised(current_cred()->cap_ambient, arg3);1405} else if (arg2 != PR_CAP_AMBIENT_RAISE &&1406arg2 != PR_CAP_AMBIENT_LOWER) {1407return -EINVAL;1408} else {1409if (arg2 == PR_CAP_AMBIENT_RAISE &&1410(!cap_raised(current_cred()->cap_permitted, arg3) ||1411!cap_raised(current_cred()->cap_inheritable,1412arg3) ||1413issecure(SECURE_NO_CAP_AMBIENT_RAISE)))1414return -EPERM;14151416new = prepare_creds();1417if (!new)1418return -ENOMEM;1419if (arg2 == PR_CAP_AMBIENT_RAISE)1420cap_raise(new->cap_ambient, arg3);1421else1422cap_lower(new->cap_ambient, arg3);1423return commit_creds(new);1424}14251426default:1427/* No functionality available - continue with default */1428return -ENOSYS;1429}1430}14311432/**1433* cap_vm_enough_memory - Determine whether a new virtual mapping is permitted1434* @mm: The VM space in which the new mapping is to be made1435* @pages: The size of the mapping1436*1437* Determine whether the allocation of a new virtual mapping by the current1438* task is permitted.1439*1440* Return: 0 if permission granted, negative error code if not.1441*/1442int cap_vm_enough_memory(struct mm_struct *mm, long pages)1443{1444return cap_capable(current_cred(), &init_user_ns, CAP_SYS_ADMIN,1445CAP_OPT_NOAUDIT);1446}14471448/**1449* cap_mmap_addr - check if able to map given addr1450* @addr: address attempting to be mapped1451*1452* If the process is attempting to map memory below dac_mmap_min_addr they need1453* CAP_SYS_RAWIO. The other parameters to this function are unused by the1454* capability security module.1455*1456* Return: 0 if this mapping should be allowed or -EPERM if not.1457*/1458int cap_mmap_addr(unsigned long addr)1459{1460int ret = 0;14611462if (addr < dac_mmap_min_addr) {1463ret = cap_capable(current_cred(), &init_user_ns, CAP_SYS_RAWIO,1464CAP_OPT_NONE);1465/* set PF_SUPERPRIV if it turns out we allow the low mmap */1466if (ret == 0)1467current->flags |= PF_SUPERPRIV;1468}1469return ret;1470}14711472#ifdef CONFIG_SECURITY14731474static const struct lsm_id capability_lsmid = {1475.name = "capability",1476.id = LSM_ID_CAPABILITY,1477};14781479static struct security_hook_list capability_hooks[] __ro_after_init = {1480LSM_HOOK_INIT(capable, cap_capable),1481LSM_HOOK_INIT(settime, cap_settime),1482LSM_HOOK_INIT(ptrace_access_check, cap_ptrace_access_check),1483LSM_HOOK_INIT(ptrace_traceme, cap_ptrace_traceme),1484LSM_HOOK_INIT(capget, cap_capget),1485LSM_HOOK_INIT(capset, cap_capset),1486LSM_HOOK_INIT(bprm_creds_from_file, cap_bprm_creds_from_file),1487LSM_HOOK_INIT(inode_need_killpriv, cap_inode_need_killpriv),1488LSM_HOOK_INIT(inode_killpriv, cap_inode_killpriv),1489LSM_HOOK_INIT(inode_getsecurity, cap_inode_getsecurity),1490LSM_HOOK_INIT(mmap_addr, cap_mmap_addr),1491LSM_HOOK_INIT(task_fix_setuid, cap_task_fix_setuid),1492LSM_HOOK_INIT(task_prctl, cap_task_prctl),1493LSM_HOOK_INIT(task_setscheduler, cap_task_setscheduler),1494LSM_HOOK_INIT(task_setioprio, cap_task_setioprio),1495LSM_HOOK_INIT(task_setnice, cap_task_setnice),1496LSM_HOOK_INIT(vm_enough_memory, cap_vm_enough_memory),1497};14981499static int __init capability_init(void)1500{1501security_add_hooks(capability_hooks, ARRAY_SIZE(capability_hooks),1502&capability_lsmid);1503return 0;1504}15051506DEFINE_LSM(capability) = {1507.name = "capability",1508.order = LSM_ORDER_FIRST,1509.init = capability_init,1510};15111512#endif /* CONFIG_SECURITY */151315141515