diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2012-03-05 18:32:11 -0500 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2012-03-05 18:43:45 -0500 |
commit | 55283e2537714f9370c4ab847d170acf223daf90 (patch) | |
tree | e20a2212d4de9d91c4b986a2a8dba5197516213e | |
parent | e7084fd52ed71249ab2ce7a7d89d601c9d1f904c (diff) |
x32: Add ptrace for x32
X32 ptrace is a hybrid of 64bit ptrace and compat ptrace with 32bit
address and longs. It use 64bit ptrace to access the full 64bit
registers. PTRACE_PEEKUSR and PTRACE_POKEUSR are only allowed to access
segment and debug registers. PTRACE_PEEKUSR returns the lower 32bits
and PTRACE_POKEUSR zero-extends 32bit value to 64bit. It works since
the upper 32bits of segment and debug registers of x32 process are always
zero. GDB only uses PTRACE_PEEKUSR and PTRACE_POKEUSR to access
segment and debug registers.
[ hpa: changed TIF_X32 test to use !is_ia32_task() instead, and moved
the system call number to the now-unused 521 slot. ]
Signed-off-by: "H.J. Lu" <hjl.tools@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Roland McGrath <roland@hack.frob.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Link: http://lkml.kernel.org/r/1329696488-16970-1-git-send-email-hpa@zytor.com
-rw-r--r-- | arch/x86/kernel/ptrace.c | 99 | ||||
-rw-r--r-- | arch/x86/syscalls/syscall_64.tbl | 4 |
2 files changed, 101 insertions, 2 deletions
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c index 50267386b766..93e7877a19c4 100644 --- a/arch/x86/kernel/ptrace.c +++ b/arch/x86/kernel/ptrace.c | |||
@@ -1130,6 +1130,100 @@ static int genregs32_set(struct task_struct *target, | |||
1130 | return ret; | 1130 | return ret; |
1131 | } | 1131 | } |
1132 | 1132 | ||
1133 | #ifdef CONFIG_X86_X32_ABI | ||
1134 | static long x32_arch_ptrace(struct task_struct *child, | ||
1135 | compat_long_t request, compat_ulong_t caddr, | ||
1136 | compat_ulong_t cdata) | ||
1137 | { | ||
1138 | unsigned long addr = caddr; | ||
1139 | unsigned long data = cdata; | ||
1140 | void __user *datap = compat_ptr(data); | ||
1141 | int ret; | ||
1142 | |||
1143 | switch (request) { | ||
1144 | /* Read 32bits at location addr in the USER area. Only allow | ||
1145 | to return the lower 32bits of segment and debug registers. */ | ||
1146 | case PTRACE_PEEKUSR: { | ||
1147 | u32 tmp; | ||
1148 | |||
1149 | ret = -EIO; | ||
1150 | if ((addr & (sizeof(data) - 1)) || addr >= sizeof(struct user) || | ||
1151 | addr < offsetof(struct user_regs_struct, cs)) | ||
1152 | break; | ||
1153 | |||
1154 | tmp = 0; /* Default return condition */ | ||
1155 | if (addr < sizeof(struct user_regs_struct)) | ||
1156 | tmp = getreg(child, addr); | ||
1157 | else if (addr >= offsetof(struct user, u_debugreg[0]) && | ||
1158 | addr <= offsetof(struct user, u_debugreg[7])) { | ||
1159 | addr -= offsetof(struct user, u_debugreg[0]); | ||
1160 | tmp = ptrace_get_debugreg(child, addr / sizeof(data)); | ||
1161 | } | ||
1162 | ret = put_user(tmp, (__u32 __user *)datap); | ||
1163 | break; | ||
1164 | } | ||
1165 | |||
1166 | /* Write the word at location addr in the USER area. Only allow | ||
1167 | to update segment and debug registers with the upper 32bits | ||
1168 | zero-extended. */ | ||
1169 | case PTRACE_POKEUSR: | ||
1170 | ret = -EIO; | ||
1171 | if ((addr & (sizeof(data) - 1)) || addr >= sizeof(struct user) || | ||
1172 | addr < offsetof(struct user_regs_struct, cs)) | ||
1173 | break; | ||
1174 | |||
1175 | if (addr < sizeof(struct user_regs_struct)) | ||
1176 | ret = putreg(child, addr, data); | ||
1177 | else if (addr >= offsetof(struct user, u_debugreg[0]) && | ||
1178 | addr <= offsetof(struct user, u_debugreg[7])) { | ||
1179 | addr -= offsetof(struct user, u_debugreg[0]); | ||
1180 | ret = ptrace_set_debugreg(child, | ||
1181 | addr / sizeof(data), data); | ||
1182 | } | ||
1183 | break; | ||
1184 | |||
1185 | case PTRACE_GETREGS: /* Get all gp regs from the child. */ | ||
1186 | return copy_regset_to_user(child, | ||
1187 | task_user_regset_view(current), | ||
1188 | REGSET_GENERAL, | ||
1189 | 0, sizeof(struct user_regs_struct), | ||
1190 | datap); | ||
1191 | |||
1192 | case PTRACE_SETREGS: /* Set all gp regs in the child. */ | ||
1193 | return copy_regset_from_user(child, | ||
1194 | task_user_regset_view(current), | ||
1195 | REGSET_GENERAL, | ||
1196 | 0, sizeof(struct user_regs_struct), | ||
1197 | datap); | ||
1198 | |||
1199 | case PTRACE_GETFPREGS: /* Get the child FPU state. */ | ||
1200 | return copy_regset_to_user(child, | ||
1201 | task_user_regset_view(current), | ||
1202 | REGSET_FP, | ||
1203 | 0, sizeof(struct user_i387_struct), | ||
1204 | datap); | ||
1205 | |||
1206 | case PTRACE_SETFPREGS: /* Set the child FPU state. */ | ||
1207 | return copy_regset_from_user(child, | ||
1208 | task_user_regset_view(current), | ||
1209 | REGSET_FP, | ||
1210 | 0, sizeof(struct user_i387_struct), | ||
1211 | datap); | ||
1212 | |||
1213 | /* normal 64bit interface to access TLS data. | ||
1214 | Works just like arch_prctl, except that the arguments | ||
1215 | are reversed. */ | ||
1216 | case PTRACE_ARCH_PRCTL: | ||
1217 | return do_arch_prctl(child, data, addr); | ||
1218 | |||
1219 | default: | ||
1220 | return compat_ptrace_request(child, request, addr, data); | ||
1221 | } | ||
1222 | |||
1223 | return ret; | ||
1224 | } | ||
1225 | #endif | ||
1226 | |||
1133 | long compat_arch_ptrace(struct task_struct *child, compat_long_t request, | 1227 | long compat_arch_ptrace(struct task_struct *child, compat_long_t request, |
1134 | compat_ulong_t caddr, compat_ulong_t cdata) | 1228 | compat_ulong_t caddr, compat_ulong_t cdata) |
1135 | { | 1229 | { |
@@ -1139,6 +1233,11 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, | |||
1139 | int ret; | 1233 | int ret; |
1140 | __u32 val; | 1234 | __u32 val; |
1141 | 1235 | ||
1236 | #ifdef CONFIG_X86_X32_ABI | ||
1237 | if (!is_ia32_task()) | ||
1238 | return x32_arch_ptrace(child, request, caddr, cdata); | ||
1239 | #endif | ||
1240 | |||
1142 | switch (request) { | 1241 | switch (request) { |
1143 | case PTRACE_PEEKUSR: | 1242 | case PTRACE_PEEKUSR: |
1144 | ret = getreg32(child, addr, &val); | 1243 | ret = getreg32(child, addr, &val); |
diff --git a/arch/x86/syscalls/syscall_64.tbl b/arch/x86/syscalls/syscall_64.tbl index 0d778b800884..dd29a9ea27c5 100644 --- a/arch/x86/syscalls/syscall_64.tbl +++ b/arch/x86/syscalls/syscall_64.tbl | |||
@@ -107,7 +107,7 @@ | |||
107 | 98 common getrusage sys_getrusage | 107 | 98 common getrusage sys_getrusage |
108 | 99 common sysinfo sys_sysinfo | 108 | 99 common sysinfo sys_sysinfo |
109 | 100 common times sys_times | 109 | 100 common times sys_times |
110 | 101 common ptrace sys_ptrace | 110 | 101 64 ptrace sys_ptrace |
111 | 102 common getuid sys_getuid | 111 | 102 common getuid sys_getuid |
112 | 103 common syslog sys_syslog | 112 | 103 common syslog sys_syslog |
113 | 104 common getgid sys_getgid | 113 | 104 common getgid sys_getgid |
@@ -331,7 +331,7 @@ | |||
331 | 518 x32 sendmsg compat_sys_sendmsg | 331 | 518 x32 sendmsg compat_sys_sendmsg |
332 | 519 x32 recvmsg compat_sys_recvmsg | 332 | 519 x32 recvmsg compat_sys_recvmsg |
333 | 520 x32 execve stub_x32_execve | 333 | 520 x32 execve stub_x32_execve |
334 | # 521 available | 334 | 521 x32 ptrace compat_sys_ptrace |
335 | 522 x32 rt_sigpending sys32_rt_sigpending | 335 | 522 x32 rt_sigpending sys32_rt_sigpending |
336 | 523 x32 rt_sigtimedwait compat_sys_rt_sigtimedwait | 336 | 523 x32 rt_sigtimedwait compat_sys_rt_sigtimedwait |
337 | 524 x32 rt_sigqueueinfo sys32_rt_sigqueueinfo | 337 | 524 x32 rt_sigqueueinfo sys32_rt_sigqueueinfo |