commoncap.c 17 KB

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