Merge 4.14.22 into android-4.14
[GitHub/moto-9609/android_kernel_motorola_exynos9610.git] / security / commoncap.c
1 /* Common capabilities, needed by capability.o.
2 *
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.
7 *
8 */
9
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/lsm_hooks.h>
16 #include <linux/file.h>
17 #include <linux/mm.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>
30 #include <linux/user_namespace.h>
31 #include <linux/binfmts.h>
32 #include <linux/personality.h>
33
34 #ifdef CONFIG_ANDROID_PARANOID_NETWORK
35 #include <linux/android_aid.h>
36 #endif
37
38 /*
39 * If a non-root user executes a setuid-root binary in
40 * !secure(SECURE_NOROOT) mode, then we raise capabilities.
41 * However if fE is also set, then the intent is for only
42 * the file capabilities to be applied, and the setuid-root
43 * bit is left on either to change the uid (plausible) or
44 * to get full privilege on a kernel without file capabilities
45 * support. So in that case we do not raise capabilities.
46 *
47 * Warn if that happens, once per boot.
48 */
49 static void warn_setuid_and_fcaps_mixed(const char *fname)
50 {
51 static int warned;
52 if (!warned) {
53 printk(KERN_INFO "warning: `%s' has both setuid-root and"
54 " effective capabilities. Therefore not raising all"
55 " capabilities.\n", fname);
56 warned = 1;
57 }
58 }
59
60 /**
61 * __cap_capable - Determine whether a task has a particular effective capability
62 * @cred: The credentials to use
63 * @ns: The user namespace in which we need the capability
64 * @cap: The capability to check for
65 * @audit: Whether to write an audit message or not
66 *
67 * Determine whether the nominated task has the specified capability amongst
68 * its effective set, returning 0 if it does, -ve if it does not.
69 *
70 * NOTE WELL: cap_has_capability() cannot be used like the kernel's capable()
71 * and has_capability() functions. That is, it has the reverse semantics:
72 * cap_has_capability() returns 0 when a task has a capability, but the
73 * kernel's capable() and has_capability() returns 1 for this case.
74 */
75 int __cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
76 int cap, int audit)
77 {
78 struct user_namespace *ns = targ_ns;
79
80 /* See if cred has the capability in the target user namespace
81 * by examining the target user namespace and all of the target
82 * user namespace's parents.
83 */
84 for (;;) {
85 /* Do we have the necessary capabilities? */
86 if (ns == cred->user_ns)
87 return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
88
89 /*
90 * If we're already at a lower level than we're looking for,
91 * we're done searching.
92 */
93 if (ns->level <= cred->user_ns->level)
94 return -EPERM;
95
96 /*
97 * The owner of the user namespace in the parent of the
98 * user namespace has all caps.
99 */
100 if ((ns->parent == cred->user_ns) && uid_eq(ns->owner, cred->euid))
101 return 0;
102
103 /*
104 * If you have a capability in a parent user ns, then you have
105 * it over all children user namespaces as well.
106 */
107 ns = ns->parent;
108 }
109
110 /* We never get here */
111 }
112
113 int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
114 int cap, int audit)
115 {
116 int ret = __cap_capable(cred, targ_ns, cap, audit);
117
118 #ifdef CONFIG_ANDROID_PARANOID_NETWORK
119 if (ret != 0 && cap == CAP_NET_RAW && in_egroup_p(AID_NET_RAW)) {
120 printk("Process %s granted CAP_NET_RAW from Android group net_raw.\n", current->comm);
121 printk(" Please update the .rc file to explictly set 'capabilities NET_RAW'\n");
122 printk(" Implicit grants are deprecated and will be removed in the future.\n");
123 return 0;
124 }
125 if (ret != 0 && cap == CAP_NET_ADMIN && in_egroup_p(AID_NET_ADMIN)) {
126 printk("Process %s granted CAP_NET_ADMIN from Android group net_admin.\n", current->comm);
127 printk(" Please update the .rc file to explictly set 'capabilities NET_ADMIN'\n");
128 printk(" Implicit grants are deprecated and will be removed in the future.\n");
129 return 0;
130 }
131 #endif
132 return ret;
133 }
134 /**
135 * cap_settime - Determine whether the current process may set the system clock
136 * @ts: The time to set
137 * @tz: The timezone to set
138 *
139 * Determine whether the current process may set the system clock and timezone
140 * information, returning 0 if permission granted, -ve if denied.
141 */
142 int cap_settime(const struct timespec64 *ts, const struct timezone *tz)
143 {
144 if (!capable(CAP_SYS_TIME))
145 return -EPERM;
146 return 0;
147 }
148
149 /**
150 * cap_ptrace_access_check - Determine whether the current process may access
151 * another
152 * @child: The process to be accessed
153 * @mode: The mode of attachment.
154 *
155 * If we are in the same or an ancestor user_ns and have all the target
156 * task's capabilities, then ptrace access is allowed.
157 * If we have the ptrace capability to the target user_ns, then ptrace
158 * access is allowed.
159 * Else denied.
160 *
161 * Determine whether a process may access another, returning 0 if permission
162 * granted, -ve if denied.
163 */
164 int cap_ptrace_access_check(struct task_struct *child, unsigned int mode)
165 {
166 int ret = 0;
167 const struct cred *cred, *child_cred;
168 const kernel_cap_t *caller_caps;
169
170 rcu_read_lock();
171 cred = current_cred();
172 child_cred = __task_cred(child);
173 if (mode & PTRACE_MODE_FSCREDS)
174 caller_caps = &cred->cap_effective;
175 else
176 caller_caps = &cred->cap_permitted;
177 if (cred->user_ns == child_cred->user_ns &&
178 cap_issubset(child_cred->cap_permitted, *caller_caps))
179 goto out;
180 if (ns_capable(child_cred->user_ns, CAP_SYS_PTRACE))
181 goto out;
182 ret = -EPERM;
183 out:
184 rcu_read_unlock();
185 return ret;
186 }
187
188 /**
189 * cap_ptrace_traceme - Determine whether another process may trace the current
190 * @parent: The task proposed to be the tracer
191 *
192 * If parent is in the same or an ancestor user_ns and has all current's
193 * capabilities, then ptrace access is allowed.
194 * If parent has the ptrace capability to current's user_ns, then ptrace
195 * access is allowed.
196 * Else denied.
197 *
198 * Determine whether the nominated task is permitted to trace the current
199 * process, returning 0 if permission is granted, -ve if denied.
200 */
201 int cap_ptrace_traceme(struct task_struct *parent)
202 {
203 int ret = 0;
204 const struct cred *cred, *child_cred;
205
206 rcu_read_lock();
207 cred = __task_cred(parent);
208 child_cred = current_cred();
209 if (cred->user_ns == child_cred->user_ns &&
210 cap_issubset(child_cred->cap_permitted, cred->cap_permitted))
211 goto out;
212 if (has_ns_capability(parent, child_cred->user_ns, CAP_SYS_PTRACE))
213 goto out;
214 ret = -EPERM;
215 out:
216 rcu_read_unlock();
217 return ret;
218 }
219
220 /**
221 * cap_capget - Retrieve a task's capability sets
222 * @target: The task from which to retrieve the capability sets
223 * @effective: The place to record the effective set
224 * @inheritable: The place to record the inheritable set
225 * @permitted: The place to record the permitted set
226 *
227 * This function retrieves the capabilities of the nominated task and returns
228 * them to the caller.
229 */
230 int cap_capget(struct task_struct *target, kernel_cap_t *effective,
231 kernel_cap_t *inheritable, kernel_cap_t *permitted)
232 {
233 const struct cred *cred;
234
235 /* Derived from kernel/capability.c:sys_capget. */
236 rcu_read_lock();
237 cred = __task_cred(target);
238 *effective = cred->cap_effective;
239 *inheritable = cred->cap_inheritable;
240 *permitted = cred->cap_permitted;
241 rcu_read_unlock();
242 return 0;
243 }
244
245 /*
246 * Determine whether the inheritable capabilities are limited to the old
247 * permitted set. Returns 1 if they are limited, 0 if they are not.
248 */
249 static inline int cap_inh_is_capped(void)
250 {
251
252 /* they are so limited unless the current task has the CAP_SETPCAP
253 * capability
254 */
255 if (cap_capable(current_cred(), current_cred()->user_ns,
256 CAP_SETPCAP, SECURITY_CAP_AUDIT) == 0)
257 return 0;
258 return 1;
259 }
260
261 /**
262 * cap_capset - Validate and apply proposed changes to current's capabilities
263 * @new: The proposed new credentials; alterations should be made here
264 * @old: The current task's current credentials
265 * @effective: A pointer to the proposed new effective capabilities set
266 * @inheritable: A pointer to the proposed new inheritable capabilities set
267 * @permitted: A pointer to the proposed new permitted capabilities set
268 *
269 * This function validates and applies a proposed mass change to the current
270 * process's capability sets. The changes are made to the proposed new
271 * credentials, and assuming no error, will be committed by the caller of LSM.
272 */
273 int cap_capset(struct cred *new,
274 const struct cred *old,
275 const kernel_cap_t *effective,
276 const kernel_cap_t *inheritable,
277 const kernel_cap_t *permitted)
278 {
279 if (cap_inh_is_capped() &&
280 !cap_issubset(*inheritable,
281 cap_combine(old->cap_inheritable,
282 old->cap_permitted)))
283 /* incapable of using this inheritable set */
284 return -EPERM;
285
286 if (!cap_issubset(*inheritable,
287 cap_combine(old->cap_inheritable,
288 old->cap_bset)))
289 /* no new pI capabilities outside bounding set */
290 return -EPERM;
291
292 /* verify restrictions on target's new Permitted set */
293 if (!cap_issubset(*permitted, old->cap_permitted))
294 return -EPERM;
295
296 /* verify the _new_Effective_ is a subset of the _new_Permitted_ */
297 if (!cap_issubset(*effective, *permitted))
298 return -EPERM;
299
300 new->cap_effective = *effective;
301 new->cap_inheritable = *inheritable;
302 new->cap_permitted = *permitted;
303
304 /*
305 * Mask off ambient bits that are no longer both permitted and
306 * inheritable.
307 */
308 new->cap_ambient = cap_intersect(new->cap_ambient,
309 cap_intersect(*permitted,
310 *inheritable));
311 if (WARN_ON(!cap_ambient_invariant_ok(new)))
312 return -EINVAL;
313 return 0;
314 }
315
316 /**
317 * cap_inode_need_killpriv - Determine if inode change affects privileges
318 * @dentry: The inode/dentry in being changed with change marked ATTR_KILL_PRIV
319 *
320 * Determine if an inode having a change applied that's marked ATTR_KILL_PRIV
321 * affects the security markings on that inode, and if it is, should
322 * inode_killpriv() be invoked or the change rejected.
323 *
324 * Returns 1 if security.capability has a value, meaning inode_killpriv()
325 * is required, 0 otherwise, meaning inode_killpriv() is not required.
326 */
327 int cap_inode_need_killpriv(struct dentry *dentry)
328 {
329 struct inode *inode = d_backing_inode(dentry);
330 int error;
331
332 error = __vfs_getxattr(dentry, inode, XATTR_NAME_CAPS, NULL, 0);
333 return error > 0;
334 }
335
336 /**
337 * cap_inode_killpriv - Erase the security markings on an inode
338 * @dentry: The inode/dentry to alter
339 *
340 * Erase the privilege-enhancing security markings on an inode.
341 *
342 * Returns 0 if successful, -ve on error.
343 */
344 int cap_inode_killpriv(struct dentry *dentry)
345 {
346 int error;
347
348 error = __vfs_removexattr(dentry, XATTR_NAME_CAPS);
349 if (error == -EOPNOTSUPP)
350 error = 0;
351 return error;
352 }
353
354 static bool rootid_owns_currentns(kuid_t kroot)
355 {
356 struct user_namespace *ns;
357
358 if (!uid_valid(kroot))
359 return false;
360
361 for (ns = current_user_ns(); ; ns = ns->parent) {
362 if (from_kuid(ns, kroot) == 0)
363 return true;
364 if (ns == &init_user_ns)
365 break;
366 }
367
368 return false;
369 }
370
371 static __u32 sansflags(__u32 m)
372 {
373 return m & ~VFS_CAP_FLAGS_EFFECTIVE;
374 }
375
376 static bool is_v2header(size_t size, const struct vfs_cap_data *cap)
377 {
378 if (size != XATTR_CAPS_SZ_2)
379 return false;
380 return sansflags(le32_to_cpu(cap->magic_etc)) == VFS_CAP_REVISION_2;
381 }
382
383 static bool is_v3header(size_t size, const struct vfs_cap_data *cap)
384 {
385 if (size != XATTR_CAPS_SZ_3)
386 return false;
387 return sansflags(le32_to_cpu(cap->magic_etc)) == VFS_CAP_REVISION_3;
388 }
389
390 /*
391 * getsecurity: We are called for security.* before any attempt to read the
392 * xattr from the inode itself.
393 *
394 * This gives us a chance to read the on-disk value and convert it. If we
395 * return -EOPNOTSUPP, then vfs_getxattr() will call the i_op handler.
396 *
397 * Note we are not called by vfs_getxattr_alloc(), but that is only called
398 * by the integrity subsystem, which really wants the unconverted values -
399 * so that's good.
400 */
401 int cap_inode_getsecurity(struct inode *inode, const char *name, void **buffer,
402 bool alloc)
403 {
404 int size, ret;
405 kuid_t kroot;
406 uid_t root, mappedroot;
407 char *tmpbuf = NULL;
408 struct vfs_cap_data *cap;
409 struct vfs_ns_cap_data *nscap;
410 struct dentry *dentry;
411 struct user_namespace *fs_ns;
412
413 if (strcmp(name, "capability") != 0)
414 return -EOPNOTSUPP;
415
416 dentry = d_find_alias(inode);
417 if (!dentry)
418 return -EINVAL;
419
420 size = sizeof(struct vfs_ns_cap_data);
421 ret = (int) vfs_getxattr_alloc(dentry, XATTR_NAME_CAPS,
422 &tmpbuf, size, GFP_NOFS);
423 dput(dentry);
424
425 if (ret < 0)
426 return ret;
427
428 fs_ns = inode->i_sb->s_user_ns;
429 cap = (struct vfs_cap_data *) tmpbuf;
430 if (is_v2header((size_t) ret, cap)) {
431 /* If this is sizeof(vfs_cap_data) then we're ok with the
432 * on-disk value, so return that. */
433 if (alloc)
434 *buffer = tmpbuf;
435 else
436 kfree(tmpbuf);
437 return ret;
438 } else if (!is_v3header((size_t) ret, cap)) {
439 kfree(tmpbuf);
440 return -EINVAL;
441 }
442
443 nscap = (struct vfs_ns_cap_data *) tmpbuf;
444 root = le32_to_cpu(nscap->rootid);
445 kroot = make_kuid(fs_ns, root);
446
447 /* If the root kuid maps to a valid uid in current ns, then return
448 * this as a nscap. */
449 mappedroot = from_kuid(current_user_ns(), kroot);
450 if (mappedroot != (uid_t)-1 && mappedroot != (uid_t)0) {
451 if (alloc) {
452 *buffer = tmpbuf;
453 nscap->rootid = cpu_to_le32(mappedroot);
454 } else
455 kfree(tmpbuf);
456 return size;
457 }
458
459 if (!rootid_owns_currentns(kroot)) {
460 kfree(tmpbuf);
461 return -EOPNOTSUPP;
462 }
463
464 /* This comes from a parent namespace. Return as a v2 capability */
465 size = sizeof(struct vfs_cap_data);
466 if (alloc) {
467 *buffer = kmalloc(size, GFP_ATOMIC);
468 if (*buffer) {
469 struct vfs_cap_data *cap = *buffer;
470 __le32 nsmagic, magic;
471 magic = VFS_CAP_REVISION_2;
472 nsmagic = le32_to_cpu(nscap->magic_etc);
473 if (nsmagic & VFS_CAP_FLAGS_EFFECTIVE)
474 magic |= VFS_CAP_FLAGS_EFFECTIVE;
475 memcpy(&cap->data, &nscap->data, sizeof(__le32) * 2 * VFS_CAP_U32);
476 cap->magic_etc = cpu_to_le32(magic);
477 }
478 }
479 kfree(tmpbuf);
480 return size;
481 }
482
483 static kuid_t rootid_from_xattr(const void *value, size_t size,
484 struct user_namespace *task_ns)
485 {
486 const struct vfs_ns_cap_data *nscap = value;
487 uid_t rootid = 0;
488
489 if (size == XATTR_CAPS_SZ_3)
490 rootid = le32_to_cpu(nscap->rootid);
491
492 return make_kuid(task_ns, rootid);
493 }
494
495 static bool validheader(size_t size, const struct vfs_cap_data *cap)
496 {
497 return is_v2header(size, cap) || is_v3header(size, cap);
498 }
499
500 /*
501 * User requested a write of security.capability. If needed, update the
502 * xattr to change from v2 to v3, or to fixup the v3 rootid.
503 *
504 * If all is ok, we return the new size, on error return < 0.
505 */
506 int cap_convert_nscap(struct dentry *dentry, void **ivalue, size_t size)
507 {
508 struct vfs_ns_cap_data *nscap;
509 uid_t nsrootid;
510 const struct vfs_cap_data *cap = *ivalue;
511 __u32 magic, nsmagic;
512 struct inode *inode = d_backing_inode(dentry);
513 struct user_namespace *task_ns = current_user_ns(),
514 *fs_ns = inode->i_sb->s_user_ns;
515 kuid_t rootid;
516 size_t newsize;
517
518 if (!*ivalue)
519 return -EINVAL;
520 if (!validheader(size, cap))
521 return -EINVAL;
522 if (!capable_wrt_inode_uidgid(inode, CAP_SETFCAP))
523 return -EPERM;
524 if (size == XATTR_CAPS_SZ_2)
525 if (ns_capable(inode->i_sb->s_user_ns, CAP_SETFCAP))
526 /* user is privileged, just write the v2 */
527 return size;
528
529 rootid = rootid_from_xattr(*ivalue, size, task_ns);
530 if (!uid_valid(rootid))
531 return -EINVAL;
532
533 nsrootid = from_kuid(fs_ns, rootid);
534 if (nsrootid == -1)
535 return -EINVAL;
536
537 newsize = sizeof(struct vfs_ns_cap_data);
538 nscap = kmalloc(newsize, GFP_ATOMIC);
539 if (!nscap)
540 return -ENOMEM;
541 nscap->rootid = cpu_to_le32(nsrootid);
542 nsmagic = VFS_CAP_REVISION_3;
543 magic = le32_to_cpu(cap->magic_etc);
544 if (magic & VFS_CAP_FLAGS_EFFECTIVE)
545 nsmagic |= VFS_CAP_FLAGS_EFFECTIVE;
546 nscap->magic_etc = cpu_to_le32(nsmagic);
547 memcpy(&nscap->data, &cap->data, sizeof(__le32) * 2 * VFS_CAP_U32);
548
549 kvfree(*ivalue);
550 *ivalue = nscap;
551 return newsize;
552 }
553
554 /*
555 * Calculate the new process capability sets from the capability sets attached
556 * to a file.
557 */
558 static inline int bprm_caps_from_vfs_caps(struct cpu_vfs_cap_data *caps,
559 struct linux_binprm *bprm,
560 bool *effective,
561 bool *has_cap)
562 {
563 struct cred *new = bprm->cred;
564 unsigned i;
565 int ret = 0;
566
567 if (caps->magic_etc & VFS_CAP_FLAGS_EFFECTIVE)
568 *effective = true;
569
570 if (caps->magic_etc & VFS_CAP_REVISION_MASK)
571 *has_cap = true;
572
573 CAP_FOR_EACH_U32(i) {
574 __u32 permitted = caps->permitted.cap[i];
575 __u32 inheritable = caps->inheritable.cap[i];
576
577 /*
578 * pP' = (X & fP) | (pI & fI)
579 * The addition of pA' is handled later.
580 */
581 new->cap_permitted.cap[i] =
582 (new->cap_bset.cap[i] & permitted) |
583 (new->cap_inheritable.cap[i] & inheritable);
584
585 if (permitted & ~new->cap_permitted.cap[i])
586 /* insufficient to execute correctly */
587 ret = -EPERM;
588 }
589
590 /*
591 * For legacy apps, with no internal support for recognizing they
592 * do not have enough capabilities, we return an error if they are
593 * missing some "forced" (aka file-permitted) capabilities.
594 */
595 return *effective ? ret : 0;
596 }
597
598 /*
599 * Extract the on-exec-apply capability sets for an executable file.
600 */
601 int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps)
602 {
603 struct inode *inode = d_backing_inode(dentry);
604 __u32 magic_etc;
605 unsigned tocopy, i;
606 int size;
607 struct vfs_ns_cap_data data, *nscaps = &data;
608 struct vfs_cap_data *caps = (struct vfs_cap_data *) &data;
609 kuid_t rootkuid;
610 struct user_namespace *fs_ns;
611
612 memset(cpu_caps, 0, sizeof(struct cpu_vfs_cap_data));
613
614 if (!inode)
615 return -ENODATA;
616
617 fs_ns = inode->i_sb->s_user_ns;
618 size = __vfs_getxattr((struct dentry *)dentry, inode,
619 XATTR_NAME_CAPS, &data, XATTR_CAPS_SZ);
620 if (size == -ENODATA || size == -EOPNOTSUPP)
621 /* no data, that's ok */
622 return -ENODATA;
623
624 if (size < 0)
625 return size;
626
627 if (size < sizeof(magic_etc))
628 return -EINVAL;
629
630 cpu_caps->magic_etc = magic_etc = le32_to_cpu(caps->magic_etc);
631
632 rootkuid = make_kuid(fs_ns, 0);
633 switch (magic_etc & VFS_CAP_REVISION_MASK) {
634 case VFS_CAP_REVISION_1:
635 if (size != XATTR_CAPS_SZ_1)
636 return -EINVAL;
637 tocopy = VFS_CAP_U32_1;
638 break;
639 case VFS_CAP_REVISION_2:
640 if (size != XATTR_CAPS_SZ_2)
641 return -EINVAL;
642 tocopy = VFS_CAP_U32_2;
643 break;
644 case VFS_CAP_REVISION_3:
645 if (size != XATTR_CAPS_SZ_3)
646 return -EINVAL;
647 tocopy = VFS_CAP_U32_3;
648 rootkuid = make_kuid(fs_ns, le32_to_cpu(nscaps->rootid));
649 break;
650
651 default:
652 return -EINVAL;
653 }
654 /* Limit the caps to the mounter of the filesystem
655 * or the more limited uid specified in the xattr.
656 */
657 if (!rootid_owns_currentns(rootkuid))
658 return -ENODATA;
659
660 CAP_FOR_EACH_U32(i) {
661 if (i >= tocopy)
662 break;
663 cpu_caps->permitted.cap[i] = le32_to_cpu(caps->data[i].permitted);
664 cpu_caps->inheritable.cap[i] = le32_to_cpu(caps->data[i].inheritable);
665 }
666
667 cpu_caps->permitted.cap[CAP_LAST_U32] &= CAP_LAST_U32_VALID_MASK;
668 cpu_caps->inheritable.cap[CAP_LAST_U32] &= CAP_LAST_U32_VALID_MASK;
669
670 return 0;
671 }
672
673 /*
674 * Attempt to get the on-exec apply capability sets for an executable file from
675 * its xattrs and, if present, apply them to the proposed credentials being
676 * constructed by execve().
677 */
678 static int get_file_caps(struct linux_binprm *bprm, bool *effective, bool *has_cap)
679 {
680 int rc = 0;
681 struct cpu_vfs_cap_data vcaps;
682
683 cap_clear(bprm->cred->cap_permitted);
684
685 if (!file_caps_enabled)
686 return 0;
687
688 if (!mnt_may_suid(bprm->file->f_path.mnt))
689 return 0;
690
691 /*
692 * This check is redundant with mnt_may_suid() but is kept to make
693 * explicit that capability bits are limited to s_user_ns and its
694 * descendants.
695 */
696 if (!current_in_userns(bprm->file->f_path.mnt->mnt_sb->s_user_ns))
697 return 0;
698
699 rc = get_vfs_caps_from_disk(bprm->file->f_path.dentry, &vcaps);
700 if (rc < 0) {
701 if (rc == -EINVAL)
702 printk(KERN_NOTICE "Invalid argument reading file caps for %s\n",
703 bprm->filename);
704 else if (rc == -ENODATA)
705 rc = 0;
706 goto out;
707 }
708
709 rc = bprm_caps_from_vfs_caps(&vcaps, bprm, effective, has_cap);
710 if (rc == -EINVAL)
711 printk(KERN_NOTICE "%s: cap_from_disk returned %d for %s\n",
712 __func__, rc, bprm->filename);
713
714 out:
715 if (rc)
716 cap_clear(bprm->cred->cap_permitted);
717
718 return rc;
719 }
720
721 /**
722 * cap_bprm_set_creds - Set up the proposed credentials for execve().
723 * @bprm: The execution parameters, including the proposed creds
724 *
725 * Set up the proposed credentials for a new execution context being
726 * constructed by execve(). The proposed creds in @bprm->cred is altered,
727 * which won't take effect immediately. Returns 0 if successful, -ve on error.
728 */
729 int cap_bprm_set_creds(struct linux_binprm *bprm)
730 {
731 const struct cred *old = current_cred();
732 struct cred *new = bprm->cred;
733 bool effective, has_cap = false, is_setid;
734 int ret;
735 kuid_t root_uid;
736
737 if (WARN_ON(!cap_ambient_invariant_ok(old)))
738 return -EPERM;
739
740 effective = false;
741 ret = get_file_caps(bprm, &effective, &has_cap);
742 if (ret < 0)
743 return ret;
744
745 root_uid = make_kuid(new->user_ns, 0);
746
747 if (!issecure(SECURE_NOROOT)) {
748 /*
749 * If the legacy file capability is set, then don't set privs
750 * for a setuid root binary run by a non-root user. Do set it
751 * for a root user just to cause least surprise to an admin.
752 */
753 if (has_cap && !uid_eq(new->uid, root_uid) && uid_eq(new->euid, root_uid)) {
754 warn_setuid_and_fcaps_mixed(bprm->filename);
755 goto skip;
756 }
757 /*
758 * To support inheritance of root-permissions and suid-root
759 * executables under compatibility mode, we override the
760 * capability sets for the file.
761 *
762 * If only the real uid is 0, we do not set the effective bit.
763 */
764 if (uid_eq(new->euid, root_uid) || uid_eq(new->uid, root_uid)) {
765 /* pP' = (cap_bset & ~0) | (pI & ~0) */
766 new->cap_permitted = cap_combine(old->cap_bset,
767 old->cap_inheritable);
768 }
769 if (uid_eq(new->euid, root_uid))
770 effective = true;
771 }
772 skip:
773
774 /* if we have fs caps, clear dangerous personality flags */
775 if (!cap_issubset(new->cap_permitted, old->cap_permitted))
776 bprm->per_clear |= PER_CLEAR_ON_SETID;
777
778
779 /* Don't let someone trace a set[ug]id/setpcap binary with the revised
780 * credentials unless they have the appropriate permit.
781 *
782 * In addition, if NO_NEW_PRIVS, then ensure we get no new privs.
783 */
784 is_setid = !uid_eq(new->euid, old->uid) || !gid_eq(new->egid, old->gid);
785
786 if ((is_setid ||
787 !cap_issubset(new->cap_permitted, old->cap_permitted)) &&
788 ((bprm->unsafe & ~LSM_UNSAFE_PTRACE) ||
789 !ptracer_capable(current, new->user_ns))) {
790 /* downgrade; they get no more than they had, and maybe less */
791 if (!ns_capable(new->user_ns, CAP_SETUID) ||
792 (bprm->unsafe & LSM_UNSAFE_NO_NEW_PRIVS)) {
793 new->euid = new->uid;
794 new->egid = new->gid;
795 }
796 new->cap_permitted = cap_intersect(new->cap_permitted,
797 old->cap_permitted);
798 }
799
800 new->suid = new->fsuid = new->euid;
801 new->sgid = new->fsgid = new->egid;
802
803 /* File caps or setid cancels ambient. */
804 if (has_cap || is_setid)
805 cap_clear(new->cap_ambient);
806
807 /*
808 * Now that we've computed pA', update pP' to give:
809 * pP' = (X & fP) | (pI & fI) | pA'
810 */
811 new->cap_permitted = cap_combine(new->cap_permitted, new->cap_ambient);
812
813 /*
814 * Set pE' = (fE ? pP' : pA'). Because pA' is zero if fE is set,
815 * this is the same as pE' = (fE ? pP' : 0) | pA'.
816 */
817 if (effective)
818 new->cap_effective = new->cap_permitted;
819 else
820 new->cap_effective = new->cap_ambient;
821
822 if (WARN_ON(!cap_ambient_invariant_ok(new)))
823 return -EPERM;
824
825 /*
826 * Audit candidate if current->cap_effective is set
827 *
828 * We do not bother to audit if 3 things are true:
829 * 1) cap_effective has all caps
830 * 2) we are root
831 * 3) root is supposed to have all caps (SECURE_NOROOT)
832 * Since this is just a normal root execing a process.
833 *
834 * Number 1 above might fail if you don't have a full bset, but I think
835 * that is interesting information to audit.
836 */
837 if (!cap_issubset(new->cap_effective, new->cap_ambient)) {
838 if (!cap_issubset(CAP_FULL_SET, new->cap_effective) ||
839 !uid_eq(new->euid, root_uid) || !uid_eq(new->uid, root_uid) ||
840 issecure(SECURE_NOROOT)) {
841 ret = audit_log_bprm_fcaps(bprm, new, old);
842 if (ret < 0)
843 return ret;
844 }
845 }
846
847 new->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);
848
849 if (WARN_ON(!cap_ambient_invariant_ok(new)))
850 return -EPERM;
851
852 /* Check for privilege-elevated exec. */
853 bprm->cap_elevated = 0;
854 if (is_setid) {
855 bprm->cap_elevated = 1;
856 } else if (!uid_eq(new->uid, root_uid)) {
857 if (effective ||
858 !cap_issubset(new->cap_permitted, new->cap_ambient))
859 bprm->cap_elevated = 1;
860 }
861
862 return 0;
863 }
864
865 /**
866 * cap_inode_setxattr - Determine whether an xattr may be altered
867 * @dentry: The inode/dentry being altered
868 * @name: The name of the xattr to be changed
869 * @value: The value that the xattr will be changed to
870 * @size: The size of value
871 * @flags: The replacement flag
872 *
873 * Determine whether an xattr may be altered or set on an inode, returning 0 if
874 * permission is granted, -ve if denied.
875 *
876 * This is used to make sure security xattrs don't get updated or set by those
877 * who aren't privileged to do so.
878 */
879 int cap_inode_setxattr(struct dentry *dentry, const char *name,
880 const void *value, size_t size, int flags)
881 {
882 /* Ignore non-security xattrs */
883 if (strncmp(name, XATTR_SECURITY_PREFIX,
884 sizeof(XATTR_SECURITY_PREFIX) - 1) != 0)
885 return 0;
886
887 /*
888 * For XATTR_NAME_CAPS the check will be done in
889 * cap_convert_nscap(), called by setxattr()
890 */
891 if (strcmp(name, XATTR_NAME_CAPS) == 0)
892 return 0;
893
894 if (!capable(CAP_SYS_ADMIN))
895 return -EPERM;
896 return 0;
897 }
898
899 /**
900 * cap_inode_removexattr - Determine whether an xattr may be removed
901 * @dentry: The inode/dentry being altered
902 * @name: The name of the xattr to be changed
903 *
904 * Determine whether an xattr may be removed from an inode, returning 0 if
905 * permission is granted, -ve if denied.
906 *
907 * This is used to make sure security xattrs don't get removed by those who
908 * aren't privileged to remove them.
909 */
910 int cap_inode_removexattr(struct dentry *dentry, const char *name)
911 {
912 /* Ignore non-security xattrs */
913 if (strncmp(name, XATTR_SECURITY_PREFIX,
914 sizeof(XATTR_SECURITY_PREFIX) - 1) != 0)
915 return 0;
916
917 if (strcmp(name, XATTR_NAME_CAPS) == 0) {
918 /* security.capability gets namespaced */
919 struct inode *inode = d_backing_inode(dentry);
920 if (!inode)
921 return -EINVAL;
922 if (!capable_wrt_inode_uidgid(inode, CAP_SETFCAP))
923 return -EPERM;
924 return 0;
925 }
926
927 if (!capable(CAP_SYS_ADMIN))
928 return -EPERM;
929 return 0;
930 }
931
932 /*
933 * cap_emulate_setxuid() fixes the effective / permitted capabilities of
934 * a process after a call to setuid, setreuid, or setresuid.
935 *
936 * 1) When set*uiding _from_ one of {r,e,s}uid == 0 _to_ all of
937 * {r,e,s}uid != 0, the permitted and effective capabilities are
938 * cleared.
939 *
940 * 2) When set*uiding _from_ euid == 0 _to_ euid != 0, the effective
941 * capabilities of the process are cleared.
942 *
943 * 3) When set*uiding _from_ euid != 0 _to_ euid == 0, the effective
944 * capabilities are set to the permitted capabilities.
945 *
946 * fsuid is handled elsewhere. fsuid == 0 and {r,e,s}uid!= 0 should
947 * never happen.
948 *
949 * -astor
950 *
951 * cevans - New behaviour, Oct '99
952 * A process may, via prctl(), elect to keep its capabilities when it
953 * calls setuid() and switches away from uid==0. Both permitted and
954 * effective sets will be retained.
955 * Without this change, it was impossible for a daemon to drop only some
956 * of its privilege. The call to setuid(!=0) would drop all privileges!
957 * Keeping uid 0 is not an option because uid 0 owns too many vital
958 * files..
959 * Thanks to Olaf Kirch and Peter Benie for spotting this.
960 */
961 static inline void cap_emulate_setxuid(struct cred *new, const struct cred *old)
962 {
963 kuid_t root_uid = make_kuid(old->user_ns, 0);
964
965 if ((uid_eq(old->uid, root_uid) ||
966 uid_eq(old->euid, root_uid) ||
967 uid_eq(old->suid, root_uid)) &&
968 (!uid_eq(new->uid, root_uid) &&
969 !uid_eq(new->euid, root_uid) &&
970 !uid_eq(new->suid, root_uid))) {
971 if (!issecure(SECURE_KEEP_CAPS)) {
972 cap_clear(new->cap_permitted);
973 cap_clear(new->cap_effective);
974 }
975
976 /*
977 * Pre-ambient programs expect setresuid to nonroot followed
978 * by exec to drop capabilities. We should make sure that
979 * this remains the case.
980 */
981 cap_clear(new->cap_ambient);
982 }
983 if (uid_eq(old->euid, root_uid) && !uid_eq(new->euid, root_uid))
984 cap_clear(new->cap_effective);
985 if (!uid_eq(old->euid, root_uid) && uid_eq(new->euid, root_uid))
986 new->cap_effective = new->cap_permitted;
987 }
988
989 /**
990 * cap_task_fix_setuid - Fix up the results of setuid() call
991 * @new: The proposed credentials
992 * @old: The current task's current credentials
993 * @flags: Indications of what has changed
994 *
995 * Fix up the results of setuid() call before the credential changes are
996 * actually applied, returning 0 to grant the changes, -ve to deny them.
997 */
998 int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags)
999 {
1000 switch (flags) {
1001 case LSM_SETID_RE:
1002 case LSM_SETID_ID:
1003 case LSM_SETID_RES:
1004 /* juggle the capabilities to follow [RES]UID changes unless
1005 * otherwise suppressed */
1006 if (!issecure(SECURE_NO_SETUID_FIXUP))
1007 cap_emulate_setxuid(new, old);
1008 break;
1009
1010 case LSM_SETID_FS:
1011 /* juggle the capabilties to follow FSUID changes, unless
1012 * otherwise suppressed
1013 *
1014 * FIXME - is fsuser used for all CAP_FS_MASK capabilities?
1015 * if not, we might be a bit too harsh here.
1016 */
1017 if (!issecure(SECURE_NO_SETUID_FIXUP)) {
1018 kuid_t root_uid = make_kuid(old->user_ns, 0);
1019 if (uid_eq(old->fsuid, root_uid) && !uid_eq(new->fsuid, root_uid))
1020 new->cap_effective =
1021 cap_drop_fs_set(new->cap_effective);
1022
1023 if (!uid_eq(old->fsuid, root_uid) && uid_eq(new->fsuid, root_uid))
1024 new->cap_effective =
1025 cap_raise_fs_set(new->cap_effective,
1026 new->cap_permitted);
1027 }
1028 break;
1029
1030 default:
1031 return -EINVAL;
1032 }
1033
1034 return 0;
1035 }
1036
1037 /*
1038 * Rationale: code calling task_setscheduler, task_setioprio, and
1039 * task_setnice, assumes that
1040 * . if capable(cap_sys_nice), then those actions should be allowed
1041 * . if not capable(cap_sys_nice), but acting on your own processes,
1042 * then those actions should be allowed
1043 * This is insufficient now since you can call code without suid, but
1044 * yet with increased caps.
1045 * So we check for increased caps on the target process.
1046 */
1047 static int cap_safe_nice(struct task_struct *p)
1048 {
1049 int is_subset, ret = 0;
1050
1051 rcu_read_lock();
1052 is_subset = cap_issubset(__task_cred(p)->cap_permitted,
1053 current_cred()->cap_permitted);
1054 if (!is_subset && !ns_capable(__task_cred(p)->user_ns, CAP_SYS_NICE))
1055 ret = -EPERM;
1056 rcu_read_unlock();
1057
1058 return ret;
1059 }
1060
1061 /**
1062 * cap_task_setscheduler - Detemine if scheduler policy change is permitted
1063 * @p: The task to affect
1064 *
1065 * Detemine if the requested scheduler policy change is permitted for the
1066 * specified task, returning 0 if permission is granted, -ve if denied.
1067 */
1068 int cap_task_setscheduler(struct task_struct *p)
1069 {
1070 return cap_safe_nice(p);
1071 }
1072
1073 /**
1074 * cap_task_ioprio - Detemine if I/O priority change is permitted
1075 * @p: The task to affect
1076 * @ioprio: The I/O priority to set
1077 *
1078 * Detemine if the requested I/O priority change is permitted for the specified
1079 * task, returning 0 if permission is granted, -ve if denied.
1080 */
1081 int cap_task_setioprio(struct task_struct *p, int ioprio)
1082 {
1083 return cap_safe_nice(p);
1084 }
1085
1086 /**
1087 * cap_task_ioprio - Detemine if task priority change is permitted
1088 * @p: The task to affect
1089 * @nice: The nice value to set
1090 *
1091 * Detemine if the requested task priority change is permitted for the
1092 * specified task, returning 0 if permission is granted, -ve if denied.
1093 */
1094 int cap_task_setnice(struct task_struct *p, int nice)
1095 {
1096 return cap_safe_nice(p);
1097 }
1098
1099 /*
1100 * Implement PR_CAPBSET_DROP. Attempt to remove the specified capability from
1101 * the current task's bounding set. Returns 0 on success, -ve on error.
1102 */
1103 static int cap_prctl_drop(unsigned long cap)
1104 {
1105 struct cred *new;
1106
1107 if (!ns_capable(current_user_ns(), CAP_SETPCAP))
1108 return -EPERM;
1109 if (!cap_valid(cap))
1110 return -EINVAL;
1111
1112 new = prepare_creds();
1113 if (!new)
1114 return -ENOMEM;
1115 cap_lower(new->cap_bset, cap);
1116 return commit_creds(new);
1117 }
1118
1119 /**
1120 * cap_task_prctl - Implement process control functions for this security module
1121 * @option: The process control function requested
1122 * @arg2, @arg3, @arg4, @arg5: The argument data for this function
1123 *
1124 * Allow process control functions (sys_prctl()) to alter capabilities; may
1125 * also deny access to other functions not otherwise implemented here.
1126 *
1127 * Returns 0 or +ve on success, -ENOSYS if this function is not implemented
1128 * here, other -ve on error. If -ENOSYS is returned, sys_prctl() and other LSM
1129 * modules will consider performing the function.
1130 */
1131 int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
1132 unsigned long arg4, unsigned long arg5)
1133 {
1134 const struct cred *old = current_cred();
1135 struct cred *new;
1136
1137 switch (option) {
1138 case PR_CAPBSET_READ:
1139 if (!cap_valid(arg2))
1140 return -EINVAL;
1141 return !!cap_raised(old->cap_bset, arg2);
1142
1143 case PR_CAPBSET_DROP:
1144 return cap_prctl_drop(arg2);
1145
1146 /*
1147 * The next four prctl's remain to assist with transitioning a
1148 * system from legacy UID=0 based privilege (when filesystem
1149 * capabilities are not in use) to a system using filesystem
1150 * capabilities only - as the POSIX.1e draft intended.
1151 *
1152 * Note:
1153 *
1154 * PR_SET_SECUREBITS =
1155 * issecure_mask(SECURE_KEEP_CAPS_LOCKED)
1156 * | issecure_mask(SECURE_NOROOT)
1157 * | issecure_mask(SECURE_NOROOT_LOCKED)
1158 * | issecure_mask(SECURE_NO_SETUID_FIXUP)
1159 * | issecure_mask(SECURE_NO_SETUID_FIXUP_LOCKED)
1160 *
1161 * will ensure that the current process and all of its
1162 * children will be locked into a pure
1163 * capability-based-privilege environment.
1164 */
1165 case PR_SET_SECUREBITS:
1166 if ((((old->securebits & SECURE_ALL_LOCKS) >> 1)
1167 & (old->securebits ^ arg2)) /*[1]*/
1168 || ((old->securebits & SECURE_ALL_LOCKS & ~arg2)) /*[2]*/
1169 || (arg2 & ~(SECURE_ALL_LOCKS | SECURE_ALL_BITS)) /*[3]*/
1170 || (cap_capable(current_cred(),
1171 current_cred()->user_ns, CAP_SETPCAP,
1172 SECURITY_CAP_AUDIT) != 0) /*[4]*/
1173 /*
1174 * [1] no changing of bits that are locked
1175 * [2] no unlocking of locks
1176 * [3] no setting of unsupported bits
1177 * [4] doing anything requires privilege (go read about
1178 * the "sendmail capabilities bug")
1179 */
1180 )
1181 /* cannot change a locked bit */
1182 return -EPERM;
1183
1184 new = prepare_creds();
1185 if (!new)
1186 return -ENOMEM;
1187 new->securebits = arg2;
1188 return commit_creds(new);
1189
1190 case PR_GET_SECUREBITS:
1191 return old->securebits;
1192
1193 case PR_GET_KEEPCAPS:
1194 return !!issecure(SECURE_KEEP_CAPS);
1195
1196 case PR_SET_KEEPCAPS:
1197 if (arg2 > 1) /* Note, we rely on arg2 being unsigned here */
1198 return -EINVAL;
1199 if (issecure(SECURE_KEEP_CAPS_LOCKED))
1200 return -EPERM;
1201
1202 new = prepare_creds();
1203 if (!new)
1204 return -ENOMEM;
1205 if (arg2)
1206 new->securebits |= issecure_mask(SECURE_KEEP_CAPS);
1207 else
1208 new->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);
1209 return commit_creds(new);
1210
1211 case PR_CAP_AMBIENT:
1212 if (arg2 == PR_CAP_AMBIENT_CLEAR_ALL) {
1213 if (arg3 | arg4 | arg5)
1214 return -EINVAL;
1215
1216 new = prepare_creds();
1217 if (!new)
1218 return -ENOMEM;
1219 cap_clear(new->cap_ambient);
1220 return commit_creds(new);
1221 }
1222
1223 if (((!cap_valid(arg3)) | arg4 | arg5))
1224 return -EINVAL;
1225
1226 if (arg2 == PR_CAP_AMBIENT_IS_SET) {
1227 return !!cap_raised(current_cred()->cap_ambient, arg3);
1228 } else if (arg2 != PR_CAP_AMBIENT_RAISE &&
1229 arg2 != PR_CAP_AMBIENT_LOWER) {
1230 return -EINVAL;
1231 } else {
1232 if (arg2 == PR_CAP_AMBIENT_RAISE &&
1233 (!cap_raised(current_cred()->cap_permitted, arg3) ||
1234 !cap_raised(current_cred()->cap_inheritable,
1235 arg3) ||
1236 issecure(SECURE_NO_CAP_AMBIENT_RAISE)))
1237 return -EPERM;
1238
1239 new = prepare_creds();
1240 if (!new)
1241 return -ENOMEM;
1242 if (arg2 == PR_CAP_AMBIENT_RAISE)
1243 cap_raise(new->cap_ambient, arg3);
1244 else
1245 cap_lower(new->cap_ambient, arg3);
1246 return commit_creds(new);
1247 }
1248
1249 default:
1250 /* No functionality available - continue with default */
1251 return -ENOSYS;
1252 }
1253 }
1254
1255 /**
1256 * cap_vm_enough_memory - Determine whether a new virtual mapping is permitted
1257 * @mm: The VM space in which the new mapping is to be made
1258 * @pages: The size of the mapping
1259 *
1260 * Determine whether the allocation of a new virtual mapping by the current
1261 * task is permitted, returning 1 if permission is granted, 0 if not.
1262 */
1263 int cap_vm_enough_memory(struct mm_struct *mm, long pages)
1264 {
1265 int cap_sys_admin = 0;
1266
1267 if (cap_capable(current_cred(), &init_user_ns, CAP_SYS_ADMIN,
1268 SECURITY_CAP_NOAUDIT) == 0)
1269 cap_sys_admin = 1;
1270 return cap_sys_admin;
1271 }
1272
1273 /*
1274 * cap_mmap_addr - check if able to map given addr
1275 * @addr: address attempting to be mapped
1276 *
1277 * If the process is attempting to map memory below dac_mmap_min_addr they need
1278 * CAP_SYS_RAWIO. The other parameters to this function are unused by the
1279 * capability security module. Returns 0 if this mapping should be allowed
1280 * -EPERM if not.
1281 */
1282 int cap_mmap_addr(unsigned long addr)
1283 {
1284 int ret = 0;
1285
1286 if (addr < dac_mmap_min_addr) {
1287 ret = cap_capable(current_cred(), &init_user_ns, CAP_SYS_RAWIO,
1288 SECURITY_CAP_AUDIT);
1289 /* set PF_SUPERPRIV if it turns out we allow the low mmap */
1290 if (ret == 0)
1291 current->flags |= PF_SUPERPRIV;
1292 }
1293 return ret;
1294 }
1295
1296 int cap_mmap_file(struct file *file, unsigned long reqprot,
1297 unsigned long prot, unsigned long flags)
1298 {
1299 return 0;
1300 }
1301
1302 #ifdef CONFIG_SECURITY
1303
1304 struct security_hook_list capability_hooks[] __lsm_ro_after_init = {
1305 LSM_HOOK_INIT(capable, cap_capable),
1306 LSM_HOOK_INIT(settime, cap_settime),
1307 LSM_HOOK_INIT(ptrace_access_check, cap_ptrace_access_check),
1308 LSM_HOOK_INIT(ptrace_traceme, cap_ptrace_traceme),
1309 LSM_HOOK_INIT(capget, cap_capget),
1310 LSM_HOOK_INIT(capset, cap_capset),
1311 LSM_HOOK_INIT(bprm_set_creds, cap_bprm_set_creds),
1312 LSM_HOOK_INIT(inode_need_killpriv, cap_inode_need_killpriv),
1313 LSM_HOOK_INIT(inode_killpriv, cap_inode_killpriv),
1314 LSM_HOOK_INIT(inode_getsecurity, cap_inode_getsecurity),
1315 LSM_HOOK_INIT(mmap_addr, cap_mmap_addr),
1316 LSM_HOOK_INIT(mmap_file, cap_mmap_file),
1317 LSM_HOOK_INIT(task_fix_setuid, cap_task_fix_setuid),
1318 LSM_HOOK_INIT(task_prctl, cap_task_prctl),
1319 LSM_HOOK_INIT(task_setscheduler, cap_task_setscheduler),
1320 LSM_HOOK_INIT(task_setioprio, cap_task_setioprio),
1321 LSM_HOOK_INIT(task_setnice, cap_task_setnice),
1322 LSM_HOOK_INIT(vm_enough_memory, cap_vm_enough_memory),
1323 };
1324
1325 void __init capability_add_hooks(void)
1326 {
1327 security_add_hooks(capability_hooks, ARRAY_SIZE(capability_hooks),
1328 "capability");
1329 }
1330
1331 #endif /* CONFIG_SECURITY */