~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to kernel/sys.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include <linux/ptrace.h>
38
38
#include <linux/fs_struct.h>
39
39
#include <linux/gfp.h>
 
40
#include <linux/syscore_ops.h>
40
41
 
41
42
#include <linux/compat.h>
42
43
#include <linux/syscalls.h>
119
120
void (*pm_power_off_prepare)(void);
120
121
 
121
122
/*
 
123
 * Returns true if current's euid is same as p's uid or euid,
 
124
 * or has CAP_SYS_NICE to p's user_ns.
 
125
 *
 
126
 * Called with rcu_read_lock, creds are safe
 
127
 */
 
128
static bool set_one_prio_perm(struct task_struct *p)
 
129
{
 
130
        const struct cred *cred = current_cred(), *pcred = __task_cred(p);
 
131
 
 
132
        if (pcred->user->user_ns == cred->user->user_ns &&
 
133
            (pcred->uid  == cred->euid ||
 
134
             pcred->euid == cred->euid))
 
135
                return true;
 
136
        if (ns_capable(pcred->user->user_ns, CAP_SYS_NICE))
 
137
                return true;
 
138
        return false;
 
139
}
 
140
 
 
141
/*
122
142
 * set the priority of a task
123
143
 * - the caller must hold the RCU read lock
124
144
 */
