getuser.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * __get_user functions.
  3. *
  4. * (C) Copyright 1998 Linus Torvalds
  5. * (C) Copyright 2005 Andi Kleen
  6. * (C) Copyright 2008 Glauber Costa
  7. *
  8. * These functions have a non-standard call interface
  9. * to make them more efficient, especially as they
  10. * return an error value in addition to the "real"
  11. * return value.
  12. */
  13. /*
  14. * __get_user_X
  15. *
  16. * Inputs: %[r|e]ax contains the address.
  17. *
  18. * Outputs: %[r|e]ax is error code (0 or -EFAULT)
  19. * %[r|e]dx contains zero-extended value
  20. * %ecx contains the high half for 32-bit __get_user_8
  21. *
  22. *
  23. * These functions should not modify any other registers,
  24. * as they get called from within inline assembly.
  25. */
  26. #include <linux/linkage.h>
  27. #include <asm/page_types.h>
  28. #include <asm/errno.h>
  29. #include <asm/asm-offsets.h>
  30. #include <asm/thread_info.h>
  31. #include <asm/asm.h>
  32. #include <asm/smap.h>
  33. .text
  34. ENTRY(__get_user_1)
  35. GET_THREAD_INFO(%_ASM_DX)
  36. cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
  37. jae bad_get_user
  38. sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
  39. and %_ASM_DX, %_ASM_AX
  40. ASM_STAC
  41. 1: movzbl (%_ASM_AX),%edx
  42. xor %eax,%eax
  43. ASM_CLAC
  44. ret
  45. ENDPROC(__get_user_1)
  46. ENTRY(__get_user_2)
  47. add $1,%_ASM_AX
  48. jc bad_get_user
  49. GET_THREAD_INFO(%_ASM_DX)
  50. cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
  51. jae bad_get_user
  52. sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
  53. and %_ASM_DX, %_ASM_AX
  54. ASM_STAC
  55. 2: movzwl -1(%_ASM_AX),%edx
  56. xor %eax,%eax
  57. ASM_CLAC
  58. ret
  59. ENDPROC(__get_user_2)
  60. ENTRY(__get_user_4)
  61. add $3,%_ASM_AX
  62. jc bad_get_user
  63. GET_THREAD_INFO(%_ASM_DX)
  64. cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
  65. jae bad_get_user
  66. sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
  67. and %_ASM_DX, %_ASM_AX
  68. ASM_STAC
  69. 3: movl -3(%_ASM_AX),%edx
  70. xor %eax,%eax
  71. ASM_CLAC
  72. ret
  73. ENDPROC(__get_user_4)
  74. ENTRY(__get_user_8)
  75. #ifdef CONFIG_X86_64
  76. add $7,%_ASM_AX
  77. jc bad_get_user
  78. GET_THREAD_INFO(%_ASM_DX)
  79. cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
  80. jae bad_get_user
  81. sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
  82. and %_ASM_DX, %_ASM_AX
  83. ASM_STAC
  84. 4: movq -7(%_ASM_AX),%rdx
  85. xor %eax,%eax
  86. ASM_CLAC
  87. ret
  88. #else
  89. add $7,%_ASM_AX
  90. jc bad_get_user_8
  91. GET_THREAD_INFO(%_ASM_DX)
  92. cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
  93. jae bad_get_user_8
  94. sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
  95. and %_ASM_DX, %_ASM_AX
  96. ASM_STAC
  97. 4: movl -7(%_ASM_AX),%edx
  98. 5: movl -3(%_ASM_AX),%ecx
  99. xor %eax,%eax
  100. ASM_CLAC
  101. ret
  102. #endif
  103. ENDPROC(__get_user_8)
  104. bad_get_user:
  105. xor %edx,%edx
  106. mov $(-EFAULT),%_ASM_AX
  107. ASM_CLAC
  108. ret
  109. END(bad_get_user)
  110. #ifdef CONFIG_X86_32
  111. bad_get_user_8:
  112. xor %edx,%edx
  113. xor %ecx,%ecx
  114. mov $(-EFAULT),%_ASM_AX
  115. ASM_CLAC
  116. ret
  117. END(bad_get_user_8)
  118. #endif
  119. _ASM_EXTABLE(1b,bad_get_user)
  120. _ASM_EXTABLE(2b,bad_get_user)
  121. _ASM_EXTABLE(3b,bad_get_user)
  122. #ifdef CONFIG_X86_64
  123. _ASM_EXTABLE(4b,bad_get_user)
  124. #else
  125. _ASM_EXTABLE(4b,bad_get_user_8)
  126. _ASM_EXTABLE(5b,bad_get_user_8)
  127. #endif