All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] objtool: Documentation: document UACCESS warnings
       [not found] <20200323212538.GN2452@worktop.programming.kicks-ass.net>
@ 2020-03-24  0:13 ` Nick Desaulniers
  2020-03-24  1:12   ` Randy Dunlap
                     ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Nick Desaulniers @ 2020-03-24  0:13 UTC (permalink / raw)
  To: jpoimboe, peterz
  Cc: Nick Desaulniers, Mauro Carvalho Chehab, Jonathan Corbet,
	Wolfram Sang, Kamalesh Babulal, Raphael Gault, linux-kernel,
	clang-built-linux

Compiling with Clang and CONFIG_KASAN=y was exposing a few warnings:
  call to memset() with UACCESS enabled

Document how to fix these for future travelers.

Link: https://github.com/ClangBuiltLinux/linux/issues/876
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 .../Documentation/stack-validation.txt        | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/tools/objtool/Documentation/stack-validation.txt b/tools/objtool/Documentation/stack-validation.txt
index de094670050b..156fee13ba02 100644
--- a/tools/objtool/Documentation/stack-validation.txt
+++ b/tools/objtool/Documentation/stack-validation.txt
@@ -289,6 +289,26 @@ they mean, and suggestions for how to fix them.
       might be corrupt due to a gcc bug.  For more details, see:
       https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70646
 
+9. file.o: warning: objtool: funcA() call to funcB() with UACCESS enabled
+
+   This means that an unexpected call to a non-whitelisted function exists
+   outside of arch-specific guards.
+   X86: SMAP (stac/clac): __uaccess_begin()/__uaccess_end()
+   ARM: PAN: uaccess_enable()/uaccess_enable()
+
+   These functions should called to denote a minimal critical section around
+   access to __user variables. See also: https://lwn.net/Articles/517475/
+
+   The intention of the warning is to prevent calls to funcB() from eventually
+   calling schedule(), potentially leaking the AC flags state, and not
+   restoring them correctly.
+
+   To fix, either:
+   1) add the correct guards before and after calls to low level functions like
+      __get_user_size()/__put_user_size().
+   2) add funcB to uaccess_safe_builtin whitelist in tools/objtool/check.c, if
+      funcB obviously does not call schedule().
+
 
 If the error doesn't seem to make sense, it could be a bug in objtool.
 Feel free to ask the objtool maintainer for help.
-- 
2.25.1.696.g5e7596f4ac-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] objtool: Documentation: document UACCESS warnings
  2020-03-24  0:13 ` [PATCH] objtool: Documentation: document UACCESS warnings Nick Desaulniers
@ 2020-03-24  1:12   ` Randy Dunlap
  2020-03-24  8:41   ` Kamalesh Babulal
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Randy Dunlap @ 2020-03-24  1:12 UTC (permalink / raw)
  To: Nick Desaulniers, jpoimboe, peterz
  Cc: Mauro Carvalho Chehab, Jonathan Corbet, Wolfram Sang,
	Kamalesh Babulal, Raphael Gault, linux-kernel, clang-built-linux

On 3/23/20 5:13 PM, Nick Desaulniers wrote:
> Compiling with Clang and CONFIG_KASAN=y was exposing a few warnings:
>   call to memset() with UACCESS enabled
> 
> Document how to fix these for future travelers.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/876
> Suggested-by: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
>  .../Documentation/stack-validation.txt        | 20 +++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/tools/objtool/Documentation/stack-validation.txt b/tools/objtool/Documentation/stack-validation.txt
> index de094670050b..156fee13ba02 100644
> --- a/tools/objtool/Documentation/stack-validation.txt
> +++ b/tools/objtool/Documentation/stack-validation.txt
> @@ -289,6 +289,26 @@ they mean, and suggestions for how to fix them.
>        might be corrupt due to a gcc bug.  For more details, see:
>        https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70646
>  
> +9. file.o: warning: objtool: funcA() call to funcB() with UACCESS enabled
> +
> +   This means that an unexpected call to a non-whitelisted function exists
> +   outside of arch-specific guards.
> +   X86: SMAP (stac/clac): __uaccess_begin()/__uaccess_end()
> +   ARM: PAN: uaccess_enable()/uaccess_enable()
> +
> +   These functions should called to denote a minimal critical section around

                      should be called

> +   access to __user variables. See also: https://lwn.net/Articles/517475/
> +
> +   The intention of the warning is to prevent calls to funcB() from eventually
> +   calling schedule(), potentially leaking the AC flags state, and not
> +   restoring them correctly.
> +
> +   To fix, either:
> +   1) add the correct guards before and after calls to low level functions like
> +      __get_user_size()/__put_user_size().
> +   2) add funcB to uaccess_safe_builtin whitelist in tools/objtool/check.c, if
> +      funcB obviously does not call schedule().
> +
>  
>  If the error doesn't seem to make sense, it could be a bug in objtool.
>  Feel free to ask the objtool maintainer for help.
> 


-- 
~Randy


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] objtool: Documentation: document UACCESS warnings
  2020-03-24  0:13 ` [PATCH] objtool: Documentation: document UACCESS warnings Nick Desaulniers
  2020-03-24  1:12   ` Randy Dunlap
@ 2020-03-24  8:41   ` Kamalesh Babulal
  2020-03-24 12:52   ` Peter Zijlstra
  2020-03-26 13:47   ` Matt Helsley
  3 siblings, 0 replies; 7+ messages in thread
