From: Masahiro Yamada <masahiroy@kernel.org>
To: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Kees Cook <keescook@chromium.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Michal Marek <michal.lkml@markovi.net>,
linux-hardening@vger.kernel.org,
Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Justin Forbes <jforbes@redhat.com>,
Ondrej Mosnacek <omosnace@redhat.com>
Subject: Re: [PATCH RFC] gcc-plugins: Handle GCC version mismatch for OOT modules
Date: Tue, 26 Jan 2021 06:16:01 +0900 [thread overview]
Message-ID: <CAK7LNAS=uOi=8xJU=NiKnXQW2iCazbErg_TX0gL9oayBiDffiA@mail.gmail.com> (raw)
In-Reply-To: <efe6b039a544da8215d5e54aa7c4b6d1986fc2b0.1611607264.git.jpoimboe@redhat.com>
On Tue, Jan 26, 2021 at 5:42 AM Josh Poimboeuf <jpoimboe@redhat.com> wrote:
>
> When building out-of-tree kernel modules, the build system doesn't
> require the GCC version to match the version used to build the original
> kernel. That's probably [1] fine.
>
> In fact, for many distros, the version of GCC used to build the latest
> kernel doesn't necessarily match the latest released GCC, so a GCC
> mismatch turns out to be pretty common. And with CONFIG_MODVERSIONS
> it's probably more common.
>
> So a lot of users have come to rely on being able to use a different
> version of GCC when building OOT modules.
>
> But with GCC plugins enabled, that's no longer allowed:
>
> cc1: error: incompatible gcc/plugin versions
> cc1: error: failed to initialize plugin ./scripts/gcc-plugins/structleak_plugin.so
>
> That error comes from the plugin's call to
> plugin_default_version_check(), which strictly enforces the GCC version.
> The strict check makes sense, because there's nothing to prevent the GCC
> plugin ABI from changing -- and it often does.
>
> But failing the build isn't necessary. For most plugins, OOT modules
> will otherwise work just fine without the plugin instrumentation.
>
> When a GCC version mismatch is detected, print a warning and disable the
> plugin. The only exception is the RANDSTRUCT plugin which needs all
> code to see the same struct layouts. In that case print an error.
>
> [1] Ignoring, for the moment, that the kernel now has
> toolchain-dependent kconfig options, which can silently disable
> features and cause havoc when compiler versions differ, or even when
> certain libraries are missing. This is a separate problem which
> also needs to be addressed.
>
> Reported-by: Ondrej Mosnacek <omosnace@redhat.com>
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> ---
We are based on the assumption that we use the same
compiler for in-tree and out-of-tree.
If people use a different compiler, they must be
prepared for any possible problem.
Using different compiler flags for in-tree and out-of-tree
is even more dangerous.
For example, CONFIG_GCC_PLUGIN_RANDSTRUCT is enabled
for in-tree build, and then disabled for out-of-tree modules,
the struct layout will mismatch, won't it?
This patch is ugly, and not doing the right thing.
> scripts/Makefile.gcc-plugins | 19 +++++++++++++++++++
> scripts/Makefile.kcov | 11 +++++++++++
> 2 files changed, 30 insertions(+)
>
> diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
> index 952e46876329..7227692fba59 100644
> --- a/scripts/Makefile.gcc-plugins
> +++ b/scripts/Makefile.gcc-plugins
> @@ -51,6 +51,25 @@ export DISABLE_ARM_SSP_PER_TASK_PLUGIN
> GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y))
> # The sancov_plugin.so is included via CFLAGS_KCOV, so it is removed here.
> GCC_PLUGINS_CFLAGS := $(filter-out %/sancov_plugin.so, $(GCC_PLUGINS_CFLAGS))
> +
> +# Out-of-tree module check: If there's a GCC version mismatch, disable plugins
> +# and print a warning. Otherwise the OOT module build will fail due to
> +# plugin_default_version_check().
> +ifneq ($(GCC_PLUGINS_CFLAGS),)
> + ifneq ($(KBUILD_EXTMOD),)
> + ifneq ($(CONFIG_GCC_VERSION), $(shell $(srctree)/scripts/gcc-version.sh $(HOSTCXX)))
> +
> + ifdef CONFIG_GCC_PLUGIN_RANDSTRUCT
> + $(error error: CONFIG_GCC_PLUGIN_RANDSTRUCT requires out-of-tree modules to be built using the same GCC version as the kernel.)
> + endif
> +
> + $(warning warning: Disabling GCC plugins for out-of-tree modules due to GCC version mismatch.)
> + $(warning warning: The following plugins have been disabled: $(gcc-plugin-y))
> + GCC_PLUGINS_CFLAGS :=
> + endif
> + endif
> +endif
> +
> export GCC_PLUGINS_CFLAGS
>
> # Add the flags to the build!
> diff --git a/scripts/Makefile.kcov b/scripts/Makefile.kcov
> index 67e8cfe3474b..63a2bc2aabb2 100644
> --- a/scripts/Makefile.kcov
> +++ b/scripts/Makefile.kcov
> @@ -3,4 +3,15 @@ kcov-flags-$(CONFIG_CC_HAS_SANCOV_TRACE_PC) += -fsanitize-coverage=trace-pc
> kcov-flags-$(CONFIG_KCOV_ENABLE_COMPARISONS) += -fsanitize-coverage=trace-cmp
> kcov-flags-$(CONFIG_GCC_PLUGIN_SANCOV) += -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so
>
> +# Out-of-tree module check for GCC version mismatch.
> +# See the similar check in scripts/Makefile.gcc-plugins
> +ifneq ($(CONFIG_GCC_PLUGIN_SANCOV),)
> + ifneq ($(KBUILD_EXTMOD),)
> + ifneq ($(CONFIG_GCC_VERSION), $(shell $(srctree)/scripts/gcc-version.sh $(HOSTCXX)))
> + $(warning warning: Disabling CONFIG_GCC_PLUGIN_SANCOV for out-of-tree modules due to GCC version mismatch.)
> + kcov-flags-y := $(filter-out %/sancov_plugin.so, $(kcov-flags-y))
> + endif
> + endif
> +endif
> +
> export CFLAGS_KCOV := $(kcov-flags-y)
> --
> 2.29.2
>
--
Best Regards
Masahiro Yamada
next prev parent reply other threads:[~2021-01-25 21:20 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-25 20:42 [PATCH RFC] gcc-plugins: Handle GCC version mismatch for OOT modules Josh Poimboeuf
2021-01-25 21:16 ` Masahiro Yamada [this message]
2021-01-25 21:27 ` Josh Poimboeuf
2021-01-25 21:44 ` Masahiro Yamada
2021-01-25 22:07 ` Josh Poimboeuf
2021-01-26 8:13 ` Greg KH
2021-01-26 12:44 ` Justin Forbes
2021-01-26 13:51 ` Greg KH
2021-01-26 14:51 ` Josh Poimboeuf
2021-01-26 15:00 ` Greg KH
2021-01-26 15:15 ` Peter Zijlstra
2021-01-26 15:46 ` Josh Poimboeuf
2021-01-26 16:05 ` Peter Zijlstra
2021-01-26 16:15 ` Justin Forbes
2021-01-26 16:19 ` Josh Poimboeuf
2021-01-26 17:06 ` Greg KH
2021-01-26 17:47 ` Justin Forbes
2021-01-26 16:22 ` David Laight
2021-01-27 18:03 ` Christoph Hellwig
2021-01-26 8:12 ` Greg KH
2021-01-25 22:03 ` Kees Cook
2021-01-25 22:19 ` Josh Poimboeuf
2021-01-26 17:56 ` Kees Cook
2021-01-26 18:43 ` Josh Poimboeuf
2021-01-26 22:59 ` Kees Cook
2021-01-26 23:32 ` Josh Poimboeuf
2021-01-26 1:53 ` Masahiro Yamada
2021-01-26 12:16 ` David Laight
2021-01-27 18:02 ` Christoph Hellwig
2021-01-27 18:38 ` Josh Poimboeuf
2021-01-27 18:43 ` Christoph Hellwig
2021-01-27 18:51 ` Josh Poimboeuf
2021-01-27 22:09 ` David Laight
2021-01-28 14:29 ` Christoph Hellwig
2021-01-28 15:45 ` Josh Poimboeuf
2021-03-02 23:26 ` Josh Poimboeuf
2021-03-03 18:49 ` Masahiro Yamada
2021-03-03 19:15 ` Josh Poimboeuf
2021-03-03 19:25 ` Linus Torvalds
2021-03-03 19:38 ` Josh Poimboeuf
2021-03-03 19:57 ` Linus Torvalds
2021-03-03 20:24 ` Josh Poimboeuf
2021-03-03 20:31 ` Josh Poimboeuf
2021-03-03 20:56 ` Linus Torvalds
2021-03-03 21:45 ` Josh Poimboeuf
2021-03-04 12:27 ` Masahiro Yamada
2021-03-04 15:08 ` Josh Poimboeuf
2021-03-04 15:35 ` Masahiro Yamada
2021-03-04 19:12 ` Linus Torvalds
2021-03-05 2:41 ` Josh Poimboeuf
2021-03-05 2:49 ` Linus Torvalds
2021-03-05 16:03 ` Masahiro Yamada
2021-03-05 19:18 ` Josh Poimboeuf
2021-03-08 9:39 ` David Laight
2021-03-05 15:31 ` Masahiro Yamada
2021-03-03 21:52 ` Kees Cook
2021-03-04 12:26 ` Masahiro Yamada
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='CAK7LNAS=uOi=8xJU=NiKnXQW2iCazbErg_TX0gL9oayBiDffiA@mail.gmail.com' \
--to=masahiroy@kernel.org \
--cc=jforbes@redhat.com \
--cc=jpoimboe@redhat.com \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.lkml@markovi.net \
--cc=omosnace@redhat.com \
--cc=peterz@infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).