125
145
static int set_one_prio(struct task_struct *p, int niceval, int error)
126
146
{
127
 
        const struct cred *cred = current_cred(), *pcred = __task_cred(p);
128
147
        int no_nice;
129
148
 
130
 
        if (pcred->uid  != cred->euid &&
131
 
            pcred->euid != cred->euid && !capable(CAP_SYS_NICE)) {
 
149
        if (!set_one_prio_perm(p)) {
132
150
                error = -EPERM;
133
151
                goto out;
134
152
        }
296
314
{
297
315
        blocking_notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd);
298
316
        system_state = SYSTEM_RESTART;
 
317
        usermodehelper_disable();
299
318
        device_shutdown();
300
 
        sysdev_shutdown();
 
319
        syscore_shutdown();
301
320
}
302
321
 
303
322
/**
325
344
        blocking_notifier_call_chain(&reboot_notifier_list,
326
345
                (state == SYSTEM_HALT)?SYS_HALT:SYS_POWER_OFF, NULL);
327
346
        system_state = state;
 
347
        usermodehelper_disable();
328
348
        device_shutdown();
329
349
}
330
350
/**
335
355
void kernel_halt(void)
336
356
{
337
357
        kernel_shutdown_prepare(SYSTEM_HALT);
338
 
        sysdev_shutdown();
 
358
        syscore_shutdown();
339
359
        printk(KERN_EMERG "System halted.\n");
340
360
        kmsg_dump(KMSG_DUMP_HALT);
341
361
        machine_halt();
354
374
        if (pm_power_off_prepare)
355
375
                pm_power_off_prepare();
356
376
        disable_nonboot_cpus();
357
 
        sysdev_shutdown();
 
377
        syscore_shutdown();
358
378
        printk(KERN_EMERG "Power down.\n");
359
379
        kmsg_dump(KMSG_DUMP_POWEROFF);
360
380
        machine_power_off();
502
522
        if (rgid != (gid_t) -1) {
503
523
                if (old->gid == rgid ||
504
524
                    old->egid == rgid ||
505
 
                    capable(CAP_SETGID))
 
525
                    nsown_capable(CAP_SETGID))
506
526
                        new->gid = rgid;
507
527
                else
508
528
                        goto error;
511
531
                if (old->gid == egid ||
512
532
                    old->egid == egid ||
513
533
                    old->sgid == egid ||
514
 
                    capable(CAP_SETGID))
 
534
                    nsown_capable(CAP_SETGID))
515
535
                        new->egid = egid;
516
536
                else
517
537
                        goto error;
546
566
        old = current_cred();
547
567
 
548
568
        retval = -EPERM;
549
 
        if (capable(CAP_SETGID))
 
569
        if (nsown_capable(CAP_SETGID))
550
570
                new->gid = new->egid = new->sgid = new->fsgid = gid;
551
571
        else if (gid == old->gid || gid == old->sgid)
552
572
                new->egid = new->fsgid = gid;
613
633
                new->uid = ruid;
614
634
                if (old->uid != ruid &&
615
635
                    old->euid != ruid &&
616
 
                    !capable(CAP_SETUID))
 
636
                    !nsown_capable(CAP_SETUID))
617
637
                        goto error;
618
638
        }
619
639
 
622
642
                if (old->uid != euid &&
623
643
                    old->euid != euid &&
624
644
                    old->suid != euid &&
625
 
                    !capable(CAP_SETUID))
 
645
                    !nsown_capable(CAP_SETUID))
626
646
                        goto error;
627
647
        }
628
648
 
670
690
        old = current_cred();
671
691
 
672
692
        retval = -EPERM;
673
 
        if (capable(CAP_SETUID)) {
 
693
        if (nsown_capable(CAP_SETUID)) {
674
694
                new->suid = new->uid = uid;
675
695
                if (uid != old->uid) {
676
696
                        retval = set_user(new);
712
732
        old = current_cred();
713
733
 
714
734
        retval = -EPERM;
715
 
        if (!capable(CAP_SETUID)) {
 
735
        if (!nsown_capable(CAP_SETUID)) {
716
736
                if (ruid != (uid_t) -1 && ruid != old->uid &&
717
737
                    ruid != old->euid  && ruid != old->suid)
718
738
                        goto error;
776
796
        old = current_cred();
777
797
 
778
798
        retval = -EPERM;
779
 
        if (!capable(CAP_SETGID)) {
 
799
        if (!nsown_capable(CAP_SETGID)) {
780
800
                if (rgid != (gid_t) -1 && rgid != old->gid &&
781
801
                    rgid != old->egid  && rgid != old->sgid)
782
802
                        goto error;
836
856
 
837
857
        if (uid == old->uid  || uid == old->euid  ||
838
858
            uid == old->suid || uid == old->fsuid ||
839
 
            capable(CAP_SETUID)) {
 
859
            nsown_capable(CAP_SETUID)) {
840
860
                if (uid != old_fsuid) {
841
861
                        new->fsuid = uid;
842
862
                        if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
869
889
 
870
890
        if (gid == old->gid  || gid == old->egid  ||
871
891
            gid == old->sgid || gid == old->fsgid ||
872
 
            capable(CAP_SETGID)) {
 
892
            nsown_capable(CAP_SETGID)) {
873
893
                if (gid != old_fsgid) {
874
894
                        new->fsgid = gid;
875
895
                        goto change_okay;
1177
1197
        int errno;
1178
1198
        char tmp[__NEW_UTS_LEN];
1179
1199
 
1180
 
        if (!capable(CAP_SYS_ADMIN))
 
1200
        if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
1181
1201
                return -EPERM;
 
1202
 
1182
1203
        if (len < 0 || len > __NEW_UTS_LEN)
1183
1204
                return -EINVAL;
1184
1205
        down_write(&uts_sem);
1226
1247
        int errno;
1227
1248
        char tmp[__NEW_UTS_LEN];
1228
1249
 
1229
 
        if (!capable(CAP_SYS_ADMIN))
 
1250
        if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
1230
1251
                return -EPERM;
1231
1252
        if (len < 0 || len > __NEW_UTS_LEN)
1232
1253
                return -EINVAL;
1341
1362
        rlim = tsk->signal->rlim + resource;
1342
1363
        task_lock(tsk->group_leader);
1343
1364
        if (new_rlim) {
 
1365
                /* Keep the capable check against init_user_ns until
 
1366
                   cgroups can contain all limits */
1344
1367
                if (new_rlim->rlim_max > rlim->rlim_max &&
1345
1368
                                !capable(CAP_SYS_RESOURCE))
1346
1369
                        retval = -EPERM;
1384
1407
{
1385
1408
        const struct cred *cred = current_cred(), *tcred;
1386
1409
 
 
1410
        if (current == task)
 
1411
                return 0;
 
1412
 
1387
1413
        tcred = __task_cred(task);
1388
 
        if (current != task &&
1389
 
            (cred->uid != tcred->euid ||
1390
 
             cred->uid != tcred->suid ||
1391
 
             cred->uid != tcred->uid  ||
1392
 
             cred->gid != tcred->egid ||
1393
 
             cred->gid != tcred->sgid ||
1394
 
             cred->gid != tcred->gid) &&
1395
 
             !capable(CAP_SYS_RESOURCE)) {
1396
 
                return -EPERM;
1397
 
        }
 
1414
        if (cred->user->user_ns == tcred->user->user_ns &&
 
1415
            (cred->uid == tcred->euid &&
 
1416
             cred->uid == tcred->suid &&
 
1417
             cred->uid == tcred->uid  &&
 
1418
             cred->gid == tcred->egid &&
 
1419
             cred->gid == tcred->sgid &&
 
1420
             cred->gid == tcred->gid))
 
1421
                return 0;
 
1422
        if (ns_capable(tcred->user->user_ns, CAP_SYS_RESOURCE))
 
1423
                return 0;
1398
1424
 
1399
 
        return 0;
 
1425
        return -EPERM;
1400
1426
}
1401
1427
 
1402
1428
SYSCALL_DEFINE4(prlimit64, pid_t, pid, unsigned int, resource,