commoncap.c 17 KB

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