diff options
Diffstat (limited to 'kernel/sys.c')
-rw-r--r-- | kernel/sys.c | 113 |
1 files changed, 51 insertions, 62 deletions
diff --git a/kernel/sys.c b/kernel/sys.c index 038a7bc0901d..53879cdae483 100644 --- a/kernel/sys.c +++ b/kernel/sys.c | |||
@@ -853,38 +853,28 @@ asmlinkage long sys_setfsgid(gid_t gid) | |||
853 | return old_fsgid; | 853 | return old_fsgid; |
854 | } | 854 | } |
855 | 855 | ||
856 | void do_sys_times(struct tms *tms) | ||
857 | { | ||
858 | struct task_cputime cputime; | ||
859 | cputime_t cutime, cstime; | ||
860 | |||
861 | spin_lock_irq(¤t->sighand->siglock); | ||
862 | thread_group_cputime(current, &cputime); | ||
863 | cutime = current->signal->cutime; | ||
864 | cstime = current->signal->cstime; | ||
865 | spin_unlock_irq(¤t->sighand->siglock); | ||
866 | tms->tms_utime = cputime_to_clock_t(cputime.utime); | ||
867 | tms->tms_stime = cputime_to_clock_t(cputime.stime); | ||
868 | tms->tms_cutime = cputime_to_clock_t(cutime); | ||
869 | tms->tms_cstime = cputime_to_clock_t(cstime); | ||
870 | } | ||
871 | |||
856 | asmlinkage long sys_times(struct tms __user * tbuf) | 872 | asmlinkage long sys_times(struct tms __user * tbuf) |
857 | { | 873 | { |
858 | /* | ||
859 | * In the SMP world we might just be unlucky and have one of | ||
860 | * the times increment as we use it. Since the value is an | ||
861 | * atomically safe type this is just fine. Conceptually its | ||
862 | * as if the syscall took an instant longer to occur. | ||
863 | */ | ||
864 | if (tbuf) { | 874 | if (tbuf) { |
865 | struct tms tmp; | 875 | struct tms tmp; |
866 | struct task_struct *tsk = current; | 876 | |
867 | struct task_struct *t; | 877 | do_sys_times(&tmp); |
868 | cputime_t utime, stime, cutime, cstime; | ||
869 | |||
870 | spin_lock_irq(&tsk->sighand->siglock); | ||
871 | utime = tsk->signal->utime; | ||
872 | stime = tsk->signal->stime; | ||
873 | t = tsk; | ||
874 | do { | ||
875 | utime = cputime_add(utime, t->utime); | ||
876 | stime = cputime_add(stime, t->stime); | ||
877 | t = next_thread(t); | ||
878 | } while (t != tsk); | ||
879 | |||
880 | cutime = tsk->signal->cutime; | ||
881 | cstime = tsk->signal->cstime; | ||
882 | spin_unlock_irq(&tsk->sighand->siglock); | ||
883 | |||
884 | tmp.tms_utime = cputime_to_clock_t(utime); | ||
885 | tmp.tms_stime = cputime_to_clock_t(stime); | ||
886 | tmp.tms_cutime = cputime_to_clock_t(cutime); | ||
887 | tmp.tms_cstime = cputime_to_clock_t(cstime); | ||
888 | if (copy_to_user(tbuf, &tmp, sizeof(struct tms))) | 878 | if (copy_to_user(tbuf, &tmp, sizeof(struct tms))) |
889 | return -EFAULT; | 879 | return -EFAULT; |
890 | } | 880 | } |
@@ -1060,9 +1050,7 @@ asmlinkage long sys_setsid(void) | |||
1060 | group_leader->signal->leader = 1; | 1050 | group_leader->signal->leader = 1; |
1061 | __set_special_pids(sid); | 1051 | __set_special_pids(sid); |
1062 | 1052 | ||
1063 | spin_lock(&group_leader->sighand->siglock); | 1053 | proc_clear_tty(group_leader); |
1064 | group_leader->signal->tty = NULL; | ||
1065 | spin_unlock(&group_leader->sighand->siglock); | ||
1066 | 1054 | ||
1067 | err = session; | 1055 | err = session; |
1068 | out: | 1056 | out: |
@@ -1351,8 +1339,10 @@ asmlinkage long sys_sethostname(char __user *name, int len) | |||
1351 | down_write(&uts_sem); | 1339 | down_write(&uts_sem); |
1352 | errno = -EFAULT; | 1340 | errno = -EFAULT; |
1353 | if (!copy_from_user(tmp, name, len)) { | 1341 | if (!copy_from_user(tmp, name, len)) { |
1354 | memcpy(utsname()->nodename, tmp, len); | 1342 | struct new_utsname *u = utsname(); |
1355 | utsname()->nodename[len] = 0; | 1343 | |
1344 | memcpy(u->nodename, tmp, len); | ||
1345 | memset(u->nodename + len, 0, sizeof(u->nodename) - len); | ||
1356 | errno = 0; | 1346 | errno = 0; |
1357 | } | 1347 | } |
1358 | up_write(&uts_sem); | 1348 | up_write(&uts_sem); |
@@ -1364,15 +1354,17 @@ asmlinkage long sys_sethostname(char __user *name, int len) | |||
1364 | asmlinkage long sys_gethostname(char __user *name, int len) | 1354 | asmlinkage long sys_gethostname(char __user *name, int len) |
1365 | { | 1355 | { |
1366 | int i, errno; | 1356 | int i, errno; |
1357 | struct new_utsname *u; | ||
1367 | 1358 | ||
1368 | if (len < 0) | 1359 | if (len < 0) |
1369 | return -EINVAL; | 1360 | return -EINVAL; |
1370 | down_read(&uts_sem); | 1361 | down_read(&uts_sem); |
1371 | i = 1 + strlen(utsname()->nodename); | 1362 | u = utsname(); |
1363 | i = 1 + strlen(u->nodename); | ||
1372 | if (i > len) | 1364 | if (i > len) |
1373 | i = len; | 1365 | i = len; |
1374 | errno = 0; | 1366 | errno = 0; |
1375 | if (copy_to_user(name, utsname()->nodename, i)) | 1367 | if (copy_to_user(name, u->nodename, i)) |
1376 | errno = -EFAULT; | 1368 | errno = -EFAULT; |
1377 | up_read(&uts_sem); | 1369 | up_read(&uts_sem); |
1378 | return errno; | 1370 | return errno; |
@@ -1397,8 +1389,10 @@ asmlinkage long sys_setdomainname(char __user *name, int len) | |||
1397 | down_write(&uts_sem); | 1389 | down_write(&uts_sem); |
1398 | errno = -EFAULT; | 1390 | errno = -EFAULT; |
1399 | if (!copy_from_user(tmp, name, len)) { | 1391 | if (!copy_from_user(tmp, name, len)) { |
1400 | memcpy(utsname()->domainname, tmp, len); | 1392 | struct new_utsname *u = utsname(); |
1401 | utsname()->domainname[len] = 0; | 1393 | |
1394 | memcpy(u->domainname, tmp, len); | ||
1395 | memset(u->domainname + len, 0, sizeof(u->domainname) - len); | ||
1402 | errno = 0; | 1396 | errno = 0; |
1403 | } | 1397 | } |
1404 | up_write(&uts_sem); | 1398 | up_write(&uts_sem); |
@@ -1445,21 +1439,28 @@ asmlinkage long sys_old_getrlimit(unsigned int resource, struct rlimit __user *r | |||
1445 | asmlinkage long sys_setrlimit(unsigned int resource, struct rlimit __user *rlim) | 1439 | asmlinkage long sys_setrlimit(unsigned int resource, struct rlimit __user *rlim) |
1446 | { | 1440 | { |
1447 | struct rlimit new_rlim, *old_rlim; | 1441 | struct rlimit new_rlim, *old_rlim; |
1448 | unsigned long it_prof_secs; | ||
1449 | int retval; | 1442 | int retval; |
1450 | 1443 | ||
1451 | if (resource >= RLIM_NLIMITS) | 1444 | if (resource >= RLIM_NLIMITS) |
1452 | return -EINVAL; | 1445 | return -EINVAL; |
1453 | if (copy_from_user(&new_rlim, rlim, sizeof(*rlim))) | 1446 | if (copy_from_user(&new_rlim, rlim, sizeof(*rlim))) |
1454 | return -EFAULT; | 1447 | return -EFAULT; |
1455 | if (new_rlim.rlim_cur > new_rlim.rlim_max) | ||
1456 | return -EINVAL; | ||
1457 | old_rlim = current->signal->rlim + resource; | 1448 | old_rlim = current->signal->rlim + resource; |
1458 | if ((new_rlim.rlim_max > old_rlim->rlim_max) && | 1449 | if ((new_rlim.rlim_max > old_rlim->rlim_max) && |
1459 | !capable(CAP_SYS_RESOURCE)) | 1450 | !capable(CAP_SYS_RESOURCE)) |
1460 | return -EPERM; | 1451 | return -EPERM; |
1461 | if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open) | 1452 | |
1462 | return -EPERM; | 1453 | if (resource == RLIMIT_NOFILE) { |
1454 | if (new_rlim.rlim_max == RLIM_INFINITY) | ||
1455 | new_rlim.rlim_max = sysctl_nr_open; | ||
1456 | if (new_rlim.rlim_cur == RLIM_INFINITY) | ||
1457 | new_rlim.rlim_cur = sysctl_nr_open; | ||
1458 | if (new_rlim.rlim_max > sysctl_nr_open) | ||
1459 | return -EPERM; | ||
1460 | } | ||
1461 | |||
1462 | if (new_rlim.rlim_cur > new_rlim.rlim_max) | ||
1463 | return -EINVAL; | ||
1463 | 1464 | ||
1464 | retval = security_task_setrlimit(resource, &new_rlim); | 1465 | retval = security_task_setrlimit(resource, &new_rlim); |
1465 | if (retval) | 1466 | if (retval) |
@@ -1491,18 +1492,7 @@ asmlinkage long sys_setrlimit(unsigned int resource, struct rlimit __user *rlim) | |||
1491 | if (new_rlim.rlim_cur == RLIM_INFINITY) | 1492 | if (new_rlim.rlim_cur == RLIM_INFINITY) |
1492 | goto out; | 1493 | goto out; |
1493 | 1494 | ||
1494 | it_prof_secs = cputime_to_secs(current->signal->it_prof_expires); | 1495 | update_rlimit_cpu(new_rlim.rlim_cur); |
1495 | if (it_prof_secs == 0 || new_rlim.rlim_cur <= it_prof_secs) { | ||
1496 | unsigned long rlim_cur = new_rlim.rlim_cur; | ||
1497 | cputime_t cputime; | ||
1498 | |||
1499 | cputime = secs_to_cputime(rlim_cur); | ||
1500 | read_lock(&tasklist_lock); | ||
1501 | spin_lock_irq(¤t->sighand->siglock); | ||
1502 | set_process_cpu_timer(current, CPUCLOCK_PROF, &cputime, NULL); | ||
1503 | spin_unlock_irq(¤t->sighand->siglock); | ||
1504 | read_unlock(&tasklist_lock); | ||
1505 | } | ||
1506 | out: | 1496 | out: |
1507 | return 0; | 1497 | return 0; |
1508 | } | 1498 | } |
@@ -1540,11 +1530,8 @@ out: | |||
1540 | * | 1530 | * |
1541 | */ | 1531 | */ |
1542 | 1532 | ||
1543 | static void accumulate_thread_rusage(struct task_struct *t, struct rusage *r, | 1533 | static void accumulate_thread_rusage(struct task_struct *t, struct rusage *r) |
1544 | cputime_t *utimep, cputime_t *stimep) | ||
1545 | { | 1534 | { |
1546 | *utimep = cputime_add(*utimep, t->utime); | ||
1547 | *stimep = cputime_add(*stimep, t->stime); | ||
1548 | r->ru_nvcsw += t->nvcsw; | 1535 | r->ru_nvcsw += t->nvcsw; |
1549 | r->ru_nivcsw += t->nivcsw; | 1536 | r->ru_nivcsw += t->nivcsw; |
1550 | r->ru_minflt += t->min_flt; | 1537 | r->ru_minflt += t->min_flt; |
@@ -1558,12 +1545,13 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) | |||
1558 | struct task_struct *t; | 1545 | struct task_struct *t; |
1559 | unsigned long flags; | 1546 | unsigned long flags; |
1560 | cputime_t utime, stime; | 1547 | cputime_t utime, stime; |
1548 | struct task_cputime cputime; | ||
1561 | 1549 | ||
1562 | memset((char *) r, 0, sizeof *r); | 1550 | memset((char *) r, 0, sizeof *r); |
1563 | utime = stime = cputime_zero; | 1551 | utime = stime = cputime_zero; |
1564 | 1552 | ||
1565 | if (who == RUSAGE_THREAD) { | 1553 | if (who == RUSAGE_THREAD) { |
1566 | accumulate_thread_rusage(p, r, &utime, &stime); | 1554 | accumulate_thread_rusage(p, r); |
1567 | goto out; | 1555 | goto out; |
1568 | } | 1556 | } |
1569 | 1557 | ||
@@ -1586,8 +1574,9 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) | |||
1586 | break; | 1574 | break; |
1587 | 1575 | ||
1588 | case RUSAGE_SELF: | 1576 | case RUSAGE_SELF: |
1589 | utime = cputime_add(utime, p->signal->utime); | 1577 | thread_group_cputime(p, &cputime); |
1590 | stime = cputime_add(stime, p->signal->stime); | 1578 | utime = cputime_add(utime, cputime.utime); |
1579 | stime = cputime_add(stime, cputime.stime); | ||
1591 | r->ru_nvcsw += p->signal->nvcsw; | 1580 | r->ru_nvcsw += p->signal->nvcsw; |
1592 | r->ru_nivcsw += p->signal->nivcsw; | 1581 | r->ru_nivcsw += p->signal->nivcsw; |
1593 | r->ru_minflt += p->signal->min_flt; | 1582 | r->ru_minflt += p->signal->min_flt; |
@@ -1596,7 +1585,7 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) | |||
1596 | r->ru_oublock += p->signal->oublock; | 1585 | r->ru_oublock += p->signal->oublock; |
1597 | t = p; | 1586 | t = p; |
1598 | do { | 1587 | do { |
1599 | accumulate_thread_rusage(t, r, &utime, &stime); | 1588 | accumulate_thread_rusage(t, r); |
1600 | t = next_thread(t); | 1589 | t = next_thread(t); |
1601 | } while (t != p); | 1590 | } while (t != p); |
1602 | break; | 1591 | break; |