blob: c8a85b512796e1b4aaa8de64ed9c91e5cb8371ce [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * __get_user functions.
4 *
5 * (C) Copyright 1998 Linus Torvalds
6 * (C) Copyright 2005 Andi Kleen
Glauber Costa6c2d4582008-06-24 12:05:11 -03007 * (C) Copyright 2008 Glauber Costa
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
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 Costa6c2d4582008-06-24 12:05:11 -030018 * Inputs: %[r|e]ax contains the address.
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 *
Glauber Costa6c2d4582008-06-24 12:05:11 -030020 * Outputs: %[r|e]ax is error code (0 or -EFAULT)
21 * %[r|e]dx contains zero-extended value
Ville Syrjälä96477b42012-12-12 13:34:03 +020022 * %ecx contains the high half for 32-bit __get_user_8
Glauber Costa6c2d4582008-06-24 12:05:11 -030023 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 *
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 Fitzhardinge0341c142009-02-13 11:14:01 -080030#include <asm/page_types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <asm/errno.h>
Sam Ravnborge2d5df92005-09-09 21:28:48 +020032#include <asm/asm-offsets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/thread_info.h>
Glauber Costa40faf462008-06-24 11:37:57 -030034#include <asm/asm.h>
H. Peter Anvin63bcff22012-09-21 12:43:12 -070035#include <asm/smap.h>
Al Viro784d5692016-01-11 11:04:34 -050036#include <asm/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38 .text
Jiri Slaby6dcc5622019-10-11 13:51:04 +020039SYM_FUNC_START(__get_user_1)
Andy Lutomirski13d4ea02016-07-14 13:22:57 -070040 mov PER_CPU_VAR(current_task), %_ASM_DX
41 cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 jae bad_get_user
Dan Williamsc7f631c2018-01-29 17:02:54 -080043 sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
44 and %_ASM_DX, %_ASM_AX
H. Peter Anvin63bcff22012-09-21 12:43:12 -070045 ASM_STAC
H. Peter Anvin16640162013-02-11 23:14:48 -0800461: movzbl (%_ASM_AX),%edx
Glauber Costaef8c1a22008-06-24 11:21:53 -030047 xor %eax,%eax
H. Peter Anvin63bcff22012-09-21 12:43:12 -070048 ASM_CLAC
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 ret
Jiri Slaby6dcc5622019-10-11 13:51:04 +020050SYM_FUNC_END(__get_user_1)
Al Viro784d5692016-01-11 11:04:34 -050051EXPORT_SYMBOL(__get_user_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Jiri Slaby6dcc5622019-10-11 13:51:04 +020053SYM_FUNC_START(__get_user_2)
Glauber Costa40faf462008-06-24 11:37:57 -030054 add $1,%_ASM_AX
Glauber Costa92628752008-06-24 11:13:16 -030055 jc bad_get_user
Andy Lutomirski13d4ea02016-07-14 13:22:57 -070056 mov PER_CPU_VAR(current_task), %_ASM_DX
57 cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX
Glauber Costa92628752008-06-24 11:13:16 -030058 jae bad_get_user
Dan Williamsc7f631c2018-01-29 17:02:54 -080059 sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
60 and %_ASM_DX, %_ASM_AX
H. Peter Anvin63bcff22012-09-21 12:43:12 -070061 ASM_STAC
Glauber Costa40faf462008-06-24 11:37:57 -0300622: movzwl -1(%_ASM_AX),%edx
Glauber Costaef8c1a22008-06-24 11:21:53 -030063 xor %eax,%eax
H. Peter Anvin63bcff22012-09-21 12:43:12 -070064 ASM_CLAC
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 ret
Jiri Slaby6dcc5622019-10-11 13:51:04 +020066SYM_FUNC_END(__get_user_2)
Al Viro784d5692016-01-11 11:04:34 -050067EXPORT_SYMBOL(__get_user_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Jiri Slaby6dcc5622019-10-11 13:51:04 +020069SYM_FUNC_START(__get_user_4)
Glauber Costa40faf462008-06-24 11:37:57 -030070 add $3,%_ASM_AX
Glauber Costa92628752008-06-24 11:13:16 -030071 jc bad_get_user
Andy Lutomirski13d4ea02016-07-14 13:22:57 -070072 mov PER_CPU_VAR(current_task), %_ASM_DX
73 cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX
Glauber Costa92628752008-06-24 11:13:16 -030074 jae bad_get_user
Dan Williamsc7f631c2018-01-29 17:02:54 -080075 sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
76 and %_ASM_DX, %_ASM_AX
H. Peter Anvin63bcff22012-09-21 12:43:12 -070077 ASM_STAC
H. Peter Anvin16640162013-02-11 23:14:48 -0800783: movl -3(%_ASM_AX),%edx
Glauber Costaef8c1a22008-06-24 11:21:53 -030079 xor %eax,%eax
H. Peter Anvin63bcff22012-09-21 12:43:12 -070080 ASM_CLAC
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 ret
Jiri Slaby6dcc5622019-10-11 13:51:04 +020082SYM_FUNC_END(__get_user_4)
Al Viro784d5692016-01-11 11:04:34 -050083EXPORT_SYMBOL(__get_user_4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Jiri Slaby6dcc5622019-10-11 13:51:04 +020085SYM_FUNC_START(__get_user_8)
Ville Syrjälä96477b42012-12-12 13:34:03 +020086#ifdef CONFIG_X86_64
Glauber Costa40faf462008-06-24 11:37:57 -030087 add $7,%_ASM_AX
Glauber Costa92628752008-06-24 11:13:16 -030088 jc bad_get_user
Andy Lutomirski13d4ea02016-07-14 13:22:57 -070089 mov PER_CPU_VAR(current_task), %_ASM_DX
90 cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX
Ville Syrjälä96477b42012-12-12 13:34:03 +020091 jae bad_get_user
Dan Williamsc7f631c2018-01-29 17:02:54 -080092 sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
93 and %_ASM_DX, %_ASM_AX
H. Peter Anvin63bcff22012-09-21 12:43:12 -070094 ASM_STAC
H. Peter Anvin16640162013-02-11 23:14:48 -0800954: movq -7(%_ASM_AX),%rdx
Glauber Costaef8c1a22008-06-24 11:21:53 -030096 xor %eax,%eax
H. Peter Anvin63bcff22012-09-21 12:43:12 -070097 ASM_CLAC
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 ret
Ville Syrjälä96477b42012-12-12 13:34:03 +020099#else
100 add $7,%_ASM_AX
101 jc bad_get_user_8
Andy Lutomirski13d4ea02016-07-14 13:22:57 -0700102 mov PER_CPU_VAR(current_task), %_ASM_DX
103 cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX
Ville Syrjälä96477b42012-12-12 13:34:03 +0200104 jae bad_get_user_8
Dan Williamsc7f631c2018-01-29 17:02:54 -0800105 sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
106 and %_ASM_DX, %_ASM_AX
Ville Syrjälä96477b42012-12-12 13:34:03 +0200107 ASM_STAC
H. Peter Anvin16640162013-02-11 23:14:48 -08001084: movl -7(%_ASM_AX),%edx
1095: movl -3(%_ASM_AX),%ecx
Ville Syrjälä96477b42012-12-12 13:34:03 +0200110 xor %eax,%eax
111 ASM_CLAC
112 ret
113#endif
Jiri Slaby6dcc5622019-10-11 13:51:04 +0200114SYM_FUNC_END(__get_user_8)
Al Viro784d5692016-01-11 11:04:34 -0500115EXPORT_SYMBOL(__get_user_8)
Ville Syrjälä96477b42012-12-12 13:34:03 +0200116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Jiri Slabyef77e682019-10-11 13:50:45 +0200118SYM_CODE_START_LOCAL(.Lbad_get_user_clac)
Josh Poimboeuf82e844a2019-07-17 20:36:44 -0500119 ASM_CLAC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120bad_get_user:
Glauber Costaef8c1a22008-06-24 11:21:53 -0300121 xor %edx,%edx
Glauber Costa40faf462008-06-24 11:37:57 -0300122 mov $(-EFAULT),%_ASM_AX
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 ret
Jiri Slabyef77e682019-10-11 13:50:45 +0200124SYM_CODE_END(.Lbad_get_user_clac)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Ville Syrjälä96477b42012-12-12 13:34:03 +0200126#ifdef CONFIG_X86_32
Jiri Slabyef77e682019-10-11 13:50:45 +0200127SYM_CODE_START_LOCAL(.Lbad_get_user_8_clac)
Josh Poimboeuf82e844a2019-07-17 20:36:44 -0500128 ASM_CLAC
Ville Syrjälä96477b42012-12-12 13:34:03 +0200129bad_get_user_8:
Ville Syrjälä96477b42012-12-12 13:34:03 +0200130 xor %edx,%edx
131 xor %ecx,%ecx
132 mov $(-EFAULT),%_ASM_AX
Ville Syrjälä96477b42012-12-12 13:34:03 +0200133 ret
Jiri Slabyef77e682019-10-11 13:50:45 +0200134SYM_CODE_END(.Lbad_get_user_8_clac)
Ville Syrjälä96477b42012-12-12 13:34:03 +0200135#endif
136
Jiri Slaby98ededb2019-09-06 09:55:50 +0200137 _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 Costa6c2d4582008-06-24 12:05:11 -0300140#ifdef CONFIG_X86_64
Jiri Slaby98ededb2019-09-06 09:55:50 +0200141 _ASM_EXTABLE_UA(4b, .Lbad_get_user_clac)
Ville Syrjälä96477b42012-12-12 13:34:03 +0200142#else
Jiri Slaby98ededb2019-09-06 09:55:50 +0200143 _ASM_EXTABLE_UA(4b, .Lbad_get_user_8_clac)
144 _ASM_EXTABLE_UA(5b, .Lbad_get_user_8_clac)
Glauber Costa6c2d4582008-06-24 12:05:11 -0300145#endif