linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC v1] copy_{to,from}_user(): only inline when !__CHECKER__
@ 2018-12-09 20:44 Tycho Andersen
  2018-12-09 21:02 ` Al Viro
  0 siblings, 1 reply; 9+ messages in thread
From: Tycho Andersen @ 2018-12-09 20:44 UTC (permalink / raw)
  To: linux-sparse, kernel-hardening; +Cc: linux-kernel, Tycho Andersen

While working on some additional copy_to_user() checks for sparse, I
noticed that sparse's current copy_to_user() checks are not triggered. This
is because copy_to_user() is declared as __always_inline, and sparse
specifically looks for a call instruction to copy_to_user() when it tries
to apply the checks.

A quick fix is to explicitly not inline when __CHECKER__ is defined, so
that sparse will be able to analyze all the copy_{to,from}_user calls.
There may be some refactoring in sparse that we can do to fix this,
although it's not immediately obvious to me how, hence the RFC-ness of this
patch.

Signed-off-by: Tycho Andersen <tycho@tycho.ws>
---
 include/linux/uaccess.h | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
index efe79c1cdd47..f20a2d173e1f 100644
--- a/include/linux/uaccess.h
+++ b/include/linux/uaccess.h
@@ -140,7 +140,13 @@ extern unsigned long
 _copy_to_user(void __user *, const void *, unsigned long);
 #endif
 
-static __always_inline unsigned long __must_check
+#ifdef __CHECKER__
+#define uaccess_inline __attribute__((__noinline__))
+#else
+#define uaccess_inline __always_inline
+#endif
+
+static uaccess_inline unsigned long __must_check
 copy_from_user(void *to, const void __user *from, unsigned long n)
 {
 	if (likely(check_copy_size(to, n, false)))
@@ -148,7 +154,7 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
 	return n;
 }
 
-static __always_inline unsigned long __must_check
+static uaccess_inline unsigned long __must_check
 copy_to_user(void __user *to, const void *from, unsigned long n)
 {
 	if (likely(check_copy_size(from, n, true)))
-- 
2.19.1

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

end of thread, other threads:[~2018-12-09 22:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-09 20:44 [RFC v1] copy_{to,from}_user(): only inline when !__CHECKER__ Tycho Andersen
2018-12-09 21:02 ` Al Viro
2018-12-09 21:25   ` Tycho Andersen
2018-12-09 21:39     ` Luc Van Oostenryck
2018-12-09 21:53       ` Tycho Andersen
2018-12-09 21:56       ` Al Viro
2018-12-09 22:08         ` Luc Van Oostenryck
2018-12-09 21:46     ` Al Viro
2018-12-09 21:56       ` Tycho Andersen

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