Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3347208pxb; Mon, 25 Jan 2021 13:31:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJzfDQ7Al/8eARynWhyRjugJKVpE/L7TckccdOIc/7JBSpQB0+igx5q1aRVP63Fa5FvEqYw3 X-Received: by 2002:a17:907:20b9:: with SMTP id pw25mr1520558ejb.262.1611610283084; Mon, 25 Jan 2021 13:31:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611610283; cv=none; d=google.com; s=arc-20160816; b=BNsIspa8IKd6DfbjdXF4AuGb6a6aN+bmKTLHbvoINakhacPefxKv3iKFYhW9mszLP1 PX4zAB2cNQopZEltSuJHL4CkFTGdxsp/G0JiAdUFjuDmrmxBb+/V3susvpJWsFwoD9vQ v2BmJBwazecMtI5givN9og6iNW5uvG6upP1rS0ydf/mo3bdtXTdLQGvhPiKW9Gzc/QWB 83jAJ+i2fYpl+DApUZfO141GdkenSOnePUHpSX0LmWsurEH8Mcwg/VlIIdo92BbLyLy1 qXLP5zzG59+W7/vMWJ1eCGON4jzdZMVUA9nSzSjk/zhRk6PmBq81LErp/IiTfFAl2Na7 EbZg== 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=j5BAnkcKu0iXTsZM9+PxuOLyHl8DKz/n3Sg7EK2+zzU=; b=Y0ou1lWnPlUufNblkQLrt3Toogaw+CWbfipZlA3EPt4Uu9+qphE6f0U1x645deKuIN kltatuzZoGMvnSHtMdVtYv2olGIv+cFG5zfFLrs3dDY1YT2UqNhzBBjh+6GoFHZJVQSH i4kI83jILK6z/J040Ww8uTbJBSN8QLKqKhPv8ajdqDz/BMbO562qDsuI9XL0lridMjoj VqeV75t9Kz6OLFUlk3At+od2ijK8hXoc1+XTt1+jA6fYhUZDTsC9QH50v1hLp8iRyviF VZAJiUCyegqx9UaJEhcxUVBZFBGtYjd+EIflPPCLtsgMidYLrqNgqI5tvtrdtX+IcP0f nioQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fN4Okbqo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kw25si5565068ejc.150.2021.01.25.13.30.59; Mon, 25 Jan 2021 13:31:23 -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=@redhat.com header.s=mimecast20190719 header.b=fN4Okbqo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732653AbhAYVaV (ORCPT + 99 others); Mon, 25 Jan 2021 16:30:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:33869 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732618AbhAYV3a (ORCPT ); Mon, 25 Jan 2021 16:29:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611610083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=j5BAnkcKu0iXTsZM9+PxuOLyHl8DKz/n3Sg7EK2+zzU=; b=fN4OkbqoAan/ttNxHx2LNuFze2nqOBw+pwRSy0432xBOlTz4/4231Cbdn/XzScs7axc0gY jCHobhBOX50Y74d5lNOOm18IMmZUM7QRIIfhyG26QH6c8EL+uHIwV89+DmJV3PkS0EJ2RG 81WI3rWWr89Ar2bMlc7EvDdS4AQq3cQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-400-ufg7fRfAMkqDK9Jy7oZDEQ-1; Mon, 25 Jan 2021 16:27:59 -0500 X-MC-Unique: ufg7fRfAMkqDK9Jy7oZDEQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6649B18C89CF; Mon, 25 Jan 2021 21:27:58 +0000 (UTC) Received: from treble (ovpn-120-118.rdu2.redhat.com [10.10.120.118]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 41BC260938; Mon, 25 Jan 2021 21:27:57 +0000 (UTC) Date: Mon, 25 Jan 2021 15:27:55 -0600 From: Josh Poimboeuf To: Masahiro Yamada Cc: Kees Cook , Linux Kernel Mailing List , Michal Marek , linux-hardening@vger.kernel.org, Linux Kbuild mailing list , Peter Zijlstra , Justin Forbes , Ondrej Mosnacek Subject: Re: [PATCH RFC] gcc-plugins: Handle GCC version mismatch for OOT modules Message-ID: <20210125212755.jfwlqogpcarmxdgt@treble> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 26, 2021 at 06:16:01AM +0900, Masahiro Yamada wrote: > On Tue, Jan 26, 2021 at 5:42 AM 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 > > --- > > > We are based on the assumption that we use the same > compiler for in-tree and out-of-tree. Sorry, but that assumption isn't based in reality. And it's not enforced. > 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? If you read the patch you'll notice that it handles that case, when it's caused by GCC mismatch. However, as alluded to in the [1] footnote, it doesn't handle the case where the OOT build system doesn't have gcc-plugin-devel installed. Then CONFIG_GCC_PLUGIN_RANDSTRUCT gets silently disabled and the build succeeds! That happens even without a GCC mismatch. > This patch is ugly, and not doing the right thing. Maybe, but I doubt the solution is to make assumptions. -- Josh