aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/uid16.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/uid16.c')
-rw-r--r--kernel/uid16.c196
1 files changed, 196 insertions, 0 deletions
diff --git a/kernel/uid16.c b/kernel/uid16.c
new file mode 100644
index 000000000000..f669941e8b26
--- /dev/null
+++ b/kernel/uid16.c
@@ -0,0 +1,196 @@
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>
9#include <linux/smp_lock.h>
10#include <linux/notifier.h>
11#include <linux/reboot.h>
12#include <linux/prctl.h>
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
20asmlinkage long sys_chown16(const char __user * filename, old_uid_t user, old_gid_t group)
21{
22 return sys_chown(filename, low2highuid(user), low2highgid(group));
23}
24
25asmlinkage long sys_lchown16(const char __user * filename, old_uid_t user, old_gid_t group)
26{
27 return sys_lchown(filename, low2highuid(user), low2highgid(group));
28}
29
30asmlinkage long sys_fchown16(unsigned int fd, old_uid_t user, old_gid_t group)
31{
32 return sys_fchown(fd, low2highuid(user), low2highgid(group));
33}
34
35asmlinkage long sys_setregid16(old_gid_t rgid, old_gid_t egid)
36{
37 return sys_setregid(low2highgid(rgid), low2highgid(egid));
38}
39
40asmlinkage long sys_setgid16(old_gid_t gid)
41{
42 return sys_setgid(low2highgid(gid));
43}
44
45asmlinkage long sys_setreuid16(old_uid_t ruid, old_uid_t euid)
46{
47 return sys_setreuid(low2highuid(ruid), low2highuid(euid));
48}
49
50asmlinkage long sys_setuid16(old_uid_t uid)
51{
52 return sys_setuid(low2highuid(uid));
53}
54
55asmlinkage long sys_setresuid16(old_uid_t ruid, old_uid_t euid, old_uid_t suid)
56{
57 return sys_setresuid(low2highuid(ruid), low2highuid(euid),
58 low2highuid(suid));
59}
60
61asmlinkage long sys_getresuid16(old_uid_t __user *ruid, old_uid_t __user *euid, old_uid_t __user *suid)
62{
63 int retval;
64
65 if (!(retval = put_user(high2lowuid(current->uid), ruid)) &&
66 !(retval = put_user(high2lowuid(current->euid), euid)))
67 retval = put_user(high2lowuid(current->suid), suid);
68
69 return retval;
70}
71
72asmlinkage long sys_setresgid16(old_gid_t rgid, old_gid_t egid, old_gid_t sgid)
73{
74 return sys_setresgid(low2highgid(rgid), low2highgid(egid),
75 low2highgid(sgid));
76}
77
78asmlinkage long sys_getresgid16(old_gid_t __user *rgid, old_gid_t __user *egid, old_gid_t __user *sgid)
79{
80 int retval;
81
82 if (!(retval = put_user(high2lowgid(current->gid), rgid)) &&
83 !(retval = put_user(high2lowgid(current->egid), egid)))
84 retval = put_user(high2lowgid(current->sgid), sgid);
85
86 return retval;
87}
88
89asmlinkage long sys_setfsuid16(old_uid_t uid)
90{
91 return sys_setfsuid(low2highuid(uid));
92}
93
94asmlinkage long sys_setfsgid16(old_gid_t gid)
95{
96 return sys_setfsgid(low2highgid(gid));
97}
98
99static int groups16_to_user(old_gid_t __user *grouplist,
100 struct group_info *group_info)
101{
102 int i;
103 old_gid_t group;
104
105 for (i = 0; i < group_info->ngroups; i++) {
106 group = high2lowgid(GROUP_AT(group_info, i));
107 if (put_user(group, grouplist+i))
108 return -EFAULT;
109 }
110
111 return 0;
112}
113
114static int groups16_from_user(struct group_info *group_info,
115 old_gid_t __user *grouplist)
116{
117 int i;
118 old_gid_t group;
119
120 for (i = 0; i < group_info->ngroups; i++) {
121 if (get_user(group, grouplist+i))
122 return -EFAULT;
123 GROUP_AT(group_info, i) = low2highgid(group);
124 }
125
126 return 0;
127}
128
129asmlinkage long sys_getgroups16(int gidsetsize, old_gid_t __user *grouplist)
130{
131 int i = 0;
132
133 if (gidsetsize < 0)
134 return -EINVAL;
135
136 get_group_info(current->group_info);
137 i = current->group_info->ngroups;
138 if (gidsetsize) {
139 if (i > gidsetsize) {
140 i = -EINVAL;
141 goto out;
142 }
143 if (groups16_to_user(grouplist, current->group_info)) {
144 i = -EFAULT;
145 goto out;
146 }
147 }
148out:
149 put_group_info(current->group_info);
150 return i;
151}
152
153asmlinkage long sys_setgroups16(int gidsetsize, old_gid_t __user *grouplist)
154{
155 struct group_info *group_info;
156 int retval;
157
158 if (!capable(CAP_SETGID))
159 return -EPERM;
160 if ((unsigned)gidsetsize > NGROUPS_MAX)
161 return -EINVAL;
162
163 group_info = groups_alloc(gidsetsize);
164 if (!group_info)
165 return -ENOMEM;
166 retval = groups16_from_user(group_info, grouplist);
167 if (retval) {
168 put_group_info(group_info);
169 return retval;
170 }
171
172 retval = set_current_groups(group_info);
173 put_group_info(group_info);
174
175 return retval;
176}
177
178asmlinkage long sys_getuid16(void)
179{
180 return high2lowuid(current->uid);
181}
182
183asmlinkage long sys_geteuid16(void)
184{
185 return high2lowuid(current->euid);
186}
187
188asmlinkage long sys_getgid16(void)
189{
190 return high2lowgid(current->gid);
191}
192
193asmlinkage long sys_getegid16(void)
194{
195 return high2lowgid(current->egid);
196}