uid16.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. #include <linux/mm.h>
  6. #include <linux/mman.h>
  7. #include <linux/notifier.h>
  8. #include <linux/reboot.h>
  9. #include <linux/prctl.h>
  10. #include <linux/capability.h>
  11. #include <linux/init.h>
  12. #include <linux/highuid.h>
  13. #include <linux/security.h>
  14. #include <linux/syscalls.h>
  15. #include <asm/uaccess.h>
  16. SYSCALL_DEFINE3(chown16, const char __user *, filename, old_uid_t, user, old_gid_t, group)
  17. {
  18. long ret = sys_chown(filename, low2highuid(user), low2highgid(group));
  19. /* avoid REGPARM breakage on x86: */
  20. asmlinkage_protect(3, ret, filename, user, group);
  21. return ret;
  22. }
  23. SYSCALL_DEFINE3(lchown16, const char __user *, filename, old_uid_t, user, old_gid_t, group)
  24. {
  25. long ret = sys_lchown(filename, low2highuid(user), low2highgid(group));
  26. /* avoid REGPARM breakage on x86: */
  27. asmlinkage_protect(3, ret, filename, user, group);
  28. return ret;
  29. }
  30. SYSCALL_DEFINE3(fchown16, unsigned int, fd, old_uid_t, user, old_gid_t, group)
  31. {
  32. long ret = sys_fchown(fd, low2highuid(user), low2highgid(group));
  33. /* avoid REGPARM breakage on x86: */
  34. asmlinkage_protect(3, ret, fd, user, group);
  35. return ret;
  36. }
  37. SYSCALL_DEFINE2(setregid16, old_gid_t, rgid, old_gid_t, egid)
  38. {
  39. long ret = sys_setregid(low2highgid(rgid), low2highgid(egid));
  40. /* avoid REGPARM breakage on x86: */
  41. asmlinkage_protect(2, ret, rgid, egid);
  42. return ret;
  43. }
  44. SYSCALL_DEFINE1(setgid16, old_gid_t, gid)
  45. {
  46. long ret = sys_setgid(low2highgid(gid));
  47. /* avoid REGPARM breakage on x86: */
  48. asmlinkage_protect(1, ret, gid);
  49. return ret;
  50. }
  51. SYSCALL_DEFINE2(setreuid16, old_uid_t, ruid, old_uid_t, euid)
  52. {
  53. long ret = sys_setreuid(low2highuid(ruid), low2highuid(euid));
  54. /* avoid REGPARM breakage on x86: */
  55. asmlinkage_protect(2, ret, ruid, euid);
  56. return ret;
  57. }
  58. SYSCALL_DEFINE1(setuid16, old_uid_t, uid)
  59. {
  60. long ret = sys_setuid(low2highuid(uid));
  61. /* avoid REGPARM breakage on x86: */
  62. asmlinkage_protect(1, ret, uid);
  63. return ret;
  64. }
  65. SYSCALL_DEFINE3(setresuid16, old_uid_t, ruid, old_uid_t, euid, old_uid_t, suid)
  66. {
  67. long ret = sys_setresuid(low2highuid(ruid), low2highuid(euid),
  68. low2highuid(suid));
  69. /* avoid REGPARM breakage on x86: */
  70. asmlinkage_protect(3, ret, ruid, euid, suid);
  71. return ret;
  72. }
  73. SYSCALL_DEFINE3(getresuid16, old_uid_t __user *, ruid, old_uid_t __user *, euid, old_uid_t __user *, suid)
  74. {
  75. const struct cred *cred = current_cred();
  76. int retval;
  77. if (!(retval = put_user(high2lowuid(cred->uid), ruid)) &&
  78. !(retval = put_user(high2lowuid(cred->euid), euid)))
  79. retval = put_user(high2lowuid(cred->suid), suid);
  80. return retval;
  81. }
  82. SYSCALL_DEFINE3(setresgid16, old_gid_t, rgid, old_gid_t, egid, old_gid_t, sgid)
  83. {
  84. long ret = sys_setresgid(low2highgid(rgid), low2highgid(egid),
  85. low2highgid(sgid));
  86. /* avoid REGPARM breakage on x86: */
  87. asmlinkage_protect(3, ret, rgid, egid, sgid);
  88. return ret;
  89. }
  90. SYSCALL_DEFINE3(getresgid16, old_gid_t __user *, rgid, old_gid_t __user *, egid, old_gid_t __user *, sgid)
  91. {
  92. const struct cred *cred = current_cred();
  93. int retval;
  94. if (!(retval = put_user(high2lowgid(cred->gid), rgid)) &&
  95. !(retval = put_user(high2lowgid(cred->egid), egid)))
  96. retval = put_user(high2lowgid(cred->sgid), sgid);
  97. return retval;
  98. }
  99. SYSCALL_DEFINE1(setfsuid16, old_uid_t, uid)
  100. {
  101. long ret = sys_setfsuid(low2highuid(uid));
  102. /* avoid REGPARM breakage on x86: */
  103. asmlinkage_protect(1, ret, uid);
  104. return ret;
  105. }
  106. SYSCALL_DEFINE1(setfsgid16, old_gid_t, gid)
  107. {
  108. long ret = sys_setfsgid(low2highgid(gid));
  109. /* avoid REGPARM breakage on x86: */
  110. asmlinkage_protect(1, ret, gid);
  111. return ret;
  112. }
  113. static int groups16_to_user(old_gid_t __user *grouplist,
  114. struct group_info *group_info)
  115. {
  116. int i;
  117. old_gid_t group;
  118. for (i = 0; i < group_info->ngroups; i++) {
  119. group = high2lowgid(GROUP_AT(group_info, i));
  120. if (put_user(group, grouplist+i))
  121. return -EFAULT;
  122. }
  123. return 0;
  124. }
  125. static int groups16_from_user(struct group_info *group_info,
  126. old_gid_t __user *grouplist)
  127. {
  128. int i;
  129. old_gid_t group;
  130. for (i = 0; i < group_info->ngroups; i++) {
  131. if (get_user(group, grouplist+i))
  132. return -EFAULT;
  133. GROUP_AT(group_info, i) = low2highgid(group);
  134. }
  135. return 0;
  136. }
  137. SYSCALL_DEFINE2(getgroups16, int, gidsetsize, old_gid_t __user *, grouplist)
  138. {
  139. const struct cred *cred = current_cred();
  140. int i;
  141. if (gidsetsize < 0)
  142. return -EINVAL;
  143. i = cred->group_info->ngroups;
  144. if (gidsetsize) {
  145. if (i > gidsetsize) {
  146. i = -EINVAL;
  147. goto out;
  148. }
  149. if (groups16_to_user(grouplist, cred->group_info)) {
  150. i = -EFAULT;
  151. goto out;
  152. }
  153. }
  154. out:
  155. return i;
  156. }
  157. SYSCALL_DEFINE2(setgroups16, int, gidsetsize, old_gid_t __user *, grouplist)
  158. {
  159. struct group_info *group_info;
  160. int retval;
  161. if (!nsown_capable(CAP_SETGID))
  162. return -EPERM;
  163. if ((unsigned)gidsetsize > NGROUPS_MAX)
  164. return -EINVAL;
  165. group_info = groups_alloc(gidsetsize);
  166. if (!group_info)
  167. return -ENOMEM;
  168. retval = groups16_from_user(group_info, grouplist);
  169. if (retval) {
  170. put_group_info(group_info);
  171. return retval;
  172. }
  173. retval = set_current_groups(group_info);
  174. put_group_info(group_info);
  175. return retval;
  176. }
  177. SYSCALL_DEFINE0(getuid16)
  178. {
  179. return high2lowuid(current_uid());
  180. }
  181. SYSCALL_DEFINE0(geteuid16)
  182. {
  183. return high2lowuid(current_euid());
  184. }
  185. SYSCALL_DEFINE0(getgid16)
  186. {
  187. return high2lowgid(current_gid());
  188. }
  189. SYSCALL_DEFINE0(getegid16)
  190. {
  191. return high2lowgid(current_egid());
  192. }