Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Wrapper functions for 16bit uid back compatibility. All nicely tied |
| 3 | * together in the faint hope we can take the out in five years time. |
| 4 | */ |
| 5 | |
| 6 | #include <linux/mm.h> |
| 7 | #include <linux/utsname.h> |
| 8 | #include <linux/mman.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/notifier.h> |
| 10 | #include <linux/reboot.h> |
| 11 | #include <linux/prctl.h> |
Randy.Dunlap | c59ede7 | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 12 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/init.h> |
| 14 | #include <linux/highuid.h> |
| 15 | #include <linux/security.h> |
| 16 | #include <linux/syscalls.h> |
| 17 | |
| 18 | #include <asm/uaccess.h> |
| 19 | |
Heiko Carstens | ca013e9 | 2009-01-14 14:14:19 +0100 | [diff] [blame] | 20 | SYSCALL_DEFINE3(chown16, const char __user *, filename, old_uid_t, user, old_gid_t, group) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | { |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 22 | long ret = sys_chown(filename, low2highuid(user), low2highgid(group)); |
| 23 | /* avoid REGPARM breakage on x86: */ |
Roland McGrath | 54a0151 | 2008-04-10 15:37:38 -0700 | [diff] [blame] | 24 | asmlinkage_protect(3, ret, filename, user, group); |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 25 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | } |
| 27 | |
Heiko Carstens | ca013e9 | 2009-01-14 14:14:19 +0100 | [diff] [blame] | 28 | SYSCALL_DEFINE3(lchown16, const char __user *, filename, old_uid_t, user, old_gid_t, group) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | { |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 30 | long ret = sys_lchown(filename, low2highuid(user), low2highgid(group)); |
| 31 | /* avoid REGPARM breakage on x86: */ |
Roland McGrath | 54a0151 | 2008-04-10 15:37:38 -0700 | [diff] [blame] | 32 | asmlinkage_protect(3, ret, filename, user, group); |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 33 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Heiko Carstens | ca013e9 | 2009-01-14 14:14:19 +0100 | [diff] [blame] | 36 | SYSCALL_DEFINE3(fchown16, unsigned int, fd, old_uid_t, user, old_gid_t, group) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 38 | long ret = sys_fchown(fd, low2highuid(user), low2highgid(group)); |
| 39 | /* avoid REGPARM breakage on x86: */ |
Roland McGrath | 54a0151 | 2008-04-10 15:37:38 -0700 | [diff] [blame] | 40 | asmlinkage_protect(3, ret, fd, user, group); |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 41 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Heiko Carstens | a6b42e8 | 2009-01-14 14:14:20 +0100 | [diff] [blame] | 44 | SYSCALL_DEFINE2(setregid16, old_gid_t, rgid, old_gid_t, egid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 46 | long ret = sys_setregid(low2highgid(rgid), low2highgid(egid)); |
| 47 | /* avoid REGPARM breakage on x86: */ |
Roland McGrath | 54a0151 | 2008-04-10 15:37:38 -0700 | [diff] [blame] | 48 | asmlinkage_protect(2, ret, rgid, egid); |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 49 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Heiko Carstens | a6b42e8 | 2009-01-14 14:14:20 +0100 | [diff] [blame] | 52 | SYSCALL_DEFINE1(setgid16, old_gid_t, gid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | { |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 54 | long ret = sys_setgid(low2highgid(gid)); |
| 55 | /* avoid REGPARM breakage on x86: */ |
Roland McGrath | 54a0151 | 2008-04-10 15:37:38 -0700 | [diff] [blame] | 56 | asmlinkage_protect(1, ret, gid); |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 57 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Heiko Carstens | a6b42e8 | 2009-01-14 14:14:20 +0100 | [diff] [blame] | 60 | SYSCALL_DEFINE2(setreuid16, old_uid_t, ruid, old_uid_t, euid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 62 | long ret = sys_setreuid(low2highuid(ruid), low2highuid(euid)); |
| 63 | /* avoid REGPARM breakage on x86: */ |
Roland McGrath | 54a0151 | 2008-04-10 15:37:38 -0700 | [diff] [blame] | 64 | asmlinkage_protect(2, ret, ruid, euid); |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 65 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Heiko Carstens | a6b42e8 | 2009-01-14 14:14:20 +0100 | [diff] [blame] | 68 | SYSCALL_DEFINE1(setuid16, old_uid_t, uid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 70 | long ret = sys_setuid(low2highuid(uid)); |
| 71 | /* avoid REGPARM breakage on x86: */ |
Roland McGrath | 54a0151 | 2008-04-10 15:37:38 -0700 | [diff] [blame] | 72 | asmlinkage_protect(1, ret, uid); |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 73 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Heiko Carstens | a6b42e8 | 2009-01-14 14:14:20 +0100 | [diff] [blame] | 76 | SYSCALL_DEFINE3(setresuid16, old_uid_t, ruid, old_uid_t, euid, old_uid_t, suid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 78 | long ret = sys_setresuid(low2highuid(ruid), low2highuid(euid), |
| 79 | low2highuid(suid)); |
| 80 | /* avoid REGPARM breakage on x86: */ |
Roland McGrath | 54a0151 | 2008-04-10 15:37:38 -0700 | [diff] [blame] | 81 | asmlinkage_protect(3, ret, ruid, euid, suid); |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 82 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Heiko Carstens | a6b42e8 | 2009-01-14 14:14:20 +0100 | [diff] [blame] | 85 | SYSCALL_DEFINE3(getresuid16, old_uid_t __user *, ruid, old_uid_t __user *, euid, old_uid_t __user *, suid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
David Howells | 86a264a | 2008-11-14 10:39:18 +1100 | [diff] [blame] | 87 | const struct cred *cred = current_cred(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | int retval; |
| 89 | |
David Howells | 86a264a | 2008-11-14 10:39:18 +1100 | [diff] [blame] | 90 | if (!(retval = put_user(high2lowuid(cred->uid), ruid)) && |
| 91 | !(retval = put_user(high2lowuid(cred->euid), euid))) |
| 92 | retval = put_user(high2lowuid(cred->suid), suid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | return retval; |
| 95 | } |
| 96 | |
Heiko Carstens | a6b42e8 | 2009-01-14 14:14:20 +0100 | [diff] [blame] | 97 | SYSCALL_DEFINE3(setresgid16, old_gid_t, rgid, old_gid_t, egid, old_gid_t, sgid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 99 | long ret = sys_setresgid(low2highgid(rgid), low2highgid(egid), |
| 100 | low2highgid(sgid)); |
| 101 | /* avoid REGPARM breakage on x86: */ |
Roland McGrath | 54a0151 | 2008-04-10 15:37:38 -0700 | [diff] [blame] | 102 | asmlinkage_protect(3, ret, rgid, egid, sgid); |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 103 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Heiko Carstens | a6b42e8 | 2009-01-14 14:14:20 +0100 | [diff] [blame] | 106 | |
| 107 | SYSCALL_DEFINE3(getresgid16, old_gid_t __user *, rgid, old_gid_t __user *, egid, old_gid_t __user *, sgid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { |
David Howells | 86a264a | 2008-11-14 10:39:18 +1100 | [diff] [blame] | 109 | const struct cred *cred = current_cred(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | int retval; |
| 111 | |
David Howells | 86a264a | 2008-11-14 10:39:18 +1100 | [diff] [blame] | 112 | if (!(retval = put_user(high2lowgid(cred->gid), rgid)) && |
| 113 | !(retval = put_user(high2lowgid(cred->egid), egid))) |
| 114 | retval = put_user(high2lowgid(cred->sgid), sgid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
| 116 | return retval; |
| 117 | } |
| 118 | |
Heiko Carstens | a6b42e8 | 2009-01-14 14:14:20 +0100 | [diff] [blame] | 119 | SYSCALL_DEFINE1(setfsuid16, old_uid_t, uid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 121 | long ret = sys_setfsuid(low2highuid(uid)); |
| 122 | /* avoid REGPARM breakage on x86: */ |
Roland McGrath | 54a0151 | 2008-04-10 15:37:38 -0700 | [diff] [blame] | 123 | asmlinkage_protect(1, ret, uid); |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 124 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Heiko Carstens | a6b42e8 | 2009-01-14 14:14:20 +0100 | [diff] [blame] | 127 | SYSCALL_DEFINE1(setfsgid16, old_gid_t, gid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 129 | long ret = sys_setfsgid(low2highgid(gid)); |
| 130 | /* avoid REGPARM breakage on x86: */ |
Roland McGrath | 54a0151 | 2008-04-10 15:37:38 -0700 | [diff] [blame] | 131 | asmlinkage_protect(1, ret, gid); |
OGAWA Hirofumi | 5a7b46b | 2006-04-20 06:41:39 +0900 | [diff] [blame] | 132 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | static int groups16_to_user(old_gid_t __user *grouplist, |
| 136 | struct group_info *group_info) |
| 137 | { |
| 138 | int i; |
| 139 | old_gid_t group; |
| 140 | |
| 141 | for (i = 0; i < group_info->ngroups; i++) { |
| 142 | group = high2lowgid(GROUP_AT(group_info, i)); |
| 143 | if (put_user(group, grouplist+i)) |
| 144 | return -EFAULT; |
| 145 | } |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | static int groups16_from_user(struct group_info *group_info, |
| 151 | old_gid_t __user *grouplist) |
| 152 | { |
| 153 | int i; |
| 154 | old_gid_t group; |
| 155 | |
| 156 | for (i = 0; i < group_info->ngroups; i++) { |
| 157 | if (get_user(group, grouplist+i)) |
| 158 | return -EFAULT; |
| 159 | GROUP_AT(group_info, i) = low2highgid(group); |
| 160 | } |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
Heiko Carstens | 003d7ab | 2009-01-14 14:14:21 +0100 | [diff] [blame] | 165 | SYSCALL_DEFINE2(getgroups16, int, gidsetsize, old_gid_t __user *, grouplist) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { |
David Howells | 86a264a | 2008-11-14 10:39:18 +1100 | [diff] [blame] | 167 | const struct cred *cred = current_cred(); |
| 168 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | if (gidsetsize < 0) |
| 171 | return -EINVAL; |
| 172 | |
David Howells | 86a264a | 2008-11-14 10:39:18 +1100 | [diff] [blame] | 173 | i = cred->group_info->ngroups; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | if (gidsetsize) { |
| 175 | if (i > gidsetsize) { |
| 176 | i = -EINVAL; |
| 177 | goto out; |
| 178 | } |
David Howells | 86a264a | 2008-11-14 10:39:18 +1100 | [diff] [blame] | 179 | if (groups16_to_user(grouplist, cred->group_info)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | i = -EFAULT; |
| 181 | goto out; |
| 182 | } |
| 183 | } |
| 184 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | return i; |
| 186 | } |
| 187 | |
Heiko Carstens | 003d7ab | 2009-01-14 14:14:21 +0100 | [diff] [blame] | 188 | SYSCALL_DEFINE2(setgroups16, int, gidsetsize, old_gid_t __user *, grouplist) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | { |
| 190 | struct group_info *group_info; |
| 191 | int retval; |
| 192 | |
| 193 | if (!capable(CAP_SETGID)) |
| 194 | return -EPERM; |
| 195 | if ((unsigned)gidsetsize > NGROUPS_MAX) |
| 196 | return -EINVAL; |
| 197 | |
| 198 | group_info = groups_alloc(gidsetsize); |
| 199 | if (!group_info) |
| 200 | return -ENOMEM; |
| 201 | retval = groups16_from_user(group_info, grouplist); |
| 202 | if (retval) { |
| 203 | put_group_info(group_info); |
| 204 | return retval; |
| 205 | } |
| 206 | |
| 207 | retval = set_current_groups(group_info); |
| 208 | put_group_info(group_info); |
| 209 | |
| 210 | return retval; |
| 211 | } |
| 212 | |
Heiko Carstens | 003d7ab | 2009-01-14 14:14:21 +0100 | [diff] [blame] | 213 | SYSCALL_DEFINE0(getuid16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
David Howells | 86a264a | 2008-11-14 10:39:18 +1100 | [diff] [blame] | 215 | return high2lowuid(current_uid()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Heiko Carstens | 003d7ab | 2009-01-14 14:14:21 +0100 | [diff] [blame] | 218 | SYSCALL_DEFINE0(geteuid16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | { |
David Howells | 86a264a | 2008-11-14 10:39:18 +1100 | [diff] [blame] | 220 | return high2lowuid(current_euid()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Heiko Carstens | 003d7ab | 2009-01-14 14:14:21 +0100 | [diff] [blame] | 223 | SYSCALL_DEFINE0(getgid16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | { |
David Howells | 86a264a | 2008-11-14 10:39:18 +1100 | [diff] [blame] | 225 | return high2lowgid(current_gid()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Heiko Carstens | 003d7ab | 2009-01-14 14:14:21 +0100 | [diff] [blame] | 228 | SYSCALL_DEFINE0(getegid16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | { |
David Howells | 86a264a | 2008-11-14 10:39:18 +1100 | [diff] [blame] | 230 | return high2lowgid(current_egid()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |