commoncap.c 17 KB

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