7 #include <linux/export.h>
9 #include <linux/utsname.h>
10 #include <linux/mman.h>
11 #include <linux/reboot.h>
16 #include <linux/perf_event.h>
17 #include <linux/resource.h>
18 #include <linux/kernel.h>
19 #include <linux/kexec.h>
21 #include <linux/capability.h>
22 #include <linux/device.h>
29 #include <linux/tty.h>
30 #include <linux/signal.h>
31 #include <linux/cn_proc.h>
34 #include <linux/seccomp.h>
36 #include <linux/personality.h>
37 #include <linux/ptrace.h>
43 #include <linux/version.h>
44 #include <linux/ctype.h>
53 #include <generated/utsrelease.h>
55 #include <asm/uaccess.h>
57 #include <asm/unistd.h>
59 #ifndef SET_UNALIGN_CTL
60 # define SET_UNALIGN_CTL(a,b) (-EINVAL)
62 #ifndef GET_UNALIGN_CTL
63 # define GET_UNALIGN_CTL(a,b) (-EINVAL)
66 # define SET_FPEMU_CTL(a,b) (-EINVAL)
69 # define GET_FPEMU_CTL(a,b) (-EINVAL)
72 # define SET_FPEXC_CTL(a,b) (-EINVAL)
75 # define GET_FPEXC_CTL(a,b) (-EINVAL)
78 # define GET_ENDIAN(a,b) (-EINVAL)
81 # define SET_ENDIAN(a,b) (-EINVAL)
84 # define GET_TSC_CTL(a) (-EINVAL)
87 # define SET_TSC_CTL(a) (-EINVAL)
136 if (uid_eq(pcred->uid, cred->
euid) ||
137 uid_eq(pcred->euid, cred->
euid))
152 if (!set_one_prio_perm(p)) {
200 error = set_one_prio(p, niceval, error);
208 error = set_one_prio(p, niceval, error);
216 else if (!uid_eq(uid, cred->
uid) &&
222 error = set_one_prio(p, niceval, error);
224 if (!uid_eq(uid, cred->
uid))
263 if (niceval > retval)
274 if (niceval > retval)
283 else if (!uid_eq(uid, cred->
uid) &&
290 if (niceval > retval)
294 if (!uid_eq(uid, cred->
uid))
324 usermodehelper_disable();
371 disable_nonboot_cpus();
386 usermodehelper_disable();
415 disable_nonboot_cpus();
483 panic(
"cannot halt");
495 buffer[
sizeof(
buffer) - 1] =
'\0';
502 ret = kernel_kexec();
506 #ifdef CONFIG_HIBERNATION
561 const struct cred *old;
569 if ((
rgid != (
gid_t) -1) && !gid_valid(krgid))
571 if ((
egid != (
gid_t) -1) && !gid_valid(kegid))
581 if (gid_eq(old->
gid, krgid) ||
582 gid_eq(old->
egid, krgid) ||
589 if (gid_eq(old->
gid, kegid) ||
590 gid_eq(old->
egid, kegid) ||
591 gid_eq(old->
sgid, kegid) ||
600 new->sgid =
new->egid;
601 new->fsgid =
new->egid;
618 const struct cred *old;
624 if (!gid_valid(kgid))
634 new->gid =
new->egid =
new->sgid =
new->fsgid = kgid;
635 else if (gid_eq(kgid, old->
gid) || gid_eq(kgid, old->
sgid))
636 new->egid =
new->fsgid = kgid;
650 static int set_user(
struct cred *
new)
672 new->user = new_user;
694 const struct cred *old;
702 if ((ruid != (
uid_t) -1) && !uid_valid(kruid))
704 if ((
euid != (
uid_t) -1) && !uid_valid(keuid))
713 if (ruid != (
uid_t) -1) {
715 if (!uid_eq(old->
uid, kruid) &&
716 !uid_eq(old->
euid, kruid) &&
723 if (!uid_eq(old->
uid, keuid) &&
724 !uid_eq(old->
euid, keuid) &&
725 !uid_eq(old->
suid, keuid) &&
730 if (!uid_eq(new->uid, old->
uid)) {
731 retval = set_user(
new);
735 if (ruid != (
uid_t) -1 ||
737 new->suid =
new->euid;
738 new->fsuid =
new->euid;
765 const struct cred *old;
771 if (!uid_valid(kuid))
781 new->suid =
new->uid = kuid;
782 if (!uid_eq(kuid, old->
uid)) {
783 retval = set_user(
new);
787 }
else if (!uid_eq(kuid, old->
uid) && !uid_eq(kuid, new->suid)) {
791 new->fsuid =
new->euid = kuid;
812 const struct cred *old;
815 kuid_t kruid, keuid, ksuid;
821 if ((ruid != (
uid_t) -1) && !uid_valid(kruid))
824 if ((
euid != (
uid_t) -1) && !uid_valid(keuid))
827 if ((
suid != (
uid_t) -1) && !uid_valid(ksuid))
838 if (ruid != (
uid_t) -1 && !uid_eq(kruid, old->
uid) &&
839 !uid_eq(kruid, old->
euid) && !uid_eq(kruid, old->
suid))
842 !uid_eq(keuid, old->
euid) && !uid_eq(keuid, old->
suid))
845 !uid_eq(ksuid, old->
euid) && !uid_eq(ksuid, old->
suid))
849 if (ruid != (
uid_t) -1) {
851 if (!uid_eq(kruid, old->
uid)) {
852 retval = set_user(
new);
861 new->fsuid =
new->euid;
884 if (!(retval =
put_user(ruid, ruidp)) &&
897 const struct cred *old;
900 kgid_t krgid, kegid, ksgid;
906 if ((
rgid != (
gid_t) -1) && !gid_valid(krgid))
908 if ((
egid != (
gid_t) -1) && !gid_valid(kegid))
910 if ((
sgid != (
gid_t) -1) && !gid_valid(ksgid))
921 !gid_eq(krgid, old->
egid) && !gid_eq(krgid, old->
sgid))
924 !gid_eq(kegid, old->
egid) && !gid_eq(kegid, old->
sgid))
927 !gid_eq(ksgid, old->
egid) && !gid_eq(ksgid, old->
sgid))
937 new->fsgid =
new->egid;
956 if (!(retval =
put_user(rgid, rgidp)) &&
972 const struct cred *old;
981 if (!uid_valid(kuid))
988 if (uid_eq(kuid, old->
uid) || uid_eq(kuid, old->
euid) ||
989 uid_eq(kuid, old->
suid) || uid_eq(kuid, old->
fsuid) ||
991 if (!uid_eq(kuid, old->
fsuid)) {
1011 const struct cred *old;
1020 if (!gid_valid(kgid))
1027 if (gid_eq(kgid, old->
gid) || gid_eq(kgid, old->
egid) ||
1028 gid_eq(kgid, old->
sgid) || gid_eq(kgid, old->
fsgid) ||
1030 if (!gid_eq(kgid, old->
fsgid)) {
1046 cputime_t tgutime, tgstime, cutime, cstime;
1048 spin_lock_irq(&
current->sighand->siglock);
1050 cutime =
current->signal->cutime;
1051 cstime =
current->signal->cstime;
1052 spin_unlock_irq(&
current->sighand->siglock);
1092 pid = task_pid_vnr(group_leader);
1110 if (!thread_group_leader(p))
1113 if (same_thread_group(p->
real_parent, group_leader)) {
1115 if (task_session(p) != task_session(group_leader))
1122 if (p != group_leader)
1136 if (!g || task_session(g) != task_session(group_leader))
1144 if (task_pgrp(p) != pgrp)
1183 #ifdef __ARCH_WANT_SYS_GETPGRP
1206 sid = task_session(p);
1223 struct pid *
sid = task_pid(group_leader);
1229 if (group_leader->
signal->leader)
1238 group_leader->
signal->leader = 1;
1248 sched_autogroup_create_attach(group_leader);
1255 #ifdef COMPAT_UTS_MACHINE
1256 #define override_architecture(name) \
1257 (personality(current->personality) == PER_LINUX32 && \
1258 copy_to_user(name->machine, COMPAT_UTS_MACHINE, \
1259 sizeof(COMPAT_UTS_MACHINE)))
1261 #define override_architecture(name) 0
1268 static int override_release(
char __user *
release,
size_t len)
1273 const char *
rest = UTS_RELEASE;
1274 char buf[65] = { 0 };
1280 if (*rest ==
'.' && ++ndots >= 3)
1282 if (!
isdigit(*rest) && *rest !=
'.')
1286 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
1287 copy =
clamp_t(
size_t, len, 1,
sizeof(buf));
1288 copy =
scnprintf(buf, copy,
"2.6.%u%s", v, rest);
1303 if (!errno && override_release(
name->release,
sizeof(
name->release)))
1310 #ifdef __ARCH_WANT_SYS_OLD_UNAME
1326 if (!error && override_release(
name->release,
sizeof(
name->release)))
1362 if (!error && override_release(
name->release,
sizeof(
name->release)))
1364 return error ? -
EFAULT : 0;
1392 #ifdef __ARCH_WANT_SYS_GETHOSTNAME
1455 #ifdef __ARCH_WANT_SYS_OLD_GETRLIMIT
1462 struct rlimit __user *, rlim)
1468 task_lock(
current->group_leader);
1470 task_unlock(
current->group_leader);
1471 if (
x.rlim_cur > 0x7FFFFFFF)
1472 x.rlim_cur = 0x7FFFFFFF;
1473 if (
x.rlim_max > 0x7FFFFFFF)
1474 x.rlim_max = 0x7FFFFFFF;
1480 static inline bool rlim64_is_infinity(
__u64 rlim64)
1482 #if BITS_PER_LONG < 64
1489 static void rlim_to_rlim64(
const struct rlimit *rlim,
struct rlimit64 *rlim64)
1501 static void rlim64_to_rlim(
const struct rlimit64 *rlim64,
struct rlimit *rlim)
1503 if (rlim64_is_infinity(rlim64->
rlim_cur))
1547 resource, new_rlim);
1572 if (!retval && new_rlim && resource ==
RLIMIT_CPU &&
1589 if (uid_eq(cred->
uid, tcred->euid) &&
1590 uid_eq(cred->
uid, tcred->suid) &&
1591 uid_eq(cred->
uid, tcred->uid) &&
1592 gid_eq(cred->
gid, tcred->egid) &&
1593 gid_eq(cred->
gid, tcred->sgid) &&
1594 gid_eq(cred->
gid, tcred->gid))
1603 const struct rlimit64 __user *, new_rlim,
1604 struct rlimit64 __user *, old_rlim)
1614 rlim64_to_rlim(&new64, &
new);
1623 ret = check_prlimit_permission(tsk);
1632 old_rlim ? &old : NULL);
1634 if (!ret && old_rlim) {
1635 rlim_to_rlim64(&old, &old64);
1640 put_task_struct(tsk);
1699 unsigned long flags;
1701 unsigned long maxrss = 0;
1703 memset((
char *) r, 0,
sizeof *r);
1708 accumulate_thread_rusage(p, r);
1709 maxrss = p->
signal->maxrss;
1713 if (!lock_task_sighand(p, &flags))
1719 utime = p->
signal->cutime;
1720 stime = p->
signal->cstime;
1727 maxrss = p->
signal->cmaxrss;
1742 if (maxrss < p->
signal->maxrss)
1743 maxrss = p->
signal->maxrss;
1746 accumulate_thread_rusage(t, r);
1754 unlock_task_sighand(p, &flags);
1763 setmax_mm_hiwater_rss(&maxrss, mm);
1773 k_getrusage(p, who, &r);
1791 #ifdef CONFIG_CHECKPOINT_RESTORE
1792 static int prctl_set_mm_exe_file(
struct mm_struct *mm,
unsigned int fd)
1802 dentry = exe.file->f_path.dentry;
1811 exe.file->f_path.mnt->mnt_flags &
MNT_NOEXEC)
1829 path_equal(&vma->
vm_file->f_path,
1854 static int prctl_set_mm(
int opt,
unsigned long addr,
1855 unsigned long arg4,
unsigned long arg5)
1869 return prctl_set_mm_exe_file(mm, (
unsigned int)addr);
1894 if (addr <= mm->end_data)
1906 if (addr <= mm->end_data)
1956 if (arg4 >
sizeof(user_auxv))
1985 static int prctl_get_tid_address(
struct task_struct *me,
int __user **tid_addr)
1991 static int prctl_set_mm(
int opt,
unsigned long addr,
1992 unsigned long arg4,
unsigned long arg5)
1996 static int prctl_get_tid_address(
struct task_struct *me,
int __user **tid_addr)
2003 unsigned long, arg4,
unsigned long, arg5)
2006 unsigned char comm[
sizeof(me->
comm)];
2016 if (!valid_signal(
arg2)) {
2029 if (arg2 < 0 || arg2 > 1) {
2064 sizeof(me->
comm) - 1) < 0)
2100 error =
current->timer_slack_ns;
2105 current->default_timer_slack_ns;
2144 error = prctl_set_mm(
arg2,
arg3, arg4, arg5);
2147 error = prctl_get_tid_address(me, (
int __user **)
arg2);
2154 (
int __user *)
arg2);
2157 if (
arg2 != 1 ||
arg3 || arg4 || arg5)
2165 return current->no_new_privs ? 1 : 0;
2182 return err ? -
EFAULT : 0;
2192 static int __orderly_poweroff(
void)
2196 static char *envp[] = {
2198 "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
2206 __func__, poweroff_cmd);
2227 int ret = __orderly_poweroff();
2231 "forcing the issue\n");