From: Arnd Bergmann <arnd@arndb.de>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Masahiro Yamada" <yamada.masahiro@socionext.com>,
"Al Viro" <viro@zeniv.linux.org.uk>,
"Arnd Bergmann" <arnd@arndb.de>,
"Changbin Du" <changbin.du@gmail.com>,
"Marc Zyngier" <marc.zyngier@arm.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Dave Martin" <Dave.Martin@arm.com>,
"Kees Cook" <keescook@chromium.org>,
"Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH] copy_{to,from}_user(): fix compile-time sanity checks with gcc -Og
Date: Fri, 2 Nov 2018 16:56:58 +0100 [thread overview]
Message-ID: <20181102155710.2299475-1-arnd@arndb.de> (raw)
When CONFIG_CC_OPTIMIZE_FOR_DEBUGGING is set, we get countless warnings
like
In function 'check_copy_size',
inlined from 'copy_from_user' at include/linux/uaccess.h:146:6,
inlined from '__copy_siginfo_from_user' at kernel/signal.c:3032:6:
include/linux/thread_info.h:147:4: error: call to '__bad_copy_to' declared with attribute error: copy destination size is too small
It seems that constant propagation doesn't work well enough to make
this code reliable, so turn it off for that configuration.
Cc: Changbin Du<changbin.du@gmail.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
include/linux/thread_info.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index 8d8821b3689a..762f379bdf5d 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -138,6 +138,11 @@ static __always_inline bool
check_copy_size(const void *addr, size_t bytes, bool is_source)
{
int sz = __compiletime_object_size(addr);
+
+ /* constant propagation doesn't work well with -Og */
+ if (IS_ENABLED(CONFIG_CC_OPTIMIZE_FOR_DEBUGGING))
+ return true;
+
if (unlikely(sz >= 0 && sz < bytes)) {
if (!__builtin_constant_p(bytes))
copy_overflow(sz, bytes);
--
2.18.0
next reply other threads:[~2018-11-02 15:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-02 15:56 Arnd Bergmann [this message]
2018-11-03 0:03 ` Changbin Du
2018-11-03 15:46 ` Arnd Bergmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181102155710.2299475-1-arnd@arndb.de \
--to=arnd@arndb.de \
--cc=Dave.Martin@arm.com \
--cc=akpm@linux-foundation.org \
--cc=alex.bennee@linaro.org \
--cc=alexander.levin@verizon.com \
--cc=changbin.du@gmail.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.zyngier@arm.com \
--cc=viro@zeniv.linux.org.uk \
--cc=yamada.masahiro@socionext.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®