diff options
author | Andy Lutomirski <luto@kernel.org> | 2019-02-22 20:17:04 -0500 |
---|---|---|
committer | Borislav Petkov <bp@suse.de> | 2019-02-25 14:17:05 -0500 |
commit | 2a418cf3f5f1caf911af288e978d61c9844b0695 (patch) | |
tree | 328d5988460e15b341ba24c37fe048e7d1df34ce | |
parent | f331e766c4be33f4338574f3c9f7f77e98ab4571 (diff) |
x86/uaccess: Don't leak the AC flag into __put_user() value evaluation
When calling __put_user(foo(), ptr), the __put_user() macro would call
foo() in between __uaccess_begin() and __uaccess_end(). If that code
were buggy, then those bugs would be run without SMAP protection.
Fortunately, there seem to be few instances of the problem in the
kernel. Nevertheless, __put_user() should be fixed to avoid doing this.
Therefore, evaluate __put_user()'s argument before setting AC.
This issue was noticed when an objtool hack by Peter Zijlstra complained
about genregs_get() and I compared the assembly output to the C source.
[ bp: Massage commit message and fixed up whitespace. ]
Fixes: 11f1a4b9755f ("x86: reorganize SMAP handling in user space accesses")
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/20190225125231.845656645@infradead.org
-rw-r--r-- | arch/x86/include/asm/uaccess.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index a77445d1b034..28376aa2d053 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h | |||
@@ -284,7 +284,7 @@ do { \ | |||
284 | __put_user_goto(x, ptr, "l", "k", "ir", label); \ | 284 | __put_user_goto(x, ptr, "l", "k", "ir", label); \ |
285 | break; \ | 285 | break; \ |
286 | case 8: \ | 286 | case 8: \ |
287 | __put_user_goto_u64((__typeof__(*ptr))(x), ptr, label); \ | 287 | __put_user_goto_u64(x, ptr, label); \ |
288 | break; \ | 288 | break; \ |
289 | default: \ | 289 | default: \ |
290 | __put_user_bad(); \ | 290 | __put_user_bad(); \ |
@@ -431,8 +431,10 @@ do { \ | |||
431 | ({ \ | 431 | ({ \ |
432 | __label__ __pu_label; \ | 432 | __label__ __pu_label; \ |
433 | int __pu_err = -EFAULT; \ | 433 | int __pu_err = -EFAULT; \ |
434 | __typeof__(*(ptr)) __pu_val; \ | ||
435 | __pu_val = x; \ | ||
434 | __uaccess_begin(); \ | 436 | __uaccess_begin(); \ |
435 | __put_user_size((x), (ptr), (size), __pu_label); \ | 437 | __put_user_size(__pu_val, (ptr), (size), __pu_label); \ |
436 | __pu_err = 0; \ | 438 | __pu_err = 0; \ |
437 | __pu_label: \ | 439 | __pu_label: \ |
438 | __uaccess_end(); \ | 440 | __uaccess_end(); \ |