From: Kamalesh Babulal @ 2020-03-24  8:41 UTC (permalink / raw)
  To: Nick Desaulniers, jpoimboe, peterz
  Cc: Mauro Carvalho Chehab, Jonathan Corbet, Wolfram Sang,
	Raphael Gault, linux-kernel, clang-built-linux

On 3/24/20 5:43 AM, Nick Desaulniers wrote:
> Compiling with Clang and CONFIG_KASAN=y was exposing a few warnings:
>   call to memset() with UACCESS enabled
> 
> Document how to fix these for future travelers.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/876
> Suggested-by: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

Looks good, a minor nitpick below.

> ---
>  .../Documentation/stack-validation.txt        | 20 +++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/tools/objtool/Documentation/stack-validation.txt b/tools/objtool/Documentation/stack-validation.txt
> index de094670050b..156fee13ba02 100644
> --- a/tools/objtool/Documentation/stack-validation.txt
> +++ b/tools/objtool/Documentation/stack-validation.txt
> @@ -289,6 +289,26 @@ they mean, and suggestions for how to fix them.
>        might be corrupt due to a gcc bug.  For more details, see:
>        https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70646
> 
> +9. file.o: warning: objtool: funcA() call to funcB() with UACCESS enabled
> +
> +   This means that an unexpected call to a non-whitelisted function exists
> +   outside of arch-specific guards.
> +   X86: SMAP (stac/clac): __uaccess_begin()/__uaccess_end()
> +   ARM: PAN: uaccess_enable()/uaccess_enable()
                                 ^^^^^^ 
                                uaccess_disable() 

> +
> +   These functions should called to denote a minimal critical section around
> +   access to __user variables. See also: https://lwn.net/Articles/517475/

-- 
Kamalesh


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] objtool: Documentation: document UACCESS warnings
  2020-03-24  0:13 ` [PATCH] objtool: Documentation: document UACCESS warnings Nick Desaulniers
  2020-03-24  1:12   ` Randy Dunlap
  2020-03-24  8:41   ` Kamalesh Babulal
@ 2020-03-24 12:52   ` Peter Zijlstra
  2020-03-26 13:47   ` Matt Helsley
  3 siblings, 0 replies; 7+ messages in thread
From: Peter Zijlstra @ 2020-03-24 12:52 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: jpoimboe, Mauro Carvalho Chehab, Jonathan Corbet, Wolfram Sang,
	Kamalesh Babulal, Raphael Gault, linux-kernel, clang-built-linux

On Mon, Mar 23, 2020 at 05:13:20PM -0700, Nick Desaulniers wrote:
> Compiling with Clang and CONFIG_KASAN=y was exposing a few warnings:
>   call to memset() with UACCESS enabled
> 
> Document how to fix these for future travelers.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/876
> Suggested-by: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
>  .../Documentation/stack-validation.txt        | 20 +++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/tools/objtool/Documentation/stack-validation.txt b/tools/objtool/Documentation/stack-validation.txt
> index de094670050b..156fee13ba02 100644
> --- a/tools/objtool/Documentation/stack-validation.txt
> +++ b/tools/objtool/Documentation/stack-validation.txt
> @@ -289,6 +289,26 @@ they mean, and suggestions for how to fix them.
>        might be corrupt due to a gcc bug.  For more details, see:
>        https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70646
>  
> +9. file.o: warning: objtool: funcA() call to funcB() with UACCESS enabled
> +
> +   This means that an unexpected call to a non-whitelisted function exists
> +   outside of arch-specific guards.
> +   X86: SMAP (stac/clac): __uaccess_begin()/__uaccess_end()
> +   ARM: PAN: uaccess_enable()/uaccess_enable()
> +
> +   These functions should called to denote a minimal critical section around
> +   access to __user variables. See also: https://lwn.net/Articles/517475/
> +
> +   The intention of the warning is to prevent calls to funcB() from eventually
> +   calling schedule(), potentially leaking the AC flags state, and not
> +   restoring them correctly.
> +
> +   To fix, either:
> +   1) add the correct guards before and after calls to low level functions like
> +      __get_user_size()/__put_user_size().
> +   2) add funcB to uaccess_safe_builtin whitelist in tools/objtool/check.c, if
> +      funcB obviously does not call schedule().

There's sadly nothing obvious about 2); __fentry__ is enough to end up
in schedule() through preempt_enable().

So any function that has function tracing on (mostly everything) is
already disqualified.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] objtool: Documentation: document UACCESS warnings
  2020-03-24  0:13 ` [PATCH] objtool: Documentation: document UACCESS warnings Nick Desaulniers
                     ` (2 preceding siblings ...)
  2020-03-24 12:52   ` Peter Zijlstra
