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 | { |
Eric W. Biederman | ae2975b | 2011-11-14 15:56:38 -0800 | [diff] [blame^] | 137 | struct user_namespace *user_ns = current_user_ns(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | int i; |
| 139 | old_gid_t group; |
Eric W. Biederman | ae2975b | 2011-11-14 15:56:38 -0800 | [diff] [blame^] | 140 | kgid_t kgid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | for (i = 0; i < group_info->ngroups; i++) { |
Eric W. Biederman | ae2975b | 2011-11-14 15:56:38 -0800 | [diff] [blame^] | 143 | kgid = GROUP_AT(group_info, i); |
| 144 | group = high2lowgid(from_kgid_munged(user_ns, kgid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | if (put_user(group, grouplist+i)) |
| 146 | return -EFAULT; |
| 147 | } |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | static int groups16_from_user(struct group_info *group_info, |
| 153 | old_gid_t __user *grouplist) |
| 154 | { |
Eric W. Biederman | ae2975b | 2011-11-14 15:56:38 -0800 | [diff] [blame^] | 155 | struct user_namespace *user_ns = current_user_ns(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | int i; |
| 157 | old_gid_t group; |
Eric W. Biederman | ae2975b | 2011-11-14 15:56:38 -0800 | [diff] [blame^] | 158 | kgid_t kgid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
| 160 | for (i = 0; i < group_info->ngroups; i++) { |
| 161 | if (get_user(group, grouplist+i)) |
| 162 | return -EFAULT; |
Eric W. Biederman | ae2975b | 2011-11-14 15:56:38 -0800 | [diff] [blame^] | 163 | |
| 164 | kgid = make_kgid(user_ns, low2highgid(group)); |
| 165 | if (!gid_valid(kgid)) |
| 166 | return -EINVAL; |
| 167 | |
| 168 | GROUP_AT(group_info, i) = kgid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
Heiko Carstens | 003d7ab | 2009-01-14 14:14:21 +0100 | [diff] [blame] | 174 | SYSCALL_DEFINE2(getgroups16, int, gidsetsize, old_gid_t __user *, grouplist) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
David Howells | 86a264a | 2008-11-14 10:39:18 +1100 | [diff] [blame] | 176 | const struct cred *cred = current_cred(); |
| 177 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
| 179 | if (gidsetsize < 0) |
| 180 | return -EINVAL; |
| 181 | |
David Howells | 86a264a | 2008-11-14 10:39:18 +1100 | [diff] [blame] | 182 | i = cred->group_info->ngroups; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | if (gidsetsize) { |
| 184 | if (i > gidsetsize) { |
| 185 | i = -EINVAL; |
| 186 | goto out; |
| 187 | } |
David Howells | 86a264a | 2008-11-14 10:39:18 +1100 | [diff] [blame] | 188 | if (groups16_to_user(grouplist, cred->group_info)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | i = -EFAULT; |
| 190 | goto out; |
| 191 | } |
| 192 | } |
| 193 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | return i; |
| 195 | } |
| 196 | |
Heiko Carstens | 003d7ab | 2009-01-14 14:14:21 +0100 | [diff] [blame] | 197 | SYSCALL_DEFINE2(setgroups16, int, gidsetsize, old_gid_t __user *, grouplist) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | { |
| 199 | struct group_info *group_info; |
| 200 | int retval; |
| 201 | |
Serge E. Hallyn | b0e7759 | 2011-03-23 16:43:24 -0700 | [diff] [blame] | 202 | if (!nsown_capable(CAP_SETGID)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | return -EPERM; |
| 204 | if ((unsigned)gidsetsize > NGROUPS_MAX) |
| 205 | return -EINVAL; |
| 206 | |
| 207 | group_info = groups_alloc(gidsetsize); |
| 208 | if (!group_info) |
| 209 | return -ENOMEM; |
| 210 | retval = groups16_from_user(group_info, grouplist); |
| 211 | if (retval) { |
| 212 | put_group_info(group_info); |
| 213 | return retval; |
| 214 | } |
| 215 | |
| 216 | retval = set_current_groups(group_info); |
| 217 | put_group_info(group_info); |
| 218 | |
| 219 | return retval; |
| 220 | } |
| 221 | |
Heiko Carstens | 003d7ab | 2009-01-14 14:14:21 +0100 | [diff] [blame] | 222 | SYSCALL_DEFINE0(getuid16) |
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 high2lowuid(current_uid()); |
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(geteuid16) |
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 high2lowuid(current_euid()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Heiko Carstens | 003d7ab | 2009-01-14 14:14:21 +0100 | [diff] [blame] | 232 | SYSCALL_DEFINE0(getgid16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { |
David Howells | 86a264a | 2008-11-14 10:39:18 +1100 | [diff] [blame] | 234 | return high2lowgid(current_gid()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Heiko Carstens | 003d7ab | 2009-01-14 14:14:21 +0100 | [diff] [blame] | 237 | SYSCALL_DEFINE0(getegid16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | { |
David Howells | 86a264a | 2008-11-14 10:39:18 +1100 | [diff] [blame] | 239 | return high2lowgid(current_egid()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } |