* [PATCH v4.4] x86/uaccess: Don't leak the AC flag into __put_user() value evaluation
@ 2019-03-03 16:07 Maxim Zhukov
2019-03-03 17:05 ` Nathan Chancellor
0 siblings, 1 reply; 3+ messages in thread
From: Maxim Zhukov @ 2019-03-03 16:07 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Andy Lutomirski, Borislav Petkov, Linus Torvalds, Peter Zijlstra,
Brian Gerst, Josh Poimboeuf, Denys Vlasenko, stable, Maxim Zhukov
From: Andy Lutomirski <luto@kernel.org>
commit 2a418cf3f5f1caf911af288e978d61c9844b0695 upstream.
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
Signed-off-by: Maxim Zhukov <mussitantesmortem@gmail.com>
---
arch/x86/include/asm/uaccess.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index d788b0cdc0ad..4f4a9fa61b8a 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -306,7 +306,7 @@ do { \
__put_user_asm(x, ptr, retval, "l", "k", "ir", errret); \
break; \
case 8: \
- __put_user_asm_u64((__typeof__(*ptr))(x), ptr, retval, \
+ __put_user_asm_u64(x, ptr, retval, \
errret); \
break; \
default: \
@@ -410,7 +410,9 @@ do { \
#define __put_user_nocheck(x, ptr, size) \
({ \
int __pu_err; \
- __put_user_size((x), (ptr), (size), __pu_err, -EFAULT); \
+ __typeof__(*(ptr)) __pu_val; \
+ __pu_val = x; \
+ __put_user_size(__pu_val, (ptr), (size), __pu_err, -EFAULT); \
__builtin_expect(__pu_err, 0); \
})
--
2.21.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v4.4] x86/uaccess: Don't leak the AC flag into __put_user() value evaluation
2019-03-03 16:07 [PATCH v4.4] x86/uaccess: Don't leak the AC flag into __put_user() value evaluation Maxim Zhukov
@ 2019-03-03 17:05 ` Nathan Chancellor
[not found] ` <CAFqsdWn2a4Q5kpmoei2WMix-cjVXuaciKQQYZJKmoNRhD9TSrA@mail.gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Nathan Chancellor @ 2019-03-03 17:05 UTC (permalink / raw)
To: Maxim Zhukov
Cc: Greg Kroah-Hartman, Andy Lutomirski, Borislav Petkov,
Linus Torvalds, Peter Zijlstra, Brian Gerst, Josh Poimboeuf,
Denys Vlasenko, stable
On Sun, Mar 03, 2019 at 07:07:09PM +0300, Maxim Zhukov wrote:
> From: Andy Lutomirski <luto@kernel.org>
>
> commit 2a418cf3f5f1caf911af288e978d61c9844b0695 upstream.
>
> 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
> Signed-off-by: Maxim Zhukov <mussitantesmortem@gmail.com>
> ---
> arch/x86/include/asm/uaccess.h | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
> index d788b0cdc0ad..4f4a9fa61b8a 100644
> --- a/arch/x86/include/asm/uaccess.h
> +++ b/arch/x86/include/asm/uaccess.h
> @@ -306,7 +306,7 @@ do { \
> __put_user_asm(x, ptr, retval, "l", "k", "ir", errret); \
> break; \
> case 8: \
> - __put_user_asm_u64((__typeof__(*ptr))(x), ptr, retval, \
> + __put_user_asm_u64(x, ptr, retval, \
> errret); \
> break; \
> default: \
> @@ -410,7 +410,9 @@ do { \
> #define __put_user_nocheck(x, ptr, size) \
> ({ \
> int __pu_err; \
> - __put_user_size((x), (ptr), (size), __pu_err, -EFAULT); \
> + __typeof__(*(ptr)) __pu_val; \
> + __pu_val = x; \
> + __put_user_size(__pu_val, (ptr), (size), __pu_err, -EFAULT); \
> __builtin_expect(__pu_err, 0); \
> })
>
> --
> 2.21.0
>
Did you generate this against a current 4.4 tree? It fails to apply to
4.4.176 because this patch doesn't account for cc8c5450b6d7 ("x86:
reorganize SMAP handling in user space accesses"). Odds are you will
only need one patch for 4.4 to 4.20.
Cheers,
Nathan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v4.4] x86/uaccess: Don't leak the AC flag into __put_user() value evaluation
[not found] ` <CAFqsdWn2a4Q5kpmoei2WMix-cjVXuaciKQQYZJKmoNRhD9TSrA@mail.gmail.com>
@ 2019-03-03 17:57 ` Greg Kroah-Hartman
0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2019-03-03 17:57 UTC (permalink / raw)
To: Maxim Zhukov
Cc: Nathan Chancellor, Maxim Zhukov, Andy Lutomirski, Borislav Petkov,
Linus Torvalds, Peter Zijlstra, Brian Gerst, Josh Poimboeuf,
Denys Vlasenko, stable
On Sun, Mar 03, 2019 at 08:28:01PM +0300, Maxim Zhukov wrote:
> Whoops, this patch generated on old tree, sorry. I regenerate patch from
> new 4.4 tree. And test for all kernels (its work). Resend one patch for all
> stable branches?
If that is what works and is needed, yes.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-03-03 17:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-03 16:07 [PATCH v4.4] x86/uaccess: Don't leak the AC flag into __put_user() value evaluation Maxim Zhukov
2019-03-03 17:05 ` Nathan Chancellor
[not found] ` <CAFqsdWn2a4Q5kpmoei2WMix-cjVXuaciKQQYZJKmoNRhD9TSrA@mail.gmail.com>
2019-03-03 17:57 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).