@ 2020-03-26 13:47   ` Matt Helsley
  2020-03-26 18:37     ` [PATCH v2] " Nick Desaulniers
  3 siblings, 1 reply; 7+ messages in thread
From: Matt Helsley @ 2020-03-26 13:47 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: jpoimboe, peterz, Mauro Carvalho Chehab, Jonathan Corbet,
	Wolfram Sang, Kamalesh Babulal, Raphael Gault, linux-kernel,
	clang-built-linux

On Mon, Mar 23, 2020 at 05:13:20PM -0700, Nick Desaulniers wrote:
> Compiling with Clang and CONFIG_KASAN=y was exposing a few warnings:
>   call to memset() with UACCESS enabled
> 
> Document how to fix these for future travelers.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/876
> Suggested-by: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
>  .../Documentation/stack-validation.txt        | 20 +++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/tools/objtool/Documentation/stack-validation.txt b/tools/objtool/Documentation/stack-validation.txt
> index de094670050b..156fee13ba02 100644
> --- a/tools/objtool/Documentation/stack-validation.txt
> +++ b/tools/objtool/Documentation/stack-validation.txt
> @@ -289,6 +289,26 @@ they mean, and suggestions for how to fix them.
>        might be corrupt due to a gcc bug.  For more details, see:
>        https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70646
>  
> +9. file.o: warning: objtool: funcA() call to funcB() with UACCESS enabled
> +
> +   This means that an unexpected call to a non-whitelisted function exists
> +   outside of arch-specific guards.
> +   X86: SMAP (stac/clac): __uaccess_begin()/__uaccess_end()
> +   ARM: PAN: uaccess_enable()/uaccess_enable()
I think you meant to put "disable" here  ^^^^^^

