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.
7 #include <linux/mman.h>
8 #include <linux/notifier.h>
9 #include <linux/reboot.h>
10 #include <linux/prctl.h>
11 #include <linux/capability.h>
12 #include <linux/init.h>
13 #include <linux/highuid.h>
14 #include <linux/security.h>
15 #include <linux/syscalls.h>
17 #include <asm/uaccess.h>
19 SYSCALL_DEFINE3(chown16
, const char __user
*, filename
, old_uid_t
, user
, old_gid_t
, group
)
21 long ret
= sys_chown(filename
, low2highuid(user
), low2highgid(group
));
22 /* avoid REGPARM breakage on x86: */
23 asmlinkage_protect(3, ret
, filename
, user
, group
);
27 SYSCALL_DEFINE3(lchown16
, const char __user
*, filename
, old_uid_t
, user
, old_gid_t
, group
)
29 long ret
= sys_lchown(filename
, low2highuid(user
), low2highgid(group
));
30 /* avoid REGPARM breakage on x86: */
31 asmlinkage_protect(3, ret
, filename
, user
, group
);
35 SYSCALL_DEFINE3(fchown16
, unsigned int, fd
, old_uid_t
, user
, old_gid_t
, group
)
37 long ret
= sys_fchown(fd
, low2highuid(user
), low2highgid(group
));
38 /* avoid REGPARM breakage on x86: */
39 asmlinkage_protect(3, ret
, fd
, user
, group
);
43 SYSCALL_DEFINE2(setregid16
, old_gid_t
, rgid
, old_gid_t
, egid
)
45 long ret
= sys_setregid(low2highgid(rgid
), low2highgid(egid
));
46 /* avoid REGPARM breakage on x86: */
47 asmlinkage_protect(2, ret
, rgid
, egid
);
51 SYSCALL_DEFINE1(setgid16
, old_gid_t
, gid
)
53 long ret
= sys_setgid(low2highgid(gid
));
54 /* avoid REGPARM breakage on x86: */
55 asmlinkage_protect(1, ret
, gid
);
59 SYSCALL_DEFINE2(setreuid16
, old_uid_t
, ruid
, old_uid_t
, euid
)
61 long ret
= sys_setreuid(low2highuid(ruid
), low2highuid(euid
));
62 /* avoid REGPARM breakage on x86: */
63 asmlinkage_protect(2, ret
, ruid
, euid
);
67 SYSCALL_DEFINE1(setuid16
, old_uid_t
, uid
)
69 long ret
= sys_setuid(low2highuid(uid
));
70 /* avoid REGPARM breakage on x86: */
71 asmlinkage_protect(1, ret
, uid
);
75 SYSCALL_DEFINE3(setresuid16
, old_uid_t
, ruid
, old_uid_t
, euid
, old_uid_t
, suid
)
77 long ret
= sys_setresuid(low2highuid(ruid
), low2highuid(euid
),
79 /* avoid REGPARM breakage on x86: */
80 asmlinkage_protect(3, ret
, ruid
, euid
, suid
);
84 SYSCALL_DEFINE3(getresuid16
, old_uid_t __user
*, ruidp
, old_uid_t __user
*, euidp
, old_uid_t __user
*, suidp
)
86 const struct cred
*cred
= current_cred();
88 old_uid_t ruid
, euid
, suid
;
90 ruid
= high2lowuid(from_kuid_munged(cred
->user_ns
, cred
->uid
));
91 euid
= high2lowuid(from_kuid_munged(cred
->user_ns
, cred
->euid
));
92 suid
= high2lowuid(from_kuid_munged(cred
->user_ns
, cred
->suid
));
94 if (!(retval
= put_user(ruid
, ruidp
)) &&
95 !(retval
= put_user(euid
, euidp
)))
96 retval
= put_user(suid
, suidp
);
101 SYSCALL_DEFINE3(setresgid16
, old_gid_t
, rgid
, old_gid_t
, egid
, old_gid_t
, sgid
)
103 long ret
= sys_setresgid(low2highgid(rgid
), low2highgid(egid
),
105 /* avoid REGPARM breakage on x86: */
106 asmlinkage_protect(3, ret
, rgid
, egid
, sgid
);
111 SYSCALL_DEFINE3(getresgid16
, old_gid_t __user
*, rgidp
, old_gid_t __user
*, egidp
, old_gid_t __user
*, sgidp
)
113 const struct cred
*cred
= current_cred();
115 old_gid_t rgid
, egid
, sgid
;
117 rgid
= high2lowgid(from_kgid_munged(cred
->user_ns
, cred
->gid
));
118 egid
= high2lowgid(from_kgid_munged(cred
->user_ns
, cred
->egid
));
119 sgid
= high2lowgid(from_kgid_munged(cred
->user_ns
, cred
->sgid
));
121 if (!(retval
= put_user(rgid
, rgidp
)) &&
122 !(retval
= put_user(egid
, egidp
)))
123 retval
= put_user(sgid
, sgidp
);
128 SYSCALL_DEFINE1(setfsuid16
, old_uid_t
, uid
)
130 long ret
= sys_setfsuid(low2highuid(uid
));
131 /* avoid REGPARM breakage on x86: */
132 asmlinkage_protect(1, ret
, uid
);
136 SYSCALL_DEFINE1(setfsgid16
, old_gid_t
, gid
)
138 long ret
= sys_setfsgid(low2highgid(gid
));
139 /* avoid REGPARM breakage on x86: */
140 asmlinkage_protect(1, ret
, gid
);
144 static int groups16_to_user(old_gid_t __user
*grouplist
,
145 struct group_info
*group_info
)
147 struct user_namespace
*user_ns
= current_user_ns();
152 for (i
= 0; i
< group_info
->ngroups
; i
++) {
153 kgid
= GROUP_AT(group_info
, i
);
154 group
= high2lowgid(from_kgid_munged(user_ns
, kgid
));
155 if (put_user(group
, grouplist
+i
))
162 static int groups16_from_user(struct group_info
*group_info
,
163 old_gid_t __user
*grouplist
)
165 struct user_namespace
*user_ns
= current_user_ns();
170 for (i
= 0; i
< group_info
->ngroups
; i
++) {
171 if (get_user(group
, grouplist
+i
))
174 kgid
= make_kgid(user_ns
, low2highgid(group
));
175 if (!gid_valid(kgid
))
178 GROUP_AT(group_info
, i
) = kgid
;
184 SYSCALL_DEFINE2(getgroups16
, int, gidsetsize
, old_gid_t __user
*, grouplist
)
186 const struct cred
*cred
= current_cred();
192 i
= cred
->group_info
->ngroups
;
194 if (i
> gidsetsize
) {
198 if (groups16_to_user(grouplist
, cred
->group_info
)) {
207 SYSCALL_DEFINE2(setgroups16
, int, gidsetsize
, old_gid_t __user
*, grouplist
)
209 struct group_info
*group_info
;
212 if (!nsown_capable(CAP_SETGID
))
214 if ((unsigned)gidsetsize
> NGROUPS_MAX
)
217 group_info
= groups_alloc(gidsetsize
);
220 retval
= groups16_from_user(group_info
, grouplist
);
222 put_group_info(group_info
);
226 retval
= set_current_groups(group_info
);
227 put_group_info(group_info
);
232 SYSCALL_DEFINE0(getuid16
)
234 return high2lowuid(from_kuid_munged(current_user_ns(), current_uid()));
237 SYSCALL_DEFINE0(geteuid16
)
239 return high2lowuid(from_kuid_munged(current_user_ns(), current_euid()));
242 SYSCALL_DEFINE0(getgid16
)
244 return high2lowgid(from_kgid_munged(current_user_ns(), current_gid()));
247 SYSCALL_DEFINE0(getegid16
)
249 return high2lowgid(from_kgid_munged(current_user_ns(), current_egid()));