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 | * __put_user functions. |
| 4 | * |
| 5 | * (C) Copyright 2005 Linus Torvalds |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 6 | * (C) Copyright 2005 Andi Kleen |
| 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 | */ |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 14 | #include <linux/linkage.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <asm/thread_info.h> |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 16 | #include <asm/errno.h> |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 17 | #include <asm/asm.h> |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 18 | #include <asm/smap.h> |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 19 | #include <asm/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 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 Lutomirski | 13d4ea0 | 2016-07-14 13:22:57 -0700 | [diff] [blame] | 34 | #define ENTER mov PER_CPU_VAR(current_task), %_ASM_BX |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 35 | #define EXIT ASM_CLAC ; \ |
Ingo Molnar | 131484c | 2015-05-28 12:21:47 +0200 | [diff] [blame] | 36 | ret |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | .text |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 39 | ENTRY(__put_user_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | ENTER |
Andy Lutomirski | 13d4ea0 | 2016-07-14 13:22:57 -0700 | [diff] [blame] | 41 | cmp TASK_addr_limit(%_ASM_BX),%_ASM_CX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | jae bad_put_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 43 | ASM_STAC |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 44 | 1: movb %al,(%_ASM_CX) |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame] | 45 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 47 | ENDPROC(__put_user_1) |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 48 | EXPORT_SYMBOL(__put_user_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 50 | ENTRY(__put_user_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | ENTER |
Andy Lutomirski | 13d4ea0 | 2016-07-14 13:22:57 -0700 | [diff] [blame] | 52 | mov TASK_addr_limit(%_ASM_BX),%_ASM_BX |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 53 | sub $1,%_ASM_BX |
| 54 | cmp %_ASM_BX,%_ASM_CX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | jae bad_put_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 56 | ASM_STAC |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 57 | 2: movw %ax,(%_ASM_CX) |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame] | 58 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 60 | ENDPROC(__put_user_2) |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 61 | EXPORT_SYMBOL(__put_user_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 63 | ENTRY(__put_user_4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | ENTER |
Andy Lutomirski | 13d4ea0 | 2016-07-14 13:22:57 -0700 | [diff] [blame] | 65 | mov TASK_addr_limit(%_ASM_BX),%_ASM_BX |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 66 | sub $3,%_ASM_BX |
| 67 | cmp %_ASM_BX,%_ASM_CX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | jae bad_put_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 69 | ASM_STAC |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 70 | 3: movl %eax,(%_ASM_CX) |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame] | 71 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 73 | ENDPROC(__put_user_4) |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 74 | EXPORT_SYMBOL(__put_user_4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 76 | ENTRY(__put_user_8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | ENTER |
Andy Lutomirski | 13d4ea0 | 2016-07-14 13:22:57 -0700 | [diff] [blame] | 78 | mov TASK_addr_limit(%_ASM_BX),%_ASM_BX |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 79 | sub $7,%_ASM_BX |
| 80 | cmp %_ASM_BX,%_ASM_CX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | jae bad_put_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 82 | ASM_STAC |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 83 | 4: mov %_ASM_AX,(%_ASM_CX) |
| 84 | #ifdef CONFIG_X86_32 |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 85 | 5: movl %edx,4(%_ASM_CX) |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 86 | #endif |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame] | 87 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 89 | ENDPROC(__put_user_8) |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 90 | EXPORT_SYMBOL(__put_user_8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | bad_put_user: |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 93 | movl $-EFAULT,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 95 | END(bad_put_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
H. Peter Anvin | a53a96e | 2012-04-20 12:19:52 -0700 | [diff] [blame] | 97 | _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 Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 101 | #ifdef CONFIG_X86_32 |
H. Peter Anvin | a53a96e | 2012-04-20 12:19:52 -0700 | [diff] [blame] | 102 | _ASM_EXTABLE(5b,bad_put_user) |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 103 | #endif |