Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp595839pxb; Wed, 27 Jan 2021 16:12:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4kIUZdcJdbk65/NT/yYRcZbjlf8kHvX2mtoPpGN6Sm9M6f1Hze0xblZWnQQDm9dRJAuLS X-Received: by 2002:a05:6402:8cd:: with SMTP id d13mr11063725edz.335.1611792751617; Wed, 27 Jan 2021 16:12:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611792751; cv=none; d=google.com; s=arc-20160816; b=gG77prAIg4WMqIqdU7OFRnhKR/8PrCkiz+CbxScCHAz19IIy2dxhOgvvwdX0cTvf7N KQ4kdop4b6tarOCwwBv0EBON535pihCcPLMY66YpPWHJ4P7x2akAViADQqPeyMhGG/JT qD3I7V3Oh0z8Oz8bxs7cbvn3mRKeSn175BpT7p5ezP5zNtUKzE1Vu04manDRt5kscvPt m7DJYtro1ylHkH/rTF+KTuaX44FiN4MBq18y4FD+TIpWAWb0dqdBsA7oijHQWzCeELav lgXQ+kmPraw4t7xqni5KT3yIwTayQCHoX/w2uq3gla77eMXc9eoniWEz2nynkfhwFikn mo3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=nmUx9B3ctDFuPF+9qyK11uP4F24HgbZFCLayZjdworI=; b=TrkOaIm/+TjkCwDVUdZSb/IEQpATY5PHtQmQVziApbxlPbXUgmyc7MZfYJE0idxrA8 LcZRWcMYc7q3vnOjHO6uqwpIQaTH6hFjsPLBL9QDs+lnKD6uq50alcyWFa28y++tBEfH wvLe/wsVOIWaugC7zo/bJF/qNObEugRo8xXik8OPheWY7TMn/zPYTfA3QqOjbEp3KlMH faeSsHsp5uBRp7j417mmFL1LoOoyRaRecKtiDavRAUgVeP7Rrj+TkTtUM3vYrqHR/4kn /0u+mA5NQNYkAijXVkvd9utEz7sAKB9Q6u0dG8bSWiDwOb/c/1YEGc6gcUqmJ6ImsRvB ioeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=dGoevGX3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ah19si1564476ejc.76.2021.01.27.16.12.07; Wed, 27 Jan 2021 16:12:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=dGoevGX3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344263AbhA0SDm (ORCPT + 99 others); Wed, 27 Jan 2021 13:03:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344148AbhA0SDZ (ORCPT ); Wed, 27 Jan 2021 13:03:25 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86490C061786; Wed, 27 Jan 2021 10:02:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=nmUx9B3ctDFuPF+9qyK11uP4F24HgbZFCLayZjdworI=; b=dGoevGX3QmkwspJI/OcjS4PdEB otTuvRN8H2wmmLy428qul28x8SshGvG2iwX/XN+sQyreT+bV0IVptj4h0DXbxb9q6SK4TRzNL0pna 2a17Wzw/Qy0qI0jBMjNIW8/WMCHlCps/e8tlDuAZsoHnh1FFLVdV8t6ijdNuYj3Yboq6hpw4aUcsm Lb+5HPxPzPGemJWzYSQy6lItWWrZ/o6kQyvRzVIUf2S3IomXyh43llg6KRmjNHUaQO/ly1KlUGtqP qfJeYCRhp+7wu/qTlaq1peBp6dd5SNvnfVhgQnZ/oRxN7qVoELZG1/VcUUtq0agfeawqDCy9Pc0P2 mLgPh3Iw==; Received: from hch by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1l4p8x-007KFR-3d; Wed, 27 Jan 2021 18:02:19 +0000 Date: Wed, 27 Jan 2021 18:02:15 +0000 From: Christoph Hellwig To: Josh Poimboeuf Cc: Kees Cook , linux-kernel@vger.kernel.org, Masahiro Yamada , Michal Marek , linux-hardening@vger.kernel.org, linux-kbuild@vger.kernel.org, Peter Zijlstra , Justin Forbes , Ondrej Mosnacek , Greg Kroah-Hartman Subject: Re: [PATCH RFC] gcc-plugins: Handle GCC version mismatch for OOT modules Message-ID: <20210127180215.GA1745339@infradead.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Please don't add all this garbage. We only add infrastructure to the kernel for what the kernel itself needs, not for weird out of tree infrastructure. On Mon, Jan 25, 2021 at 02:42:10PM -0600, Josh Poimboeuf 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 > Signed-off-by: Josh Poimboeuf > --- > 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 > ---end quoted text---