Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. A simplified version of the patch follows (The original is 176df245 in linus’s git repository) Note that this patch was applied to v2.6.22 – These files have moved around, so pull out an older kernel if you’re trying to follow along at home:
  2.  
  3. --- a/arch/x86_64/ia32/ia32entry.S
  4. +++ b/arch/x86_64/ia32/ia32entry.S
  5. @@ -38,6 +38,18 @@
  6.         movq    %rax,R8(%rsp)
  7.         .endm
  8.  
  9. +       .macro LOAD_ARGS32 offset
  10. +       movl \offset(%rsp),%r11d
  11. +       movl \offset+8(%rsp),%r10d
  12. +       movl \offset+16(%rsp),%r9d
  13. +       movl \offset+24(%rsp),%r8d
  14. +       movl \offset+40(%rsp),%ecx
  15. +       movl \offset+48(%rsp),%edx
  16. +       movl \offset+56(%rsp),%esi
  17. +       movl \offset+64(%rsp),%edi
  18. +       movl \offset+72(%rsp),%eax
  19. +       .endm
  20. @@ -334,7 +346,7 @@ ia32_tracesys:
  21.         movq $-ENOSYS,RAX(%rsp) /* really needed? */
  22.         movq %rsp,%rdi        /* &pt_regs -> arg1 */
  23.        call syscall_trace_enter
  24. -       LOAD_ARGS ARGOFFSET  /* reload args from stack in case ptrace changed it */
  25. +       LOAD_ARGS32 ARGOFFSET  /* reload args from stack in case ptrace changed it */
  26.        RESTORE_REST
  27.        jmp ia32_do_syscall
  28. END(ia32_syscall)
  29.  
  30. The patch defines the IA32_LOAD_ARGS macro, and replaces LOAD_ARGS with it in several places (I’ve only shown one for simplicity). LOAD_ARGS32 differs only slightly from the LOAD_ARGS macro that it is replacing, which is defined in include/asm-x86_64/calling.h:
  31.  
  32. .macro LOAD_ARGS offset
  33. movq \offset(%rsp),%r11
  34. movq \offset+8(%rsp),%r10
  35. movq \offset+16(%rsp),%r9
  36. movq \offset+24(%rsp),%r8
  37. movq \offset+40(%rsp),%rcx
  38. movq \offset+48(%rsp),%rdx
  39. movq \offset+56(%rsp),%rsi
  40. movq \offset+64(%rsp),%rdi
  41. movq \offset+72(%rsp),%rax
  42. .endm
  43.  
  44. As the name suggests, LOAD_ARGS32 loads the registers from the stack as 32-bit values, rather than 64-bit. Importantly, in doing so it takes advantage of a quirk in the x86_64 architecture, that causes the top 32 bits of the registers to be zeroed if you write to the 32-bit versions. LOAD_ARGS32 thus zero-extends the 32-bit values it loads into the 64-bit registers.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement