CRED: Inaugurate COW credentials
[safe/jmp/linux-2.6] / security / commoncap.c
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
10 #include <linux/capability.h>
11 #include <linux/audit.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/security.h>
16 #include <linux/file.h>
17 #include <linux/mm.h>
18 #include <linux/mman.h>
19 #include <linux/pagemap.h>
20 #include <linux/swap.h>
21 #include <linux/skbuff.h>
22 #include <linux/netlink.h>
23 #include <linux/ptrace.h>
24 #include <linux/xattr.h>
25 #include <linux/hugetlb.h>
26 #include <linux/mount.h>
27 #include <linux/sched.h>
28 #include <linux/prctl.h>
29 #include <linux/securebits.h>
30
31 int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
32 {
33         NETLINK_CB(skb).eff_cap = current_cap();
34         return 0;
35 }
36
37 int cap_netlink_recv(struct sk_buff *skb, int cap)
38 {
39         if (!cap_raised(NETLINK_CB(skb).eff_cap, cap))
40                 return -EPERM;
41         return 0;
42 }
43
44 EXPORT_SYMBOL(cap_netlink_recv);
45
46 /*
47  * NOTE WELL: cap_capable() cannot be used like the kernel's capable()
48  * function.  That is, it has the reverse semantics: cap_capable()
49  * returns 0 when a task has a capability, but the kernel's capable()
50  * returns 1 for this case.
51  */
52 int cap_capable(struct task_struct *tsk, int cap, int audit)
53 {
54         __u32 cap_raised;
55
56         /* Derived from include/linux/sched.h:capable. */
57         rcu_read_lock();
58         cap_raised = cap_raised(__task_cred(tsk)->cap_effective, cap);
59         rcu_read_unlock();
60         return cap_raised ? 0 : -EPERM;
61 }
62
63 int cap_settime(struct timespec *ts, struct timezone *tz)
64 {
65         if (!capable(CAP_SYS_TIME))
66                 return -EPERM;
67         return 0;
68 }
69
70 int cap_ptrace_may_access(struct task_struct *child, unsigned int mode)
71 {
72         int ret = 0;
73
74         rcu_read_lock();
75         if (!cap_issubset(__task_cred(child)->cap_permitted,
76                           current_cred()->cap_permitted) &&
77             !capable(CAP_SYS_PTRACE))
78                 ret = -EPERM;
79         rcu_read_unlock();
80         return ret;
81 }
82
83 int cap_ptrace_traceme(struct task_struct *parent)
84 {
85         int ret = 0;
86
87         rcu_read_lock();
88         if (!cap_issubset(current_cred()->cap_permitted,
89                           __task_cred(parent)->cap_permitted) &&
90             !has_capability(parent, CAP_SYS_PTRACE))
91                 ret = -EPERM;
92         rcu_read_unlock();
93         return ret;
94 }
95
96 int cap_capget (struct task_struct *target, kernel_cap_t *effective,
97                 kernel_cap_t *inheritable, kernel_cap_t *permitted)
98 {
99         const struct cred *cred;
100
101         /* Derived from kernel/capability.c:sys_capget. */
102         rcu_read_lock();
103         cred = __task_cred(target);
104         *effective   = cred->cap_effective;
105         *inheritable = cred->cap_inheritable;
106         *permitted   = cred->cap_permitted;
107         rcu_read_unlock();
108         return 0;
109 }
110
111 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
112
113 static inline int cap_inh_is_capped(void)
114 {
115         /*
116          * Return 1 if changes to the inheritable set are limited
117          * to the old permitted set. That is, if the current task
118          * does *not* possess the CAP_SETPCAP capability.
119          */
120         return cap_capable(current, CAP_SETPCAP, SECURITY_CAP_AUDIT) != 0;
121 }
122
123 static inline int cap_limit_ptraced_target(void) { return 1; }
124
125 #else /* ie., ndef CONFIG_SECURITY_FILE_CAPABILITIES */
126
127 static inline int cap_inh_is_capped(void) { return 1; }
128 static inline int cap_limit_ptraced_target(void)
129 {
130         return !capable(CAP_SETPCAP);
131 }
132
133 #endif /* def CONFIG_SECURITY_FILE_CAPABILITIES */
134
135 int cap_capset(struct cred *new,
136                const struct cred *old,
137                const kernel_cap_t *effective,
138                const kernel_cap_t *inheritable,
139                const kernel_cap_t *permitted)
140 {
141         if (cap_inh_is_capped() &&
142             !cap_issubset(*inheritable,
143                           cap_combine(old->cap_inheritable,
144                                       old->cap_permitted)))
145                 /* incapable of using this inheritable set */
146                 return -EPERM;
147
148         if (!cap_issubset(*inheritable,
149                           cap_combine(old->cap_inheritable,
150                                       old->cap_bset)))
151                 /* no new pI capabilities outside bounding set */
152                 return -EPERM;
153
154         /* verify restrictions on target's new Permitted set */
155         if (!cap_issubset(*permitted, old->cap_permitted))
156                 return -EPERM;
157
158         /* verify the _new_Effective_ is a subset of the _new_Permitted_ */
159         if (!cap_issubset(*effective, *permitted))
160                 return -EPERM;
161
162         new->cap_effective   = *effective;
163         new->cap_inheritable = *inheritable;
164         new->cap_permitted   = *permitted;
165         return 0;
166 }
167
168 static inline void bprm_clear_caps(struct linux_binprm *bprm)
169 {
170         cap_clear(bprm->cap_post_exec_permitted);
171         bprm->cap_effective = false;
172 }
173
174 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
175
176 int cap_inode_need_killpriv(struct dentry *dentry)
177 {
178         struct inode *inode = dentry->d_inode;
179         int error;
180
181         if (!inode->i_op || !inode->i_op->getxattr)
182                return 0;
183
184         error = inode->i_op->getxattr(dentry, XATTR_NAME_CAPS, NULL, 0);
185         if (error <= 0)
186                 return 0;
187         return 1;
188 }
189
190 int cap_inode_killpriv(struct dentry *dentry)
191 {
192         struct inode *inode = dentry->d_inode;
193
194         if (!inode->i_op || !inode->i_op->removexattr)
195                return 0;
196
197         return inode->i_op->removexattr(dentry, XATTR_NAME_CAPS);
198 }
199
200 static inline int bprm_caps_from_vfs_caps(struct cpu_vfs_cap_data *caps,
201                                           struct linux_binprm *bprm)
202 {
203         unsigned i;
204         int ret = 0;
205
206         if (caps->magic_etc & VFS_CAP_FLAGS_EFFECTIVE)
207                 bprm->cap_effective = true;
208         else
209                 bprm->cap_effective = false;
210
211         CAP_FOR_EACH_U32(i) {
212                 __u32 permitted = caps->permitted.cap[i];
213                 __u32 inheritable = caps->inheritable.cap[i];
214
215                 /*
216                  * pP' = (X & fP) | (pI & fI)
217                  */
218                 bprm->cap_post_exec_permitted.cap[i] =
219                         (current->cred->cap_bset.cap[i] & permitted) |
220                         (current->cred->cap_inheritable.cap[i] & inheritable);
221
222                 if (permitted & ~bprm->cap_post_exec_permitted.cap[i]) {
223                         /*
224                          * insufficient to execute correctly
225                          */
226                         ret = -EPERM;
227                 }
228         }
229
230         /*
231          * For legacy apps, with no internal support for recognizing they
232          * do not have enough capabilities, we return an error if they are
233          * missing some "forced" (aka file-permitted) capabilities.
234          */
235         return bprm->cap_effective ? ret : 0;
236 }
237
238 int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps)
239 {
240         struct inode *inode = dentry->d_inode;
241         __u32 magic_etc;
242         unsigned tocopy, i;
243         int size;
244         struct vfs_cap_data caps;
245
246         memset(cpu_caps, 0, sizeof(struct cpu_vfs_cap_data));
247
248         if (!inode || !inode->i_op || !inode->i_op->getxattr)
249                 return -ENODATA;
250
251         size = inode->i_op->getxattr((struct dentry *)dentry, XATTR_NAME_CAPS, &caps,
252                                    XATTR_CAPS_SZ);
253         if (size == -ENODATA || size == -EOPNOTSUPP) {
254                 /* no data, that's ok */
255                 return -ENODATA;
256         }
257         if (size < 0)
258                 return size;
259
260         if (size < sizeof(magic_etc))
261                 return -EINVAL;
262
263         cpu_caps->magic_etc = magic_etc = le32_to_cpu(caps.magic_etc);
264
265         switch ((magic_etc & VFS_CAP_REVISION_MASK)) {
266         case VFS_CAP_REVISION_1:
267                 if (size != XATTR_CAPS_SZ_1)
268                         return -EINVAL;
269                 tocopy = VFS_CAP_U32_1;
270                 break;
271         case VFS_CAP_REVISION_2:
272                 if (size != XATTR_CAPS_SZ_2)
273                         return -EINVAL;
274                 tocopy = VFS_CAP_U32_2;
275                 break;
276         default:
277                 return -EINVAL;
278         }
279
280         CAP_FOR_EACH_U32(i) {
281                 if (i >= tocopy)
282                         break;
283                 cpu_caps->permitted.cap[i] = le32_to_cpu(caps.data[i].permitted);
284                 cpu_caps->inheritable.cap[i] = le32_to_cpu(caps.data[i].inheritable);
285         }
286         return 0;
287 }
288
289 /* Locate any VFS capabilities: */
290 static int get_file_caps(struct linux_binprm *bprm)
291 {
292         struct dentry *dentry;
293         int rc = 0;
294         struct cpu_vfs_cap_data vcaps;
295
296         bprm_clear_caps(bprm);
297
298         if (!file_caps_enabled)
299                 return 0;
300
301         if (bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID)
302                 return 0;
303
304         dentry = dget(bprm->file->f_dentry);
305
306         rc = get_vfs_caps_from_disk(dentry, &vcaps);
307         if (rc < 0) {
308                 if (rc == -EINVAL)
309                         printk(KERN_NOTICE "%s: get_vfs_caps_from_disk returned %d for %s\n",
310                                 __func__, rc, bprm->filename);
311                 else if (rc == -ENODATA)
312                         rc = 0;
313                 goto out;
314         }
315
316         rc = bprm_caps_from_vfs_caps(&vcaps, bprm);
317
318 out:
319         dput(dentry);
320         if (rc)
321                 bprm_clear_caps(bprm);
322
323         return rc;
324 }
325
326 #else
327 int cap_inode_need_killpriv(struct dentry *dentry)
328 {
329         return 0;
330 }
331
332 int cap_inode_killpriv(struct dentry *dentry)
333 {
334         return 0;
335 }
336
337 static inline int get_file_caps(struct linux_binprm *bprm)
338 {
339         bprm_clear_caps(bprm);
340         return 0;
341 }
342 #endif
343
344 int cap_bprm_set_security (struct linux_binprm *bprm)
345 {
346         int ret;
347
348         ret = get_file_caps(bprm);
349
350         if (!issecure(SECURE_NOROOT)) {
351                 /*
352                  * To support inheritance of root-permissions and suid-root
353                  * executables under compatibility mode, we override the
354                  * capability sets for the file.
355                  *
356                  * If only the real uid is 0, we do not set the effective
357                  * bit.
358                  */
359                 if (bprm->e_uid == 0 || current_uid() == 0) {
360                         /* pP' = (cap_bset & ~0) | (pI & ~0) */
361                         bprm->cap_post_exec_permitted = cap_combine(
362                                 current->cred->cap_bset,
363                                 current->cred->cap_inheritable);
364                         bprm->cap_effective = (bprm->e_uid == 0);
365                         ret = 0;
366                 }
367         }
368
369         return ret;
370 }
371
372 int cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
373 {
374         const struct cred *old = current_cred();
375         struct cred *new;
376
377         new = prepare_creds();
378         if (!new)
379                 return -ENOMEM;
380
381         if (bprm->e_uid != old->uid || bprm->e_gid != old->gid ||
382             !cap_issubset(bprm->cap_post_exec_permitted,
383                           old->cap_permitted)) {
384                 set_dumpable(current->mm, suid_dumpable);
385                 current->pdeath_signal = 0;
386
387                 if (unsafe & ~LSM_UNSAFE_PTRACE_CAP) {
388                         if (!capable(CAP_SETUID)) {
389                                 bprm->e_uid = old->uid;
390                                 bprm->e_gid = old->gid;
391                         }
392                         if (cap_limit_ptraced_target()) {
393                                 bprm->cap_post_exec_permitted = cap_intersect(
394                                         bprm->cap_post_exec_permitted,
395                                         new->cap_permitted);
396                         }
397                 }
398         }
399
400         new->suid = new->euid = new->fsuid = bprm->e_uid;
401         new->sgid = new->egid = new->fsgid = bprm->e_gid;
402
403         /* For init, we want to retain the capabilities set
404          * in the init_task struct. Thus we skip the usual
405          * capability rules */
406         if (!is_global_init(current)) {
407                 new->cap_permitted = bprm->cap_post_exec_permitted;
408                 if (bprm->cap_effective)
409                         new->cap_effective = bprm->cap_post_exec_permitted;
410                 else
411                         cap_clear(new->cap_effective);
412         }
413
414         /*
415          * Audit candidate if current->cap_effective is set
416          *
417          * We do not bother to audit if 3 things are true:
418          *   1) cap_effective has all caps
419          *   2) we are root
420          *   3) root is supposed to have all caps (SECURE_NOROOT)
421          * Since this is just a normal root execing a process.
422          *
423          * Number 1 above might fail if you don't have a full bset, but I think
424          * that is interesting information to audit.
425          */
426         if (!cap_isclear(new->cap_effective)) {
427                 if (!cap_issubset(CAP_FULL_SET, new->cap_effective) ||
428                     bprm->e_uid != 0 || new->uid != 0 ||
429                     issecure(SECURE_NOROOT))
430                         audit_log_bprm_fcaps(bprm, new, old);
431         }
432
433         new->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);
434         return commit_creds(new);
435 }
436
437 int cap_bprm_secureexec (struct linux_binprm *bprm)
438 {
439         const struct cred *cred = current_cred();
440
441         if (cred->uid != 0) {
442                 if (bprm->cap_effective)
443                         return 1;
444                 if (!cap_isclear(bprm->cap_post_exec_permitted))
445                         return 1;
446         }
447
448         return (cred->euid != cred->uid ||
449                 cred->egid != cred->gid);
450 }
451
452 int cap_inode_setxattr(struct dentry *dentry, const char *name,
453                        const void *value, size_t size, int flags)
454 {
455         if (!strcmp(name, XATTR_NAME_CAPS)) {
456                 if (!capable(CAP_SETFCAP))
457                         return -EPERM;
458                 return 0;
459         } else if (!strncmp(name, XATTR_SECURITY_PREFIX,
460                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
461             !capable(CAP_SYS_ADMIN))
462                 return -EPERM;
463         return 0;
464 }
465
466 int cap_inode_removexattr(struct dentry *dentry, const char *name)
467 {
468         if (!strcmp(name, XATTR_NAME_CAPS)) {
469                 if (!capable(CAP_SETFCAP))
470                         return -EPERM;
471                 return 0;
472         } else if (!strncmp(name, XATTR_SECURITY_PREFIX,
473                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
474             !capable(CAP_SYS_ADMIN))
475                 return -EPERM;
476         return 0;
477 }
478
479 /* moved from kernel/sys.c. */
480 /* 
481  * cap_emulate_setxuid() fixes the effective / permitted capabilities of
482  * a process after a call to setuid, setreuid, or setresuid.
483  *
484  *  1) When set*uiding _from_ one of {r,e,s}uid == 0 _to_ all of
485  *  {r,e,s}uid != 0, the permitted and effective capabilities are
486  *  cleared.
487  *
488  *  2) When set*uiding _from_ euid == 0 _to_ euid != 0, the effective
489  *  capabilities of the process are cleared.
490  *
491  *  3) When set*uiding _from_ euid != 0 _to_ euid == 0, the effective
492  *  capabilities are set to the permitted capabilities.
493  *
494  *  fsuid is handled elsewhere. fsuid == 0 and {r,e,s}uid!= 0 should 
495  *  never happen.
496  *
497  *  -astor 
498  *
499  * cevans - New behaviour, Oct '99
500  * A process may, via prctl(), elect to keep its capabilities when it
501  * calls setuid() and switches away from uid==0. Both permitted and
502  * effective sets will be retained.
503  * Without this change, it was impossible for a daemon to drop only some
504  * of its privilege. The call to setuid(!=0) would drop all privileges!
505  * Keeping uid 0 is not an option because uid 0 owns too many vital
506  * files..
507  * Thanks to Olaf Kirch and Peter Benie for spotting this.
508  */
509 static inline void cap_emulate_setxuid(struct cred *new, const struct cred *old)
510 {
511         if ((old->uid == 0 || old->euid == 0 || old->suid == 0) &&
512             (new->uid != 0 && new->euid != 0 && new->suid != 0) &&
513             !issecure(SECURE_KEEP_CAPS)) {
514                 cap_clear(new->cap_permitted);
515                 cap_clear(new->cap_effective);
516         }
517         if (old->euid == 0 && new->euid != 0)
518                 cap_clear(new->cap_effective);
519         if (old->euid != 0 && new->euid == 0)
520                 new->cap_effective = new->cap_permitted;
521 }
522
523 int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags)
524 {
525         switch (flags) {
526         case LSM_SETID_RE:
527         case LSM_SETID_ID:
528         case LSM_SETID_RES:
529                 /* Copied from kernel/sys.c:setreuid/setuid/setresuid. */
530                 if (!issecure(SECURE_NO_SETUID_FIXUP))
531                         cap_emulate_setxuid(new, old);
532                 break;
533         case LSM_SETID_FS:
534                 /* Copied from kernel/sys.c:setfsuid. */
535
536                 /*
537                  * FIXME - is fsuser used for all CAP_FS_MASK capabilities?
538                  *          if not, we might be a bit too harsh here.
539                  */
540                 if (!issecure(SECURE_NO_SETUID_FIXUP)) {
541                         if (old->fsuid == 0 && new->fsuid != 0) {
542                                 new->cap_effective =
543                                         cap_drop_fs_set(new->cap_effective);
544                         }
545                         if (old->fsuid != 0 && new->fsuid == 0) {
546                                 new->cap_effective =
547                                         cap_raise_fs_set(new->cap_effective,
548                                                          new->cap_permitted);
549                         }
550                 }
551                 break;
552         default:
553                 return -EINVAL;
554         }
555
556         return 0;
557 }
558
559 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
560 /*
561  * Rationale: code calling task_setscheduler, task_setioprio, and
562  * task_setnice, assumes that
563  *   . if capable(cap_sys_nice), then those actions should be allowed
564  *   . if not capable(cap_sys_nice), but acting on your own processes,
565  *      then those actions should be allowed
566  * This is insufficient now since you can call code without suid, but
567  * yet with increased caps.
568  * So we check for increased caps on the target process.
569  */
570 static int cap_safe_nice(struct task_struct *p)
571 {
572         int is_subset;
573
574         rcu_read_lock();
575         is_subset = cap_issubset(__task_cred(p)->cap_permitted,
576                                  current_cred()->cap_permitted);
577         rcu_read_unlock();
578
579         if (!is_subset && !capable(CAP_SYS_NICE))
580                 return -EPERM;
581         return 0;
582 }
583
584 int cap_task_setscheduler (struct task_struct *p, int policy,
585                            struct sched_param *lp)
586 {
587         return cap_safe_nice(p);
588 }
589
590 int cap_task_setioprio (struct task_struct *p, int ioprio)
591 {
592         return cap_safe_nice(p);
593 }
594
595 int cap_task_setnice (struct task_struct *p, int nice)
596 {
597         return cap_safe_nice(p);
598 }
599
600 /*
601  * called from kernel/sys.c for prctl(PR_CABSET_DROP)
602  * done without task_capability_lock() because it introduces
603  * no new races - i.e. only another task doing capget() on
604  * this task could get inconsistent info.  There can be no
605  * racing writer bc a task can only change its own caps.
606  */
607 static long cap_prctl_drop(struct cred *new, unsigned long cap)
608 {
609         if (!capable(CAP_SETPCAP))
610                 return -EPERM;
611         if (!cap_valid(cap))
612                 return -EINVAL;
613
614         cap_lower(new->cap_bset, cap);
615         return 0;
616 }
617
618 #else
619 int cap_task_setscheduler (struct task_struct *p, int policy,
620                            struct sched_param *lp)
621 {
622         return 0;
623 }
624 int cap_task_setioprio (struct task_struct *p, int ioprio)
625 {
626         return 0;
627 }
628 int cap_task_setnice (struct task_struct *p, int nice)
629 {
630         return 0;
631 }
632 #endif
633
634 int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
635                    unsigned long arg4, unsigned long arg5)
636 {
637         struct cred *new;
638         long error = 0;
639
640         new = prepare_creds();
641         if (!new)
642                 return -ENOMEM;
643
644         switch (option) {
645         case PR_CAPBSET_READ:
646                 error = -EINVAL;
647                 if (!cap_valid(arg2))
648                         goto error;
649                 error = !!cap_raised(new->cap_bset, arg2);
650                 goto no_change;
651
652 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
653         case PR_CAPBSET_DROP:
654                 error = cap_prctl_drop(new, arg2);
655                 if (error < 0)
656                         goto error;
657                 goto changed;
658
659         /*
660          * The next four prctl's remain to assist with transitioning a
661          * system from legacy UID=0 based privilege (when filesystem
662          * capabilities are not in use) to a system using filesystem
663          * capabilities only - as the POSIX.1e draft intended.
664          *
665          * Note:
666          *
667          *  PR_SET_SECUREBITS =
668          *      issecure_mask(SECURE_KEEP_CAPS_LOCKED)
669          *    | issecure_mask(SECURE_NOROOT)
670          *    | issecure_mask(SECURE_NOROOT_LOCKED)
671          *    | issecure_mask(SECURE_NO_SETUID_FIXUP)
672          *    | issecure_mask(SECURE_NO_SETUID_FIXUP_LOCKED)
673          *
674          * will ensure that the current process and all of its
675          * children will be locked into a pure
676          * capability-based-privilege environment.
677          */
678         case PR_SET_SECUREBITS:
679                 error = -EPERM;
680                 if ((((new->securebits & SECURE_ALL_LOCKS) >> 1)
681                      & (new->securebits ^ arg2))                        /*[1]*/
682                     || ((new->securebits & SECURE_ALL_LOCKS & ~arg2))   /*[2]*/
683                     || (arg2 & ~(SECURE_ALL_LOCKS | SECURE_ALL_BITS))   /*[3]*/
684                     || (cap_capable(current, CAP_SETPCAP, SECURITY_CAP_AUDIT) != 0) /*[4]*/
685                         /*
686                          * [1] no changing of bits that are locked
687                          * [2] no unlocking of locks
688                          * [3] no setting of unsupported bits
689                          * [4] doing anything requires privilege (go read about
690                          *     the "sendmail capabilities bug")
691                          */
692                     )
693                         /* cannot change a locked bit */
694                         goto error;
695                 new->securebits = arg2;
696                 goto changed;
697
698         case PR_GET_SECUREBITS:
699                 error = new->securebits;
700                 goto no_change;
701
702 #endif /* def CONFIG_SECURITY_FILE_CAPABILITIES */
703
704         case PR_GET_KEEPCAPS:
705                 if (issecure(SECURE_KEEP_CAPS))
706                         error = 1;
707                 goto no_change;
708
709         case PR_SET_KEEPCAPS:
710                 error = -EINVAL;
711                 if (arg2 > 1) /* Note, we rely on arg2 being unsigned here */
712                         goto error;
713                 error = -EPERM;
714                 if (issecure(SECURE_KEEP_CAPS_LOCKED))
715                         goto error;
716                 if (arg2)
717                         new->securebits |= issecure_mask(SECURE_KEEP_CAPS);
718                 else
719                         new->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);
720                 goto changed;
721
722         default:
723                 /* No functionality available - continue with default */
724                 error = -ENOSYS;
725                 goto error;
726         }
727
728         /* Functionality provided */
729 changed:
730         return commit_creds(new);
731
732 no_change:
733         error = 0;
734 error:
735         abort_creds(new);
736         return error;
737 }
738
739 int cap_syslog (int type)
740 {
741         if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
742                 return -EPERM;
743         return 0;
744 }
745
746 int cap_vm_enough_memory(struct mm_struct *mm, long pages)
747 {
748         int cap_sys_admin = 0;
749
750         if (cap_capable(current, CAP_SYS_ADMIN, SECURITY_CAP_NOAUDIT) == 0)
751                 cap_sys_admin = 1;
752         return __vm_enough_memory(mm, pages, cap_sys_admin);
753 }
754