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