Skip to contentSkip to conversation

objtool: Documentation: document UACCESS warnings

PATCH Superseded Nick Desaulniers 6 participants 7 messages Mar 24, 2020 – Apr 3, 2020 1 message not in the archive objtool

lore
Share & tools
lore
#1 lore raw

PATCH 1/1 objtool: Documentation: document UACCESS warnings

In reply to a message not in the archive

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.

---
 .../Documentation/stack-validation.txt        | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/objtool/Documentation/stack-validation.txt +20 -0
index de094670050b..156fee13ba02 100644
@@ -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.
Signature · 1 line
2.25.1.696.g5e7596f4ac-goog
#2 lore raw
Quoted 18 lines · Nick Desaulniers

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.

---
 .../Documentation/stack-validation.txt        | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/objtool/Documentation/stack-validation.txt +0 -0
index de094670050b..156fee13ba02 100644
@@ -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:

tools/objtool/Documentation/stack-validation.txt they mean, and suggestions for how to fix them. · line 299

Quoted 10 lines
tools/objtool/Documentation/stack-validation.txt +8 -0
       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

Quoted 16 lines
tools/objtool/Documentation/stack-validation.txt +12 -0
+   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.
Signature · 1 line
~Randy
#3 lore raw
In reply to Nick Desaulniers
Quoted 8 lines · Nick Desaulniers

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.

Looks good, a minor nitpick below.

Quoted 9 lines
---
 .../Documentation/stack-validation.txt        | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/objtool/Documentation/stack-validation.txt +0 -0
index de094670050b..156fee13ba02 100644

tools/objtool/Documentation/stack-validation.txt they mean, and suggestions for how to fix them. · line 297

Quoted 9 lines
tools/objtool/Documentation/stack-validation.txt +6 -0
@@ -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() 
Quoted 3 lines
tools/objtool/Documentation/stack-validation.txt +3 -0
+
+   These functions should called to denote a minimal critical section around
+   access to __user variables. See also: https://lwn.net/Articles/517475/
Signature · 1 line
Kamalesh
maintainer
#4 lore raw
In reply to Nick Desaulniers
Quoted 29 lines · Nick Desaulniers

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.

---
 .../Documentation/stack-validation.txt        | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/objtool/Documentation/stack-validation.txt +9 -0
index de094670050b..156fee13ba02 100644
@@ -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/

tools/objtool/Documentation/stack-validation.txt they mean, and suggestions for how to fix them. · line 310

Quoted 10 lines
tools/objtool/Documentation/stack-validation.txt +10 -0
+
+   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.

#5 lore raw
In reply to Nick Desaulniers
Quoted 17 lines · Nick Desaulniers

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.

---
 .../Documentation/stack-validation.txt        | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/objtool/Documentation/stack-validation.txt +0 -0
index de094670050b..156fee13ba02 100644

tools/objtool/Documentation/stack-validation.txt they mean, and suggestions for how to fix them. · line 297

Quoted 9 lines
tools/objtool/Documentation/stack-validation.txt +6 -0
@@ -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

#6 lore raw

PATCH v2 1/1 objtool: Documentation: document UACCESS warnings

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.

---
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(+)
tools/objtool/Documentation/stack-validation.txt +26 -0
index de094670050b..faa47c3aafae 100644
@@ -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.
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
#7 lore raw
Quoted 11 lines · Nick Desaulniers

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.

Quoted 9 lines

---
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.

Signature · 1 line
Josh