CRED: Make execve() take advantage of copy-on-write 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->cred->cap_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                                           bool *effective)
203 {
204         struct cred *new = bprm->cred;
205         unsigned i;
206         int ret = 0;
207
208         if (caps->magic_etc & VFS_CAP_FLAGS_EFFECTIVE)
209                 *effective = true;
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                 new->cap_permitted.cap[i] =
219                         (new->cap_bset.cap[i] & permitted) |
220                         (new->cap_inheritable.cap[i] & inheritable);
221
222                 if (permitted & ~new->cap_permitted.cap[i])
223                         /* insufficient to execute correctly */
224                         ret = -EPERM;
225         }
226
227         /*
228          * For legacy apps, with no internal support for recognizing they
229          * do not have enough capabilities, we return an error if they are
230          * missing some "forced" (aka file-permitted) capabilities.
231          */
232         return *effective ? ret : 0;
233 }
234
235 int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps)
236 {
237         struct inode *inode = dentry->d_inode;
238         __u32 magic_etc;
239         unsigned tocopy, i;
240         int size;
241         struct vfs_cap_data caps;
242
243         memset(cpu_caps, 0, sizeof(struct cpu_vfs_cap_data));
244
245         if (!inode || !inode->i_op || !inode->i_op->getxattr)
246                 return -ENODATA;
247
248         size = inode->i_op->getxattr((struct dentry *)dentry, XATTR_NAME_CAPS, &caps,
249                                    XATTR_CAPS_SZ);
250         if (size == -ENODATA || size == -EOPNOTSUPP)
251                 /* no data, that's ok */
252                 return -ENODATA;
253         if (size < 0)
254                 return size;
255
256         if (size < sizeof(magic_etc))
257                 return -EINVAL;
258
259         cpu_caps->magic_etc = magic_etc = le32_to_cpu(caps.magic_etc);
260
261         switch (magic_etc & VFS_CAP_REVISION_MASK) {
262         case VFS_CAP_REVISION_1:
263                 if (size != XATTR_CAPS_SZ_1)
264                         return -EINVAL;
265                 tocopy = VFS_CAP_U32_1;
266                 break;
267         case VFS_CAP_REVISION_2:
268                 if (size != XATTR_CAPS_SZ_2)
269                         return -EINVAL;
270                 tocopy = VFS_CAP_U32_2;
271                 break;
272         default:
273                 return -EINVAL;
274         }
275
276         CAP_FOR_EACH_U32(i) {
277                 if (i >= tocopy)
278                         break;
279                 cpu_caps->permitted.cap[i] = le32_to_cpu(caps.data[i].permitted);
280                 cpu_caps->inheritable.cap[i] = le32_to_cpu(caps.data[i].inheritable);
281         }
282
283         return 0;
284 }
285
286 /* Locate any VFS capabilities: */
287 static int get_file_caps(struct linux_binprm *bprm, bool *effective)
288 {
289         struct dentry *dentry;
290         int rc = 0;
291         struct cpu_vfs_cap_data vcaps;
292
293         bprm_clear_caps(bprm);
294
295         if (!file_caps_enabled)
296                 return 0;
297
298         if (bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID)
299                 return 0;
300
301         dentry = dget(bprm->file->f_dentry);
302
303         rc = get_vfs_caps_from_disk(dentry, &vcaps);
304         if (rc < 0) {
305                 if (rc == -EINVAL)
306                         printk(KERN_NOTICE "%s: get_vfs_caps_from_disk returned %d for %s\n",
307                                 __func__, rc, bprm->filename);
308                 else if (rc == -ENODATA)
309                         rc = 0;
310                 goto out;
311         }
312
313         rc = bprm_caps_from_vfs_caps(&vcaps, bprm, effective);
314         if (rc == -EINVAL)
315                 printk(KERN_NOTICE "%s: cap_from_disk returned %d for %s\n",
316                        __func__, rc, bprm->filename);
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, bool *effective)
338 {
339         bprm_clear_caps(bprm);
340         return 0;
341 }
342 #endif
343
344 /*
345  * set up the new credentials for an exec'd task
346  */
347 int cap_bprm_set_creds(struct linux_binprm *bprm)
348 {
349         const struct cred *old = current_cred();
350         struct cred *new = bprm->cred;
351         bool effective;
352         int ret;
353
354         effective = false;
355         ret = get_file_caps(bprm, &effective);
356         if (ret < 0)
357                 return ret;
358
359         if (!issecure(SECURE_NOROOT)) {
360                 /*
361                  * To support inheritance of root-permissions and suid-root
362                  * executables under compatibility mode, we override the
363                  * capability sets for the file.
364                  *
365                  * If only the real uid is 0, we do not set the effective bit.
366                  */
367                 if (new->euid == 0 || new->uid == 0) {
368                         /* pP' = (cap_bset & ~0) | (pI & ~0) */
369                         new->cap_permitted = cap_combine(old->cap_bset,
370                                                          old->cap_inheritable);
371                 }
372                 if (new->euid == 0)
373                         effective = true;
374         }
375
376         /* Don't let someone trace a set[ug]id/setpcap binary with the revised
377          * credentials unless they have the appropriate permit
378          */
379         if ((new->euid != old->uid ||
380              new->egid != old->gid ||
381              !cap_issubset(new->cap_permitted, old->cap_permitted)) &&
382             bprm->unsafe & ~LSM_UNSAFE_PTRACE_CAP) {
383                 /* downgrade; they get no more than they had, and maybe less */
384                 if (!capable(CAP_SETUID)) {
385                         new->euid = new->uid;
386                         new->egid = new->gid;
387                 }
388                 if (cap_limit_ptraced_target())
389                         new->cap_permitted = cap_intersect(new->cap_permitted,
390                                                            old->cap_permitted);
391         }
392
393         new->suid = new->fsuid = new->euid;
394         new->sgid = new->fsgid = new->egid;
395
396         /* For init, we want to retain the capabilities set in the initial
397          * task.  Thus we skip the usual capability rules
398          */
399         if (!is_global_init(current)) {
400                 if (effective)
401                         new->cap_effective = new->cap_permitted;
402                 else
403                         cap_clear(new->cap_effective);
404         }
405         bprm->cap_effective = effective;
406
407         /*
408          * Audit candidate if current->cap_effective is set
409          *
410          * We do not bother to audit if 3 things are true:
411          *   1) cap_effective has all caps
412          *   2) we are root
413          *   3) root is supposed to have all caps (SECURE_NOROOT)
414          * Since this is just a normal root execing a process.
415          *
416          * Number 1 above might fail if you don't have a full bset, but I think
417          * that is interesting information to audit.
418          */
419         if (!cap_isclear(new->cap_effective)) {
420                 if (!cap_issubset(CAP_FULL_SET, new->cap_effective) ||
421                     new->euid != 0 || new->uid != 0 ||
422                     issecure(SECURE_NOROOT)) {
423                         ret = audit_log_bprm_fcaps(bprm, new, old);
424                         if (ret < 0)
425                                 return ret;
426                 }
427         }
428
429         new->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);
430         return 0;
431 }
432
433 /*
434  * determine whether a secure execution is required
435  * - the creds have been committed at this point, and are no longer available
436  *   through bprm
437  */
438 int cap_bprm_secureexec(struct linux_binprm *bprm)
439 {
440         const struct cred *cred = current_cred();
441
442         if (cred->uid != 0) {
443                 if (bprm->cap_effective)
444                         return 1;
445                 if (!cap_isclear(cred->cap_permitted))
446                         return 1;
447         }
448
449         return (cred->euid != cred->uid ||
450                 cred->egid != cred->gid);
451 }
452
453 int cap_inode_setxattr(struct dentry *dentry, const char *name,
454                        const void *value, size_t size, int flags)
455 {
456         if (!strcmp(name, XATTR_NAME_CAPS)) {
457                 if (!capable(CAP_SETFCAP))
458                         return -EPERM;
459                 return 0;
460         } else if (!strncmp(name, XATTR_SECURITY_PREFIX,
461                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
462             !capable(CAP_SYS_ADMIN))
463                 return -EPERM;
464         return 0;
465 }
466
467 int cap_inode_removexattr(struct dentry *dentry, const char *name)
468 {
469         if (!strcmp(name, XATTR_NAME_CAPS)) {
470                 if (!capable(CAP_SETFCAP))
471                         return -EPERM;
472                 return 0;
473         } else if (!strncmp(name, XATTR_SECURITY_PREFIX,
474                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
475             !capable(CAP_SYS_ADMIN))
476                 return -EPERM;
477         return 0;
478 }
479
480 /* moved from kernel/sys.c. */
481 /*
482  * cap_emulate_setxuid() fixes the effective / permitted capabilities of
483  * a process after a call to setuid, setreuid, or setresuid.
484  *
485  *  1) When set*uiding _from_ one of {r,e,s}uid == 0 _to_ all of
486  *  {r,e,s}uid != 0, the permitted and effective capabilities are
487  *  cleared.
488  *
489  *  2) When set*uiding _from_ euid == 0 _to_ euid != 0, the effective
490  *  capabilities of the process are cleared.
491  *
492  *  3) When set*uiding _from_ euid != 0 _to_ euid == 0, the effective
493  *  capabilities are set to the permitted capabilities.
494  *
495  *  fsuid is handled elsewhere. fsuid == 0 and {r,e,s}uid!= 0 should
496  *  never happen.
497  *
498  *  -astor
499  *
500  * cevans - New behaviour, Oct '99
501  * A process may, via prctl(), elect to keep its capabilities when it
502  * calls setuid() and switches away from uid==0. Both permitted and
503  * effective sets will be retained.
504  * Without this change, it was impossible for a daemon to drop only some
505  * of its privilege. The call to setuid(!=0) would drop all privileges!
506  * Keeping uid 0 is not an option because uid 0 owns too many vital
507  * files..
508  * Thanks to Olaf Kirch and Peter Benie for spotting this.
509  */
510 static inline void cap_emulate_setxuid(struct cred *new, const struct cred *old)
511 {
512         if ((old->uid == 0 || old->euid == 0 || old->suid == 0) &&
513             (new->uid != 0 && new->euid != 0 && new->suid != 0) &&
514             !issecure(SECURE_KEEP_CAPS)) {
515                 cap_clear(new->cap_permitted);
516                 cap_clear(new->cap_effective);
517         }
518         if (old->euid == 0 && new->euid != 0)
519                 cap_clear(new->cap_effective);
520         if (old->euid != 0 && new->euid == 0)
521                 new->cap_effective = new->cap_permitted;
522 }
523
524 int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags)
525 {
526         switch (flags) {
527         case LSM_SETID_RE:
528         case LSM_SETID_ID:
529         case LSM_SETID_RES:
530                 /* Copied from kernel/sys.c:setreuid/setuid/setresuid. */
531                 if (!issecure(SECURE_NO_SETUID_FIXUP))
532                         cap_emulate_setxuid(new, old);
533                 break;
534         case LSM_SETID_FS:
535                 /* Copied from kernel/sys.c:setfsuid. */
536
537                 /*
538                  * FIXME - is fsuser used for all CAP_FS_MASK capabilities?
539                  *          if not, we might be a bit too harsh here.
540                  */
541                 if (!issecure(SECURE_NO_SETUID_FIXUP)) {
542                         if (old->fsuid == 0 && new->fsuid != 0) {
543                                 new->cap_effective =
544                                         cap_drop_fs_set(new->cap_effective);
545                         }
546                         if (old->fsuid != 0 && new->fsuid == 0) {
547                                 new->cap_effective =
548                                         cap_raise_fs_set(new->cap_effective,
549                                                          new->cap_permitted);
550                         }
551                 }
552                 break;
553         default:
554                 return -EINVAL;
555         }
556
557         return 0;
558 }
559
560 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
561 /*
562  * Rationale: code calling task_setscheduler, task_setioprio, and
563  * task_setnice, assumes that
564  *   . if capable(cap_sys_nice), then those actions should be allowed
565  *   . if not capable(cap_sys_nice), but acting on your own processes,
566  *      then those actions should be allowed
567  * This is insufficient now since you can call code without suid, but
568  * yet with increased caps.
569  * So we check for increased caps on the target process.
570  */
571 static int cap_safe_nice(struct task_struct *p)
572 {
573         int is_subset;
574
575         rcu_read_lock();
576         is_subset = cap_issubset(__task_cred(p)->cap_permitted,
577                                  current_cred()->cap_permitted);
578         rcu_read_unlock();
579
580         if (!is_subset && !capable(CAP_SYS_NICE))
581                 return -EPERM;
582         return 0;
583 }
584
585 int cap_task_setscheduler (struct task_struct *p, int policy,
586                            struct sched_param *lp)
587 {
588         return cap_safe_nice(p);
589 }
590
591 int cap_task_setioprio (struct task_struct *p, int ioprio)
592 {
593         return cap_safe_nice(p);
594 }
595
596 int cap_task_setnice (struct task_struct *p, int nice)
597 {
598         return cap_safe_nice(p);
599 }
600
601 /*
602  * called from kernel/sys.c for prctl(PR_CABSET_DROP)
603  * done without task_capability_lock() because it introduces
604  * no new races - i.e. only another task doing capget() on
605  * this task could get inconsistent info.  There can be no
606  * racing writer bc a task can only change its own caps.
607  */
608 static long cap_prctl_drop(struct cred *new, unsigned long cap)
609 {
610         if (!capable(CAP_SETPCAP))
611                 return -EPERM;
612         if (!cap_valid(cap))
613                 return -EINVAL;
614
615         cap_lower(new->cap_bset, cap);
616         return 0;
617 }
618
619 #else
620 int cap_task_setscheduler (struct task_struct *p, int policy,
621                            struct sched_param *lp)
622 {
623         return 0;
624 }
625 int cap_task_setioprio (struct task_struct *p, int ioprio)
626 {
627         return 0;
628 }
629 int cap_task_setnice (struct task_struct *p, int nice)
630 {
631         return 0;
632 }
633 #endif
634
635 int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
636                    unsigned long arg4, unsigned long arg5)
637 {
638         struct cred *new;
639         long error = 0;
640
641         new = prepare_creds();
642         if (!new)
643                 return -ENOMEM;
644
645         switch (option) {
646         case PR_CAPBSET_READ:
647                 error = -EINVAL;
648                 if (!cap_valid(arg2))
649                         goto error;
650                 error = !!cap_raised(new->cap_bset, arg2);
651                 goto no_change;
652
653 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
654         case PR_CAPBSET_DROP:
655                 error = cap_prctl_drop(new, arg2);
656                 if (error < 0)
657                         goto error;
658                 goto changed;
659
660         /*
661          * The next four prctl's remain to assist with transitioning a
662          * system from legacy UID=0 based privilege (when filesystem
663          * capabilities are not in use) to a system using filesystem
664          * capabilities only - as the POSIX.1e draft intended.
665          *
666          * Note:
667          *
668          *  PR_SET_SECUREBITS =
669          *      issecure_mask(SECURE_KEEP_CAPS_LOCKED)
670          *    | issecure_mask(SECURE_NOROOT)
671          *    | issecure_mask(SECURE_NOROOT_LOCKED)
672          *    | issecure_mask(SECURE_NO_SETUID_FIXUP)
673          *    | issecure_mask(SECURE_NO_SETUID_FIXUP_LOCKED)
674          *
675          * will ensure that the current process and all of its
676          * children will be locked into a pure
677          * capability-based-privilege environment.
678          */
679         case PR_SET_SECUREBITS:
680                 error = -EPERM;
681                 if ((((new->securebits & SECURE_ALL_LOCKS) >> 1)
682                      & (new->securebits ^ arg2))                        /*[1]*/
683                     || ((new->securebits & SECURE_ALL_LOCKS & ~arg2))   /*[2]*/
684                     || (arg2 & ~(SECURE_ALL_LOCKS | SECURE_ALL_BITS))   /*[3]*/
685                     || (cap_capable(current, CAP_SETPCAP, SECURITY_CAP_AUDIT) != 0) /*[4]*/
686                         /*
687                          * [1] no changing of bits that are locked
688                          * [2] no unlocking of locks
689                          * [3] no setting of unsupported bits
690                          * [4] doing anything requires privilege (go read about
691                          *     the "sendmail capabilities bug")
692                          */
693                     )
694                         /* cannot change a locked bit */
695                         goto error;
696                 new->securebits = arg2;
697                 goto changed;
698
699         case PR_GET_SECUREBITS:
700                 error = new->securebits;
701                 goto no_change;
702
703 #endif /* def CONFIG_SECURITY_FILE_CAPABILITIES */
704
705         case PR_GET_KEEPCAPS:
706                 if (issecure(SECURE_KEEP_CAPS))
707                         error = 1;
708                 goto no_change;
709
710         case PR_SET_KEEPCAPS:
711                 error = -EINVAL;
712                 if (arg2 > 1) /* Note, we rely on arg2 being unsigned here */
713                         goto error;
714                 error = -EPERM;
715                 if (issecure(SECURE_KEEP_CAPS_LOCKED))
716                         goto error;
717                 if (arg2)
718                         new->securebits |= issecure_mask(SECURE_KEEP_CAPS);
719                 else
720                         new->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);
721                 goto changed;
722
723         default:
724                 /* No functionality available - continue with default */
725                 error = -ENOSYS;
726                 goto error;
727         }
728
729         /* Functionality provided */
730 changed:
731         return commit_creds(new);
732
733 no_change:
734         error = 0;
735 error:
736         abort_creds(new);
737         return error;
738 }
739
740 int cap_syslog (int type)
741 {
742         if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
743                 return -EPERM;
744         return 0;
745 }
746
747 int cap_vm_enough_memory(struct mm_struct *mm, long pages)
748 {
749         int cap_sys_admin = 0;
750
751         if (cap_capable(current, CAP_SYS_ADMIN, SECURITY_CAP_NOAUDIT) == 0)
752                 cap_sys_admin = 1;
753         return __vm_enough_memory(mm, pages, cap_sys_admin);
754 }