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