commoncap.c 18 KB

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