blob: 96dce5fe2a35f49c92c6e44a3273567931227ceb [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 * __put_user functions.
4 *
5 * (C) Copyright 2005 Linus Torvalds
Glauber Costa5cbbc3b2008-06-24 17:40:14 -03006 * (C) Copyright 2005 Andi Kleen
7 * (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 */
Jan Beulich00e065e2007-05-02 19:27:05 +020014#include <linux/linkage.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/thread_info.h>
Glauber Costa5cbbc3b2008-06-24 17:40:14 -030016#include <asm/errno.h>
Glauber Costa2528de42008-06-24 17:36:31 -030017#include <asm/asm.h>
H. Peter Anvin63bcff22012-09-21 12:43:12 -070018#include <asm/smap.h>
Al Viro784d5692016-01-11 11:04:34 -050019#include <asm/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21
22/*
23 * __put_user_X
24 *
25 * Inputs: %eax[:%edx] contains the data
26 * %ecx contains the address
27 *
28 * Outputs: %eax is error code (0 or -EFAULT)
29 *
30 * These functions should not modify any other registers,
31 * as they get called from within inline assembly.
32 */
33
Andy Lutomirski13d4ea02016-07-14 13:22:57 -070034#define ENTER mov PER_CPU_VAR(current_task), %_ASM_BX
H. Peter Anvin63bcff22012-09-21 12:43:12 -070035#define EXIT ASM_CLAC ; \
Ingo Molnar131484c2015-05-28 12:21:47 +020036 ret
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38.text
Jan Beulich00e065e2007-05-02 19:27:05 +020039ENTRY(__put_user_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 ENTER
Andy Lutomirski13d4ea02016-07-14 13:22:57 -070041 cmp TASK_addr_limit(%_ASM_BX),%_ASM_CX
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 jae bad_put_user
H. Peter Anvin63bcff22012-09-21 12:43:12 -070043 ASM_STAC
Glauber Costa2528de42008-06-24 17:36:31 -0300441: movb %al,(%_ASM_CX)
Glauber Costaefea5052008-06-24 16:59:05 -030045 xor %eax,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020047ENDPROC(__put_user_1)
Al Viro784d5692016-01-11 11:04:34 -050048EXPORT_SYMBOL(__put_user_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Jan Beulich00e065e2007-05-02 19:27:05 +020050ENTRY(__put_user_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 ENTER
Andy Lutomirski13d4ea02016-07-14 13:22:57 -070052 mov TASK_addr_limit(%_ASM_BX),%_ASM_BX
Glauber Costa2528de42008-06-24 17:36:31 -030053 sub $1,%_ASM_BX
54 cmp %_ASM_BX,%_ASM_CX
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 jae bad_put_user
H. Peter Anvin63bcff22012-09-21 12:43:12 -070056 ASM_STAC
Glauber Costa2528de42008-06-24 17:36:31 -0300572: movw %ax,(%_ASM_CX)
Glauber Costaefea5052008-06-24 16:59:05 -030058 xor %eax,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020060ENDPROC(__put_user_2)
Al Viro784d5692016-01-11 11:04:34 -050061EXPORT_SYMBOL(__put_user_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Jan Beulich00e065e2007-05-02 19:27:05 +020063ENTRY(__put_user_4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 ENTER
Andy Lutomirski13d4ea02016-07-14 13:22:57 -070065 mov TASK_addr_limit(%_ASM_BX),%_ASM_BX
Glauber Costa2528de42008-06-24 17:36:31 -030066 sub $3,%_ASM_BX
67 cmp %_ASM_BX,%_ASM_CX
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 jae bad_put_user
H. Peter Anvin63bcff22012-09-21 12:43:12 -070069 ASM_STAC
Glauber Costa2528de42008-06-24 17:36:31 -0300703: movl %eax,(%_ASM_CX)
Glauber Costaefea5052008-06-24 16:59:05 -030071 xor %eax,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020073ENDPROC(__put_user_4)
Al Viro784d5692016-01-11 11:04:34 -050074EXPORT_SYMBOL(__put_user_4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Jan Beulich00e065e2007-05-02 19:27:05 +020076ENTRY(__put_user_8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 ENTER
Andy Lutomirski13d4ea02016-07-14 13:22:57 -070078 mov TASK_addr_limit(%_ASM_BX),%_ASM_BX
Glauber Costa2528de42008-06-24 17:36:31 -030079 sub $7,%_ASM_BX
80 cmp %_ASM_BX,%_ASM_CX
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 jae bad_put_user
H. Peter Anvin63bcff22012-09-21 12:43:12 -070082 ASM_STAC
Glauber Costa5cbbc3b2008-06-24 17:40:14 -0300834: mov %_ASM_AX,(%_ASM_CX)
84#ifdef CONFIG_X86_32
Glauber Costa2528de42008-06-24 17:36:31 -0300855: movl %edx,4(%_ASM_CX)
Glauber Costa5cbbc3b2008-06-24 17:40:14 -030086#endif
Glauber Costaefea5052008-06-24 16:59:05 -030087 xor %eax,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020089ENDPROC(__put_user_8)
Al Viro784d5692016-01-11 11:04:34 -050090EXPORT_SYMBOL(__put_user_8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92bad_put_user:
Glauber Costa5cbbc3b2008-06-24 17:40:14 -030093 movl $-EFAULT,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020095END(bad_put_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
H. Peter Anvina53a96e2012-04-20 12:19:52 -070097 _ASM_EXTABLE(1b,bad_put_user)
98 _ASM_EXTABLE(2b,bad_put_user)
99 _ASM_EXTABLE(3b,bad_put_user)
100 _ASM_EXTABLE(4b,bad_put_user)
Glauber Costa5cbbc3b2008-06-24 17:40:14 -0300101#ifdef CONFIG_X86_32
H. Peter Anvina53a96e2012-04-20 12:19:52 -0700102 _ASM_EXTABLE(5b,bad_put_user)
Glauber Costa5cbbc3b2008-06-24 17:40:14 -0300103#endif