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. if (bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID) {
  243. bprm_clear_caps(bprm);
  244. return 0;
  245. }
  246. dentry = dget(bprm->file->f_dentry);
  247. inode = dentry->d_inode;
  248. if (!inode->i_op || !inode->i_op->getxattr)
  249. goto out;
  250. rc = inode->i_op->getxattr(dentry, XATTR_NAME_CAPS, &vcaps,
  251. XATTR_CAPS_SZ);
  252. if (rc == -ENODATA || rc == -EOPNOTSUPP) {
  253. /* no data, that's ok */
  254. rc = 0;
  255. goto out;
  256. }
  257. if (rc < 0)
  258. goto out;
  259. rc = cap_from_disk(&vcaps, bprm, rc);
  260. if (rc == -EINVAL)
  261. printk(KERN_NOTICE "%s: cap_from_disk returned %d for %s\n",
  262. __func__, rc, bprm->filename);
  263. out:
  264. dput(dentry);
  265. if (rc)
  266. bprm_clear_caps(bprm);
  267. return rc;
  268. }
  269. #else
  270. int cap_inode_need_killpriv(struct dentry *dentry)
  271. {
  272. return 0;
  273. }
  274. int cap_inode_killpriv(struct dentry *dentry)
  275. {
  276. return 0;
  277. }
  278. static inline int get_file_caps(struct linux_binprm *bprm)
  279. {
  280. bprm_clear_caps(bprm);
  281. return 0;
  282. }
  283. #endif
  284. int cap_bprm_set_security (struct linux_binprm *bprm)
  285. {
  286. int ret;
  287. ret = get_file_caps(bprm);
  288. if (!issecure(SECURE_NOROOT)) {
  289. /*
  290. * To support inheritance of root-permissions and suid-root
  291. * executables under compatibility mode, we override the
  292. * capability sets for the file.
  293. *
  294. * If only the real uid is 0, we do not set the effective
  295. * bit.
  296. */
  297. if (bprm->e_uid == 0 || current->uid == 0) {
  298. /* pP' = (cap_bset & ~0) | (pI & ~0) */
  299. bprm->cap_post_exec_permitted = cap_combine(
  300. current->cap_bset, current->cap_inheritable
  301. );
  302. bprm->cap_effective = (bprm->e_uid == 0);
  303. ret = 0;
  304. }
  305. }
  306. return ret;
  307. }
  308. void cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
  309. {
  310. if (bprm->e_uid != current->uid || bprm->e_gid != current->gid ||
  311. !cap_issubset(bprm->cap_post_exec_permitted,
  312. current->cap_permitted)) {
  313. set_dumpable(current->mm, suid_dumpable);
  314. current->pdeath_signal = 0;
  315. if (unsafe & ~LSM_UNSAFE_PTRACE_CAP) {
  316. if (!capable(CAP_SETUID)) {
  317. bprm->e_uid = current->uid;
  318. bprm->e_gid = current->gid;
  319. }
  320. if (cap_limit_ptraced_target()) {
  321. bprm->cap_post_exec_permitted = cap_intersect(
  322. bprm->cap_post_exec_permitted,
  323. current->cap_permitted);
  324. }
  325. }
  326. }
  327. current->suid = current->euid = current->fsuid = bprm->e_uid;
  328. current->sgid = current->egid = current->fsgid = bprm->e_gid;
  329. /* For init, we want to retain the capabilities set
  330. * in the init_task struct. Thus we skip the usual
  331. * capability rules */
  332. if (!is_global_init(current)) {
  333. current->cap_permitted = bprm->cap_post_exec_permitted;
  334. if (bprm->cap_effective)
  335. current->cap_effective = bprm->cap_post_exec_permitted;
  336. else
  337. cap_clear(current->cap_effective);
  338. }
  339. /* AUD: Audit candidate if current->cap_effective is set */
  340. current->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);
  341. }
  342. int cap_bprm_secureexec (struct linux_binprm *bprm)
  343. {
  344. if (current->uid != 0) {
  345. if (bprm->cap_effective)
  346. return 1;
  347. if (!cap_isclear(bprm->cap_post_exec_permitted))
  348. return 1;
  349. }
  350. return (current->euid != current->uid ||
  351. current->egid != current->gid);
  352. }
  353. int cap_inode_setxattr(struct dentry *dentry, const char *name,
  354. const void *value, size_t size, int flags)
  355. {
  356. if (!strcmp(name, XATTR_NAME_CAPS)) {
  357. if (!capable(CAP_SETFCAP))
  358. return -EPERM;
  359. return 0;
  360. } else if (!strncmp(name, XATTR_SECURITY_PREFIX,
  361. sizeof(XATTR_SECURITY_PREFIX) - 1) &&
  362. !capable(CAP_SYS_ADMIN))
  363. return -EPERM;
  364. return 0;
  365. }
  366. int cap_inode_removexattr(struct dentry *dentry, const char *name)
  367. {
  368. if (!strcmp(name, XATTR_NAME_CAPS)) {
  369. if (!capable(CAP_SETFCAP))
  370. return -EPERM;
  371. return 0;
  372. } else if (!strncmp(name, XATTR_SECURITY_PREFIX,
  373. sizeof(XATTR_SECURITY_PREFIX) - 1) &&
  374. !capable(CAP_SYS_ADMIN))
  375. return -EPERM;
  376. return 0;
  377. }
  378. /* moved from kernel/sys.c. */
  379. /*
  380. * cap_emulate_setxuid() fixes the effective / permitted capabilities of
  381. * a process after a call to setuid, setreuid, or setresuid.
  382. *
  383. * 1) When set*uiding _from_ one of {r,e,s}uid == 0 _to_ all of
  384. * {r,e,s}uid != 0, the permitted and effective capabilities are
  385. * cleared.
  386. *
  387. * 2) When set*uiding _from_ euid == 0 _to_ euid != 0, the effective
  388. * capabilities of the process are cleared.
  389. *
  390. * 3) When set*uiding _from_ euid != 0 _to_ euid == 0, the effective
  391. * capabilities are set to the permitted capabilities.
  392. *
  393. * fsuid is handled elsewhere. fsuid == 0 and {r,e,s}uid!= 0 should
  394. * never happen.
  395. *
  396. * -astor
  397. *
  398. * cevans - New behaviour, Oct '99
  399. * A process may, via prctl(), elect to keep its capabilities when it
  400. * calls setuid() and switches away from uid==0. Both permitted and
  401. * effective sets will be retained.
  402. * Without this change, it was impossible for a daemon to drop only some
  403. * of its privilege. The call to setuid(!=0) would drop all privileges!
  404. * Keeping uid 0 is not an option because uid 0 owns too many vital
  405. * files..
  406. * Thanks to Olaf Kirch and Peter Benie for spotting this.
  407. */
  408. static inline void cap_emulate_setxuid (int old_ruid, int old_euid,
  409. int old_suid)
  410. {
  411. if ((old_ruid == 0 || old_euid == 0 || old_suid == 0) &&
  412. (current->uid != 0 && current->euid != 0 && current->suid != 0) &&
  413. !issecure(SECURE_KEEP_CAPS)) {
  414. cap_clear (current->cap_permitted);
  415. cap_clear (current->cap_effective);
  416. }
  417. if (old_euid == 0 && current->euid != 0) {
  418. cap_clear (current->cap_effective);
  419. }
  420. if (old_euid != 0 && current->euid == 0) {
  421. current->cap_effective = current->cap_permitted;
  422. }
  423. }
  424. int cap_task_post_setuid (uid_t old_ruid, uid_t old_euid, uid_t old_suid,
  425. int flags)
  426. {
  427. switch (flags) {
  428. case LSM_SETID_RE:
  429. case LSM_SETID_ID:
  430. case LSM_SETID_RES:
  431. /* Copied from kernel/sys.c:setreuid/setuid/setresuid. */
  432. if (!issecure (SECURE_NO_SETUID_FIXUP)) {
  433. cap_emulate_setxuid (old_ruid, old_euid, old_suid);
  434. }
  435. break;
  436. case LSM_SETID_FS:
  437. {
  438. uid_t old_fsuid = old_ruid;
  439. /* Copied from kernel/sys.c:setfsuid. */
  440. /*
  441. * FIXME - is fsuser used for all CAP_FS_MASK capabilities?
  442. * if not, we might be a bit too harsh here.
  443. */
  444. if (!issecure (SECURE_NO_SETUID_FIXUP)) {
  445. if (old_fsuid == 0 && current->fsuid != 0) {
  446. current->cap_effective =
  447. cap_drop_fs_set(
  448. current->cap_effective);
  449. }
  450. if (old_fsuid != 0 && current->fsuid == 0) {
  451. current->cap_effective =
  452. cap_raise_fs_set(
  453. current->cap_effective,
  454. current->cap_permitted);
  455. }
  456. }
  457. break;
  458. }
  459. default:
  460. return -EINVAL;
  461. }
  462. return 0;
  463. }
  464. #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
  465. /*
  466. * Rationale: code calling task_setscheduler, task_setioprio, and
  467. * task_setnice, assumes that
  468. * . if capable(cap_sys_nice), then those actions should be allowed
  469. * . if not capable(cap_sys_nice), but acting on your own processes,
  470. * then those actions should be allowed
  471. * This is insufficient now since you can call code without suid, but
  472. * yet with increased caps.
  473. * So we check for increased caps on the target process.
  474. */
  475. static inline int cap_safe_nice(struct task_struct *p)
  476. {
  477. if (!cap_issubset(p->cap_permitted, current->cap_permitted) &&
  478. !capable(CAP_SYS_NICE))
  479. return -EPERM;
  480. return 0;
  481. }
  482. int cap_task_setscheduler (struct task_struct *p, int policy,
  483. struct sched_param *lp)
  484. {
  485. return cap_safe_nice(p);
  486. }
  487. int cap_task_setioprio (struct task_struct *p, int ioprio)
  488. {
  489. return cap_safe_nice(p);
  490. }
  491. int cap_task_setnice (struct task_struct *p, int nice)
  492. {
  493. return cap_safe_nice(p);
  494. }
  495. /*
  496. * called from kernel/sys.c for prctl(PR_CABSET_DROP)
  497. * done without task_capability_lock() because it introduces
  498. * no new races - i.e. only another task doing capget() on
  499. * this task could get inconsistent info. There can be no
  500. * racing writer bc a task can only change its own caps.
  501. */
  502. static long cap_prctl_drop(unsigned long cap)
  503. {
  504. if (!capable(CAP_SETPCAP))
  505. return -EPERM;
  506. if (!cap_valid(cap))
  507. return -EINVAL;
  508. cap_lower(current->cap_bset, cap);
  509. return 0;
  510. }
  511. #else
  512. int cap_task_setscheduler (struct task_struct *p, int policy,
  513. struct sched_param *lp)
  514. {
  515. return 0;
  516. }
  517. int cap_task_setioprio (struct task_struct *p, int ioprio)
  518. {
  519. return 0;
  520. }
  521. int cap_task_setnice (struct task_struct *p, int nice)
  522. {
  523. return 0;
  524. }
  525. #endif
  526. int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
  527. unsigned long arg4, unsigned long arg5, long *rc_p)
  528. {
  529. long error = 0;
  530. switch (option) {
  531. case PR_CAPBSET_READ:
  532. if (!cap_valid(arg2))
  533. error = -EINVAL;
  534. else
  535. error = !!cap_raised(current->cap_bset, arg2);
  536. break;
  537. #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
  538. case PR_CAPBSET_DROP:
  539. error = cap_prctl_drop(arg2);
  540. break;
  541. /*
  542. * The next four prctl's remain to assist with transitioning a
  543. * system from legacy UID=0 based privilege (when filesystem
  544. * capabilities are not in use) to a system using filesystem
  545. * capabilities only - as the POSIX.1e draft intended.
  546. *
  547. * Note:
  548. *
  549. * PR_SET_SECUREBITS =
  550. * issecure_mask(SECURE_KEEP_CAPS_LOCKED)
  551. * | issecure_mask(SECURE_NOROOT)
  552. * | issecure_mask(SECURE_NOROOT_LOCKED)
  553. * | issecure_mask(SECURE_NO_SETUID_FIXUP)
  554. * | issecure_mask(SECURE_NO_SETUID_FIXUP_LOCKED)
  555. *
  556. * will ensure that the current process and all of its
  557. * children will be locked into a pure
  558. * capability-based-privilege environment.
  559. */
  560. case PR_SET_SECUREBITS:
  561. if ((((current->securebits & SECURE_ALL_LOCKS) >> 1)
  562. & (current->securebits ^ arg2)) /*[1]*/
  563. || ((current->securebits & SECURE_ALL_LOCKS
  564. & ~arg2)) /*[2]*/
  565. || (arg2 & ~(SECURE_ALL_LOCKS | SECURE_ALL_BITS)) /*[3]*/
  566. || (cap_capable(current, CAP_SETPCAP) != 0)) { /*[4]*/
  567. /*
  568. * [1] no changing of bits that are locked
  569. * [2] no unlocking of locks
  570. * [3] no setting of unsupported bits
  571. * [4] doing anything requires privilege (go read about
  572. * the "sendmail capabilities bug")
  573. */
  574. error = -EPERM; /* cannot change a locked bit */
  575. } else {
  576. current->securebits = arg2;
  577. }
  578. break;
  579. case PR_GET_SECUREBITS:
  580. error = current->securebits;
  581. break;
  582. #endif /* def CONFIG_SECURITY_FILE_CAPABILITIES */
  583. case PR_GET_KEEPCAPS:
  584. if (issecure(SECURE_KEEP_CAPS))
  585. error = 1;
  586. break;
  587. case PR_SET_KEEPCAPS:
  588. if (arg2 > 1) /* Note, we rely on arg2 being unsigned here */
  589. error = -EINVAL;
  590. else if (issecure(SECURE_KEEP_CAPS_LOCKED))
  591. error = -EPERM;
  592. else if (arg2)
  593. current->securebits |= issecure_mask(SECURE_KEEP_CAPS);
  594. else
  595. current->securebits &=
  596. ~issecure_mask(SECURE_KEEP_CAPS);
  597. break;
  598. default:
  599. /* No functionality available - continue with default */
  600. return 0;
  601. }
  602. /* Functionality provided */
  603. *rc_p = error;
  604. return 1;
  605. }
  606. void cap_task_reparent_to_init (struct task_struct *p)
  607. {
  608. cap_set_init_eff(p->cap_effective);
  609. cap_clear(p->cap_inheritable);
  610. cap_set_full(p->cap_permitted);
  611. p->securebits = SECUREBITS_DEFAULT;
  612. return;
  613. }
  614. int cap_syslog (int type)
  615. {
  616. if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
  617. return -EPERM;
  618. return 0;
  619. }
  620. int cap_vm_enough_memory(struct mm_struct *mm, long pages)
  621. {
  622. int cap_sys_admin = 0;
  623. if (cap_capable(current, CAP_SYS_ADMIN) == 0)
  624. cap_sys_admin = 1;
  625. return __vm_enough_memory(mm, pages, cap_sys_admin);
  626. }