commoncap.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /* Common capabilities, needed by capability.o and root_plug.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. #include <linux/capability.h>
  10. #include <linux/module.h>
  11. #include <linux/init.h>
  12. #include <linux/kernel.h>
  13. #include <linux/security.h>
  14. #include <linux/file.h>
  15. #include <linux/mm.h>
  16. #include <linux/mman.h>
  17. #include <linux/pagemap.h>
  18. #include <linux/swap.h>
  19. #include <linux/skbuff.h>
  20. #include <linux/netlink.h>
  21. #include <linux/ptrace.h>
  22. #include <linux/xattr.h>
  23. #include <linux/hugetlb.h>
  24. #include <linux/mount.h>
  25. #include <linux/sched.h>
  26. #include <linux/prctl.h>
  27. #include <linux/securebits.h>
  28. int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
  29. {
  30. NETLINK_CB(skb).eff_cap = current->cap_effective;
  31. return 0;
  32. }
  33. int cap_netlink_recv(struct sk_buff *skb, int cap)
  34. {
  35. if (!cap_raised(NETLINK_CB(skb).eff_cap, cap))
  36. return -EPERM;
  37. return 0;
  38. }
  39. EXPORT_SYMBOL(cap_netlink_recv);
  40. /*
  41. * NOTE WELL: cap_capable() cannot be used like the kernel's capable()
  42. * function. That is, it has the reverse semantics: cap_capable()
  43. * returns 0 when a task has a capability, but the kernel's capable()
  44. * returns 1 for this case.
  45. */
  46. int cap_capable (struct task_struct *tsk, int cap)
  47. {
  48. /* Derived from include/linux/sched.h:capable. */
  49. if (cap_raised(tsk->cap_effective, cap))
  50. return 0;
  51. return -EPERM;
  52. }
  53. int cap_settime(struct timespec *ts, struct timezone *tz)
  54. {
  55. if (!capable(CAP_SYS_TIME))
  56. return -EPERM;
  57. return 0;
  58. }
  59. int cap_ptrace (struct task_struct *parent, struct task_struct *child)
  60. {
  61. /* Derived from arch/i386/kernel/ptrace.c:sys_ptrace. */
  62. if (!cap_issubset(child->cap_permitted, parent->cap_permitted) &&
  63. !__capable(parent, CAP_SYS_PTRACE))
  64. return -EPERM;
  65. return 0;
  66. }
  67. int cap_capget (struct task_struct *target, kernel_cap_t *effective,
  68. kernel_cap_t *inheritable, kernel_cap_t *permitted)
  69. {
  70. /* Derived from kernel/capability.c:sys_capget. */
  71. *effective = target->cap_effective;
  72. *inheritable = target->cap_inheritable;
  73. *permitted = target->cap_permitted;
  74. return 0;
  75. }
  76. #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
  77. static inline int cap_block_setpcap(struct task_struct *target)
  78. {
  79. /*
  80. * No support for remote process capability manipulation with
  81. * filesystem capability support.
  82. */
  83. return (target != current);
  84. }
  85. static inline int cap_inh_is_capped(void)
  86. {
  87. /*
  88. * Return 1 if changes to the inheritable set are limited
  89. * to the old permitted set. That is, if the current task
  90. * does *not* possess the CAP_SETPCAP capability.
  91. */
  92. return (cap_capable(current, CAP_SETPCAP) != 0);
  93. }
  94. static inline int cap_limit_ptraced_target(void) { return 1; }
  95. #else /* ie., ndef CONFIG_SECURITY_FILE_CAPABILITIES */
  96. static inline int cap_block_setpcap(struct task_struct *t) { return 0; }
  97. static inline int cap_inh_is_capped(void) { return 1; }
  98. static inline int cap_limit_ptraced_target(void)
  99. {
  100. return !capable(CAP_SETPCAP);
  101. }
  102. #endif /* def CONFIG_SECURITY_FILE_CAPABILITIES */
  103. int cap_capset_check (struct task_struct *target, kernel_cap_t *effective,
  104. kernel_cap_t *inheritable, kernel_cap_t *permitted)
  105. {
  106. if (cap_block_setpcap(target)) {
  107. return -EPERM;
  108. }
  109. if (cap_inh_is_capped()
  110. && !cap_issubset(*inheritable,
  111. cap_combine(target->cap_inheritable,
  112. current->cap_permitted))) {
  113. /* incapable of using this inheritable set */
  114. return -EPERM;
  115. }
  116. if (!cap_issubset(*inheritable,
  117. cap_combine(target->cap_inheritable,
  118. current->cap_bset))) {
  119. /* no new pI capabilities outside bounding set */
  120. return -EPERM;
  121. }
  122. /* verify restrictions on target's new Permitted set */
  123. if (!cap_issubset (*permitted,
  124. cap_combine (target->cap_permitted,
  125. current->cap_permitted))) {
  126. return -EPERM;
  127. }
  128. /* verify the _new_Effective_ is a subset of the _new_Permitted_ */
  129. if (!cap_issubset (*effective, *permitted)) {
  130. return -EPERM;
  131. }
  132. return 0;
  133. }
  134. void cap_capset_set (struct task_struct *target, kernel_cap_t *effective,
  135. kernel_cap_t *inheritable, kernel_cap_t *permitted)
  136. {
  137. target->cap_effective = *effective;
  138. target->cap_inheritable = *inheritable;
  139. target->cap_permitted = *permitted;
  140. }
  141. static inline void bprm_clear_caps(struct linux_binprm *bprm)
  142. {
  143. cap_clear(bprm->cap_inheritable);
  144. cap_clear(bprm->cap_permitted);
  145. bprm->cap_effective = false;
  146. }
  147. #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
  148. int cap_inode_need_killpriv(struct dentry *dentry)
  149. {
  150. struct inode *inode = dentry->d_inode;
  151. int error;
  152. if (!inode->i_op || !inode->i_op->getxattr)
  153. return 0;
  154. error = inode->i_op->getxattr(dentry, XATTR_NAME_CAPS, NULL, 0);
  155. if (error <= 0)
  156. return 0;
  157. return 1;
  158. }
  159. int cap_inode_killpriv(struct dentry *dentry)
  160. {
  161. struct inode *inode = dentry->d_inode;
  162. if (!inode->i_op || !inode->i_op->removexattr)
  163. return 0;
  164. return inode->i_op->removexattr(dentry, XATTR_NAME_CAPS);
  165. }
  166. static inline int cap_from_disk(struct vfs_cap_data *caps,
  167. struct linux_binprm *bprm, unsigned size)
  168. {
  169. __u32 magic_etc;
  170. unsigned tocopy, i;
  171. if (size < sizeof(magic_etc))
  172. return -EINVAL;
  173. magic_etc = le32_to_cpu(caps->magic_etc);
  174. switch ((magic_etc & VFS_CAP_REVISION_MASK)) {
  175. case VFS_CAP_REVISION_1:
  176. if (size != XATTR_CAPS_SZ_1)
  177. return -EINVAL;
  178. tocopy = VFS_CAP_U32_1;
  179. break;
  180. case VFS_CAP_REVISION_2:
  181. if (size != XATTR_CAPS_SZ_2)
  182. return -EINVAL;
  183. tocopy = VFS_CAP_U32_2;
  184. break;
  185. default:
  186. return -EINVAL;
  187. }
  188. if (magic_etc & VFS_CAP_FLAGS_EFFECTIVE) {
  189. bprm->cap_effective = true;
  190. } else {
  191. bprm->cap_effective = false;
  192. }
  193. for (i = 0; i < tocopy; ++i) {
  194. bprm->cap_permitted.cap[i] =
  195. le32_to_cpu(caps->data[i].permitted);
  196. bprm->cap_inheritable.cap[i] =
  197. le32_to_cpu(caps->data[i].inheritable);
  198. }
  199. while (i < VFS_CAP_U32) {
  200. bprm->cap_permitted.cap[i] = 0;
  201. bprm->cap_inheritable.cap[i] = 0;
  202. i++;
  203. }
  204. return 0;
  205. }
  206. /* Locate any VFS capabilities: */
  207. static int get_file_caps(struct linux_binprm *bprm)
  208. {
  209. struct dentry *dentry;
  210. int rc = 0;
  211. struct vfs_cap_data vcaps;
  212. struct inode *inode;
  213. if (bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID) {
  214. bprm_clear_caps(bprm);
  215. return 0;
  216. }
  217. dentry = dget(bprm->file->f_dentry);
  218. inode = dentry->d_inode;
  219. if (!inode->i_op || !inode->i_op->getxattr)
  220. goto out;
  221. rc = inode->i_op->getxattr(dentry, XATTR_NAME_CAPS, &vcaps,
  222. XATTR_CAPS_SZ);
  223. if (rc == -ENODATA || rc == -EOPNOTSUPP) {
  224. /* no data, that's ok */
  225. rc = 0;
  226. goto out;
  227. }
  228. if (rc < 0)
  229. goto out;
  230. rc = cap_from_disk(&vcaps, bprm, rc);
  231. if (rc)
  232. printk(KERN_NOTICE "%s: cap_from_disk returned %d for %s\n",
  233. __func__, rc, bprm->filename);
  234. out:
  235. dput(dentry);
  236. if (rc)
  237. bprm_clear_caps(bprm);
  238. return rc;
  239. }
  240. #else
  241. int cap_inode_need_killpriv(struct dentry *dentry)
  242. {
  243. return 0;
  244. }
  245. int cap_inode_killpriv(struct dentry *dentry)
  246. {
  247. return 0;
  248. }
  249. static inline int get_file_caps(struct linux_binprm *bprm)
  250. {
  251. bprm_clear_caps(bprm);
  252. return 0;
  253. }
  254. #endif
  255. int cap_bprm_set_security (struct linux_binprm *bprm)
  256. {
  257. int ret;
  258. ret = get_file_caps(bprm);
  259. if (ret)
  260. printk(KERN_NOTICE "%s: get_file_caps returned %d for %s\n",
  261. __func__, ret, bprm->filename);
  262. /* To support inheritance of root-permissions and suid-root
  263. * executables under compatibility mode, we raise all three
  264. * capability sets for the file.
  265. *
  266. * If only the real uid is 0, we only raise the inheritable
  267. * and permitted sets of the executable file.
  268. */
  269. if (!issecure (SECURE_NOROOT)) {
  270. if (bprm->e_uid == 0 || current->uid == 0) {
  271. cap_set_full (bprm->cap_inheritable);
  272. cap_set_full (bprm->cap_permitted);
  273. }
  274. if (bprm->e_uid == 0)
  275. bprm->cap_effective = true;
  276. }
  277. return ret;
  278. }
  279. void cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
  280. {
  281. /* Derived from fs/exec.c:compute_creds. */
  282. kernel_cap_t new_permitted, working;
  283. new_permitted = cap_intersect(bprm->cap_permitted,
  284. current->cap_bset);
  285. working = cap_intersect(bprm->cap_inheritable,
  286. current->cap_inheritable);
  287. new_permitted = cap_combine(new_permitted, working);
  288. if (bprm->e_uid != current->uid || bprm->e_gid != current->gid ||
  289. !cap_issubset (new_permitted, current->cap_permitted)) {
  290. set_dumpable(current->mm, suid_dumpable);
  291. current->pdeath_signal = 0;
  292. if (unsafe & ~LSM_UNSAFE_PTRACE_CAP) {
  293. if (!capable(CAP_SETUID)) {
  294. bprm->e_uid = current->uid;
  295. bprm->e_gid = current->gid;
  296. }
  297. if (cap_limit_ptraced_target()) {
  298. new_permitted =
  299. cap_intersect(new_permitted,
  300. current->cap_permitted);
  301. }
  302. }
  303. }
  304. current->suid = current->euid = current->fsuid = bprm->e_uid;
  305. current->sgid = current->egid = current->fsgid = bprm->e_gid;
  306. /* For init, we want to retain the capabilities set
  307. * in the init_task struct. Thus we skip the usual
  308. * capability rules */
  309. if (!is_global_init(current)) {
  310. current->cap_permitted = new_permitted;
  311. if (bprm->cap_effective)
  312. current->cap_effective = new_permitted;
  313. else
  314. cap_clear(current->cap_effective);
  315. }
  316. /* AUD: Audit candidate if current->cap_effective is set */
  317. current->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);
  318. }
  319. int cap_bprm_secureexec (struct linux_binprm *bprm)
  320. {
  321. if (current->uid != 0) {
  322. if (bprm->cap_effective)
  323. return 1;
  324. if (!cap_isclear(bprm->cap_permitted))
  325. return 1;
  326. if (!cap_isclear(bprm->cap_inheritable))
  327. return 1;
  328. }
  329. return (current->euid != current->uid ||
  330. current->egid != current->gid);
  331. }
  332. int cap_inode_setxattr(struct dentry *dentry, const char *name,
  333. const void *value, size_t size, int flags)
  334. {
  335. if (!strcmp(name, XATTR_NAME_CAPS)) {
  336. if (!capable(CAP_SETFCAP))
  337. return -EPERM;
  338. return 0;
  339. } else if (!strncmp(name, XATTR_SECURITY_PREFIX,
  340. sizeof(XATTR_SECURITY_PREFIX) - 1) &&
  341. !capable(CAP_SYS_ADMIN))
  342. return -EPERM;
  343. return 0;
  344. }
  345. int cap_inode_removexattr(struct dentry *dentry, const char *name)
  346. {
  347. if (!strcmp(name, XATTR_NAME_CAPS)) {
  348. if (!capable(CAP_SETFCAP))
  349. return -EPERM;
  350. return 0;
  351. } else if (!strncmp(name, XATTR_SECURITY_PREFIX,
  352. sizeof(XATTR_SECURITY_PREFIX) - 1) &&
  353. !capable(CAP_SYS_ADMIN))
  354. return -EPERM;
  355. return 0;
  356. }
  357. /* moved from kernel/sys.c. */
  358. /*
  359. * cap_emulate_setxuid() fixes the effective / permitted capabilities of
  360. * a process after a call to setuid, setreuid, or setresuid.
  361. *
  362. * 1) When set*uiding _from_ one of {r,e,s}uid == 0 _to_ all of
  363. * {r,e,s}uid != 0, the permitted and effective capabilities are
  364. * cleared.
  365. *
  366. * 2) When set*uiding _from_ euid == 0 _to_ euid != 0, the effective
  367. * capabilities of the process are cleared.
  368. *
  369. * 3) When set*uiding _from_ euid != 0 _to_ euid == 0, the effective
  370. * capabilities are set to the permitted capabilities.
  371. *
  372. * fsuid is handled elsewhere. fsuid == 0 and {r,e,s}uid!= 0 should
  373. * never happen.
  374. *
  375. * -astor
  376. *
  377. * cevans - New behaviour, Oct '99
  378. * A process may, via prctl(), elect to keep its capabilities when it
  379. * calls setuid() and switches away from uid==0. Both permitted and
  380. * effective sets will be retained.
  381. * Without this change, it was impossible for a daemon to drop only some
  382. * of its privilege. The call to setuid(!=0) would drop all privileges!
  383. * Keeping uid 0 is not an option because uid 0 owns too many vital
  384. * files..
  385. * Thanks to Olaf Kirch and Peter Benie for spotting this.
  386. */
  387. static inline void cap_emulate_setxuid (int old_ruid, int old_euid,
  388. int old_suid)
  389. {
  390. if ((old_ruid == 0 || old_euid == 0 || old_suid == 0) &&
  391. (current->uid != 0 && current->euid != 0 && current->suid != 0) &&
  392. !issecure(SECURE_KEEP_CAPS)) {
  393. cap_clear (current->cap_permitted);
  394. cap_clear (current->cap_effective);
  395. }
  396. if (old_euid == 0 && current->euid != 0) {
  397. cap_clear (current->cap_effective);
  398. }
  399. if (old_euid != 0 && current->euid == 0) {
  400. current->cap_effective = current->cap_permitted;
  401. }
  402. }
  403. int cap_task_post_setuid (uid_t old_ruid, uid_t old_euid, uid_t old_suid,
  404. int flags)
  405. {
  406. switch (flags) {
  407. case LSM_SETID_RE:
  408. case LSM_SETID_ID:
  409. case LSM_SETID_RES:
  410. /* Copied from kernel/sys.c:setreuid/setuid/setresuid. */
  411. if (!issecure (SECURE_NO_SETUID_FIXUP)) {
  412. cap_emulate_setxuid (old_ruid, old_euid, old_suid);
  413. }
  414. break;
  415. case LSM_SETID_FS:
  416. {
  417. uid_t old_fsuid = old_ruid;
  418. /* Copied from kernel/sys.c:setfsuid. */
  419. /*
  420. * FIXME - is fsuser used for all CAP_FS_MASK capabilities?
  421. * if not, we might be a bit too harsh here.
  422. */
  423. if (!issecure (SECURE_NO_SETUID_FIXUP)) {
  424. if (old_fsuid == 0 && current->fsuid != 0) {
  425. current->cap_effective =
  426. cap_drop_fs_set(
  427. current->cap_effective);
  428. }
  429. if (old_fsuid != 0 && current->fsuid == 0) {
  430. current->cap_effective =
  431. cap_raise_fs_set(
  432. current->cap_effective,
  433. current->cap_permitted);
  434. }
  435. }
  436. break;
  437. }
  438. default:
  439. return -EINVAL;
  440. }
  441. return 0;
  442. }
  443. #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
  444. /*
  445. * Rationale: code calling task_setscheduler, task_setioprio, and
  446. * task_setnice, assumes that
  447. * . if capable(cap_sys_nice), then those actions should be allowed
  448. * . if not capable(cap_sys_nice), but acting on your own processes,
  449. * then those actions should be allowed
  450. * This is insufficient now since you can call code without suid, but
  451. * yet with increased caps.
  452. * So we check for increased caps on the target process.
  453. */
  454. static inline int cap_safe_nice(struct task_struct *p)
  455. {
  456. if (!cap_issubset(p->cap_permitted, current->cap_permitted) &&
  457. !__capable(current, CAP_SYS_NICE))
  458. return -EPERM;
  459. return 0;
  460. }
  461. int cap_task_setscheduler (struct task_struct *p, int policy,
  462. struct sched_param *lp)
  463. {
  464. return cap_safe_nice(p);
  465. }
  466. int cap_task_setioprio (struct task_struct *p, int ioprio)
  467. {
  468. return cap_safe_nice(p);
  469. }
  470. int cap_task_setnice (struct task_struct *p, int nice)
  471. {
  472. return cap_safe_nice(p);
  473. }
  474. /*
  475. * called from kernel/sys.c for prctl(PR_CABSET_DROP)
  476. * done without task_capability_lock() because it introduces
  477. * no new races - i.e. only another task doing capget() on
  478. * this task could get inconsistent info. There can be no
  479. * racing writer bc a task can only change its own caps.
  480. */
  481. static long cap_prctl_drop(unsigned long cap)
  482. {
  483. if (!capable(CAP_SETPCAP))
  484. return -EPERM;
  485. if (!cap_valid(cap))
  486. return -EINVAL;
  487. cap_lower(current->cap_bset, cap);
  488. return 0;
  489. }
  490. #else
  491. int cap_task_setscheduler (struct task_struct *p, int policy,
  492. struct sched_param *lp)
  493. {
  494. return 0;
  495. }
  496. int cap_task_setioprio (struct task_struct *p, int ioprio)
  497. {
  498. return 0;
  499. }
  500. int cap_task_setnice (struct task_struct *p, int nice)
  501. {
  502. return 0;
  503. }
  504. #endif
  505. int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
  506. unsigned long arg4, unsigned long arg5, long *rc_p)
  507. {
  508. long error = 0;
  509. switch (option) {
  510. case PR_CAPBSET_READ:
  511. if (!cap_valid(arg2))
  512. error = -EINVAL;
  513. else
  514. error = !!cap_raised(current->cap_bset, arg2);
  515. break;
  516. #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
  517. case PR_CAPBSET_DROP:
  518. error = cap_prctl_drop(arg2);
  519. break;
  520. /*
  521. * The next four prctl's remain to assist with transitioning a
  522. * system from legacy UID=0 based privilege (when filesystem
  523. * capabilities are not in use) to a system using filesystem
  524. * capabilities only - as the POSIX.1e draft intended.
  525. *
  526. * Note:
  527. *
  528. * PR_SET_SECUREBITS =
  529. * issecure_mask(SECURE_KEEP_CAPS_LOCKED)
  530. * | issecure_mask(SECURE_NOROOT)
  531. * | issecure_mask(SECURE_NOROOT_LOCKED)
  532. * | issecure_mask(SECURE_NO_SETUID_FIXUP)
  533. * | issecure_mask(SECURE_NO_SETUID_FIXUP_LOCKED)
  534. *
  535. * will ensure that the current process and all of its
  536. * children will be locked into a pure
  537. * capability-based-privilege environment.
  538. */
  539. case PR_SET_SECUREBITS:
  540. if ((((current->securebits & SECURE_ALL_LOCKS) >> 1)
  541. & (current->securebits ^ arg2)) /*[1]*/
  542. || ((current->securebits & SECURE_ALL_LOCKS
  543. & ~arg2)) /*[2]*/
  544. || (arg2 & ~(SECURE_ALL_LOCKS | SECURE_ALL_BITS)) /*[3]*/
  545. || (cap_capable(current, CAP_SETPCAP) != 0)) { /*[4]*/
  546. /*
  547. * [1] no changing of bits that are locked
  548. * [2] no unlocking of locks
  549. * [3] no setting of unsupported bits
  550. * [4] doing anything requires privilege (go read about
  551. * the "sendmail capabilities bug")
  552. */
  553. error = -EPERM; /* cannot change a locked bit */
  554. } else {
  555. current->securebits = arg2;
  556. }
  557. break;
  558. case PR_GET_SECUREBITS:
  559. error = current->securebits;
  560. break;
  561. #endif /* def CONFIG_SECURITY_FILE_CAPABILITIES */
  562. case PR_GET_KEEPCAPS:
  563. if (issecure(SECURE_KEEP_CAPS))
  564. error = 1;
  565. break;
  566. case PR_SET_KEEPCAPS:
  567. if (arg2 > 1) /* Note, we rely on arg2 being unsigned here */
  568. error = -EINVAL;
  569. else if (issecure(SECURE_KEEP_CAPS_LOCKED))
  570. error = -EPERM;
  571. else if (arg2)
  572. current->securebits |= issecure_mask(SECURE_KEEP_CAPS);
  573. else
  574. current->securebits &=
  575. ~issecure_mask(SECURE_KEEP_CAPS);
  576. break;
  577. default:
  578. /* No functionality available - continue with default */
  579. return 0;
  580. }
  581. /* Functionality provided */
  582. *rc_p = error;
  583. return 1;
  584. }
  585. void cap_task_reparent_to_init (struct task_struct *p)
  586. {
  587. cap_set_init_eff(p->cap_effective);
  588. cap_clear(p->cap_inheritable);
  589. cap_set_full(p->cap_permitted);
  590. p->securebits = SECUREBITS_DEFAULT;
  591. return;
  592. }
  593. int cap_syslog (int type)
  594. {
  595. if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
  596. return -EPERM;
  597. return 0;
  598. }
  599. int cap_vm_enough_memory(struct mm_struct *mm, long pages)
  600. {
  601. int cap_sys_admin = 0;
  602. if (cap_capable(current, CAP_SYS_ADMIN) == 0)
  603. cap_sys_admin = 1;
  604. return __vm_enough_memory(mm, pages, cap_sys_admin);
  605. }