Cheers,
    -Matt Helsley

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] objtool: Documentation: document UACCESS warnings
  2020-03-26 13:47   ` Matt Helsley
@ 2020-03-26 18:37     ` Nick Desaulniers
  2020-04-03 16:20       ` Josh Poimboeuf
  0 siblings, 1 reply; 7+ messages in thread
From: Nick Desaulniers @ 2020-03-26 18:37 UTC (permalink / raw)
  To: jpoimboe, peterz
  Cc: Nick Desaulniers, Kamalesh Babulal, Matt Helsley, Randy Dunlap,
	Jonathan Corbet, Mauro Carvalho Chehab, Petr Mladek,
	Raphael Gault, linux-kernel, clang-built-linux

Compiling with Clang and CONFIG_KASAN=y was exposing a few warnings:
  call to memset() with UACCESS enabled

Document how to fix these for future travelers.

Link: https://github.com/ClangBuiltLinux/linux/issues/876
Suggested-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
Suggested-by: Matt Helsley <mhelsley@vmware.com>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Suggested-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
Changes V1 -> V2:
* fix typo of listing uaccess_enable() twice rather than
  uaccess_disable() as per Matt and Kamalesh.
* fix type of "should called" to "should be called" as per Randy.
* Mention non-obvious compiler instrumentation ie. -pg/mcount
  -mfentry/fentry via tracing as per Peter.
* Add sentence "It also helps verify..."
* Add potential fix "1) remove explicit..."


 .../Documentation/stack-validation.txt        | 26 +++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/tools/objtool/Documentation/stack-validation.txt b/tools/objtool/Documentation/stack-validation.txt
index de094670050b..faa47c3aafae 100644
--- a/tools/objtool/Documentation/stack-validation.txt
+++ b/tools/objtool/Documentation/stack-validation.txt
@@ -289,6 +289,32 @@ they mean, and suggestions for how to fix them.
       might be corrupt due to a gcc bug.  For more details, see:
       https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70646
 
+9. file.o: warning: objtool: funcA() call to funcB() with UACCESS enabled
+
+   This means that an unexpected call to a non-whitelisted function exists
+   outside of arch-specific guards.
+   X86: SMAP (stac/clac): __uaccess_begin()/__uaccess_end()
+   ARM: PAN: uaccess_enable()/uaccess_disable()
+
+   These functions should be called to denote a minimal critical section around
+   access to __user variables. See also: https://lwn.net/Articles/517475/
+
+   The intention of the warning is to prevent calls to funcB() from eventually
+   calling schedule(), potentially leaking the AC flags state, and not
+   restoring them correctly.
+
+   It also helps verify that there are no unexpected calls to funcB() which may
+   access user space pages with protections against doing so disabled.
+
+   To fix, either:
+   1) remove explicit calls to funcB() from funcA().
+   2) add the correct guards before and after calls to low level functions like
+      __get_user_size()/__put_user_size().
+   3) add funcB to uaccess_safe_builtin whitelist in tools/objtool/check.c, if
+      funcB obviously does not call schedule(), and is marked notrace (since
+      function tracing inserts additional calls, which is not obvious from the
+      sources).
+
 
 If the error doesn't seem to make sense, it could be a bug in objtool.
 Feel free to ask the objtool maintainer for help.
-- 
2.26.0.rc2.310.g2932bb562d-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] objtool: Documentation: document UACCESS warnings
  2020-03-26 18:37     ` [PATCH v2] " Nick Desaulniers
@ 2020-04-03 16:20       ` Josh Poimboeuf
  0 siblings, 0 replies; 7+ messages in thread
From: Josh Poimboeuf @ 2020-04-03 16:20 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: peterz, Kamalesh Babulal, Matt Helsley, Randy Dunlap,
	Jonathan Corbet, Mauro Carvalho Chehab, Petr Mladek,
	Raphael Gault, linux-kernel, clang-built-linux

On Thu, Mar 26, 2020 at 11:37:06AM -0700, Nick Desaulniers wrote:
> Compiling with Clang and CONFIG_KASAN=y was exposing a few warnings:
>   call to memset() with UACCESS enabled
> 
> Document how to fix these for future travelers.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/876
> Suggested-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
> Suggested-by: Matt Helsley <mhelsley@vmware.com>
> Suggested-by: Peter Zijlstra <peterz@infradead.org>
> Suggested-by: Randy Dunlap <rdunlap@infradead.org>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
> Changes V1 -> V2:
> * fix typo of listing uaccess_enable() twice rather than
>   uaccess_disable() as per Matt and Kamalesh.
> * fix type of "should called" to "should be called" as per Randy.
> * Mention non-obvious compiler instrumentation ie. -pg/mcount
>   -mfentry/fentry via tracing as per Peter.
> * Add sentence "It also helps verify..."
> * Add potential fix "1) remove explicit..."

Thanks, adding this one to the queue for tip.

-- 
Josh


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-04-03 16:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200323212538.GN2452@worktop.programming.kicks-ass.net>
2020-03-24  0:13 ` [PATCH] objtool: Documentation: document UACCESS warnings Nick Desaulniers
2020-03-24  1:12   ` Randy Dunlap
2020-03-24  8:41   ` Kamalesh Babulal
2020-03-24 12:52   ` Peter Zijlstra
2020-03-26 13:47   ` Matt Helsley
2020-03-26 18:37     ` [PATCH v2] " Nick Desaulniers
2020-04-03 16:20       ` Josh Poimboeuf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.