Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * __get_user functions. |
| 3 | * |
| 4 | * (C) Copyright 1998 Linus Torvalds |
| 5 | * (C) Copyright 2005 Andi Kleen |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 6 | * (C) Copyright 2008 Glauber Costa |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | /* |
| 15 | * __get_user_X |
| 16 | * |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 17 | * Inputs: %[r|e]ax contains the address. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 19 | * Outputs: %[r|e]ax is error code (0 or -EFAULT) |
| 20 | * %[r|e]dx contains zero-extended value |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 21 | * %ecx contains the high half for 32-bit __get_user_8 |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 22 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | * |
| 24 | * These functions should not modify any other registers, |
| 25 | * as they get called from within inline assembly. |
| 26 | */ |
| 27 | |
| 28 | #include <linux/linkage.h> |
Jeremy Fitzhardinge | 0341c14 | 2009-02-13 11:14:01 -0800 | [diff] [blame] | 29 | #include <asm/page_types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/errno.h> |
Sam Ravnborg | e2d5df9 | 2005-09-09 21:28:48 +0200 | [diff] [blame] | 31 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/thread_info.h> |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 33 | #include <asm/asm.h> |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 34 | #include <asm/smap.h> |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 35 | #include <asm/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | .text |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 38 | ENTRY(__get_user_1) |
Andy Lutomirski | 13d4ea0 | 2016-07-14 13:22:57 -0700 | [diff] [blame] | 39 | mov PER_CPU_VAR(current_task), %_ASM_DX |
| 40 | cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | jae bad_get_user |
Dan Williams | 398a393 | 2018-01-29 17:02:54 -0800 | [diff] [blame] | 42 | sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */ |
| 43 | and %_ASM_DX, %_ASM_AX |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 44 | ASM_STAC |
H. Peter Anvin | 1664016 | 2013-02-11 23:14:48 -0800 | [diff] [blame] | 45 | 1: movzbl (%_ASM_AX),%edx |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 46 | xor %eax,%eax |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 47 | ASM_CLAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 49 | ENDPROC(__get_user_1) |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 50 | EXPORT_SYMBOL(__get_user_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 52 | ENTRY(__get_user_2) |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 53 | add $1,%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 54 | jc bad_get_user |
Andy Lutomirski | 13d4ea0 | 2016-07-14 13:22:57 -0700 | [diff] [blame] | 55 | mov PER_CPU_VAR(current_task), %_ASM_DX |
| 56 | cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 57 | jae bad_get_user |
Dan Williams | 398a393 | 2018-01-29 17:02:54 -0800 | [diff] [blame] | 58 | sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */ |
| 59 | and %_ASM_DX, %_ASM_AX |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 60 | ASM_STAC |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 61 | 2: movzwl -1(%_ASM_AX),%edx |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 62 | xor %eax,%eax |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 63 | ASM_CLAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 65 | ENDPROC(__get_user_2) |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 66 | EXPORT_SYMBOL(__get_user_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 68 | ENTRY(__get_user_4) |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 69 | add $3,%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 70 | jc bad_get_user |
Andy Lutomirski | 13d4ea0 | 2016-07-14 13:22:57 -0700 | [diff] [blame] | 71 | mov PER_CPU_VAR(current_task), %_ASM_DX |
| 72 | cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 73 | jae bad_get_user |
Dan Williams | 398a393 | 2018-01-29 17:02:54 -0800 | [diff] [blame] | 74 | sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */ |
| 75 | and %_ASM_DX, %_ASM_AX |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 76 | ASM_STAC |
H. Peter Anvin | 1664016 | 2013-02-11 23:14:48 -0800 | [diff] [blame] | 77 | 3: movl -3(%_ASM_AX),%edx |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 78 | xor %eax,%eax |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 79 | ASM_CLAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 81 | ENDPROC(__get_user_4) |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 82 | EXPORT_SYMBOL(__get_user_4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 84 | ENTRY(__get_user_8) |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 85 | #ifdef CONFIG_X86_64 |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 86 | add $7,%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 87 | jc bad_get_user |
Andy Lutomirski | 13d4ea0 | 2016-07-14 13:22:57 -0700 | [diff] [blame] | 88 | mov PER_CPU_VAR(current_task), %_ASM_DX |
| 89 | cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 90 | jae bad_get_user |
Dan Williams | 398a393 | 2018-01-29 17:02:54 -0800 | [diff] [blame] | 91 | sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */ |
| 92 | and %_ASM_DX, %_ASM_AX |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 93 | ASM_STAC |
H. Peter Anvin | 1664016 | 2013-02-11 23:14:48 -0800 | [diff] [blame] | 94 | 4: movq -7(%_ASM_AX),%rdx |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 95 | xor %eax,%eax |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 96 | ASM_CLAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | ret |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 98 | #else |
| 99 | add $7,%_ASM_AX |
| 100 | jc bad_get_user_8 |
Andy Lutomirski | 13d4ea0 | 2016-07-14 13:22:57 -0700 | [diff] [blame] | 101 | mov PER_CPU_VAR(current_task), %_ASM_DX |
| 102 | cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 103 | jae bad_get_user_8 |
Dan Williams | 398a393 | 2018-01-29 17:02:54 -0800 | [diff] [blame] | 104 | sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */ |
| 105 | and %_ASM_DX, %_ASM_AX |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 106 | ASM_STAC |
H. Peter Anvin | 1664016 | 2013-02-11 23:14:48 -0800 | [diff] [blame] | 107 | 4: movl -7(%_ASM_AX),%edx |
| 108 | 5: movl -3(%_ASM_AX),%ecx |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 109 | xor %eax,%eax |
| 110 | ASM_CLAC |
| 111 | ret |
| 112 | #endif |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 113 | ENDPROC(__get_user_8) |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 114 | EXPORT_SYMBOL(__get_user_8) |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | bad_get_user: |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 118 | xor %edx,%edx |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 119 | mov $(-EFAULT),%_ASM_AX |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 120 | ASM_CLAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 122 | END(bad_get_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 124 | #ifdef CONFIG_X86_32 |
| 125 | bad_get_user_8: |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 126 | xor %edx,%edx |
| 127 | xor %ecx,%ecx |
| 128 | mov $(-EFAULT),%_ASM_AX |
| 129 | ASM_CLAC |
| 130 | ret |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 131 | END(bad_get_user_8) |
| 132 | #endif |
| 133 | |
H. Peter Anvin | 1a27bc0 | 2012-04-20 12:19:51 -0700 | [diff] [blame] | 134 | _ASM_EXTABLE(1b,bad_get_user) |
| 135 | _ASM_EXTABLE(2b,bad_get_user) |
| 136 | _ASM_EXTABLE(3b,bad_get_user) |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 137 | #ifdef CONFIG_X86_64 |
H. Peter Anvin | 1a27bc0 | 2012-04-20 12:19:51 -0700 | [diff] [blame] | 138 | _ASM_EXTABLE(4b,bad_get_user) |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 139 | #else |
| 140 | _ASM_EXTABLE(4b,bad_get_user_8) |
| 141 | _ASM_EXTABLE(5b,bad_get_user_8) |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 142 | #endif |