From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0BB4C433E0 for ; Mon, 1 Feb 2021 21:15:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8ECE460232 for ; Mon, 1 Feb 2021 21:15:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231226AbhBAVPB (ORCPT ); Mon, 1 Feb 2021 16:15:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42724 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229879AbhBAVPA (ORCPT ); Mon, 1 Feb 2021 16:15:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612214013; 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=MmWztmGR5QmsHu5+b9WkkQVWRHsWQU/iqLJE+kYPk+k=; b=FQxg7qe752hONfMYUy/xn9tE+uE2QxaHeuZyptM4iuIwkYJfktR9UVygzts4sijR75uBq8 3basGuxJiCu/ROKdFW2diZ9WPKsKMgF7pgqBet1hYASzAZne6HazaEZs9sOZ+E4mCN6gEl ENdyUT7F2oC6lr3PTEJooeWx1INNfYc= 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-555-dKGUuVngP364zEE8h3y-2Q-1; Mon, 01 Feb 2021 16:13:29 -0500 X-MC-Unique: dKGUuVngP364zEE8h3y-2Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 00D2D1842140; Mon, 1 Feb 2021 21:13:27 +0000 (UTC) Received: from treble (ovpn-120-118.rdu2.redhat.com [10.10.120.118]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 70D2560BF3; Mon, 1 Feb 2021 21:13:24 +0000 (UTC) Date: Mon, 1 Feb 2021 15:13:22 -0600 From: Josh Poimboeuf To: Masahiro Yamada Cc: Linus Torvalds , Michal Marek , Linux Kernel Mailing List , Kees Cook , linux-hardening@vger.kernel.org, Linux Kbuild mailing list , Peter Zijlstra , Justin Forbes , Ondrej Mosnacek , Greg Kroah-Hartman , Christoph Hellwig , Miroslav Benes , David Laight , Jessica Yu Subject: Re: [PATCH RFC] kbuild: Prevent compiler mismatch with external modules Message-ID: <20210201211322.t2rxmvnrystc2ky7@treble> References: <20210128205207.awdbh4bmx56pxxjl@treble> <20210128213409.qxnclchjyq6v23up@treble> <20210128220803.fixcmuv4ceq5m7dy@treble> 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.12 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org On Fri, Jan 29, 2021 at 08:17:51AM +0900, Masahiro Yamada wrote: > [3] > Peterz already pointed out asm-goto as an example of ABI mismatch. > > I remember a trouble reported in the past due > to the mismatch of -mstack-protector-guard-offset. > > https://bugzilla.kernel.org/show_bug.cgi?id=201891 > > This has already been fixed, > and it will no longer happen though. This is kind of concerning though. It would be nice to somehow store KCLAGS in the config and warn if it changes unexpectedly. This can be a problem not only for OOT modules, but for regular kernel builds which have a .config copied from somewhere. Because of the toolchain-dependent kconfig options, features can silently disappear if the toolchain doesn't support them, due to a different compiler version, or even a missing library. > [2] > > As for this patch, it is wrong to do this check in the Makefile > parse stage. > > "make M=... clean" > "make M=... help" > > etc. will fail. > Such targets do not require the compiler in the first place. > > This check must be done before starting building something, > > Also, this patch is not applicable. > gcc-version.sh and clang-version.sh do not exist. > See linux-next. Something like so? diff --git a/Makefile b/Makefile index 95ab9856f357..10ca621369fb 100644 --- a/Makefile +++ b/Makefile @@ -1721,12 +1721,25 @@ KBUILD_MODULES := 1 build-dirs := $(KBUILD_EXTMOD) PHONY += modules -modules: $(MODORDER) +modules: ext_compiler_check $(MODORDER) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost $(MODORDER): descend @: +orig_name := $(if $(CONFIG_CC_IS_GCC),GCC,CLANG) +orig_minor := $(shell expr $(if $(CONFIG_CC_IS_GCC),$(CONFIG_GCC_VERSION),$(CONFIG_CLANG_VERSION)) / 100) +cur_namever := $(shell $(srctree)/scripts/cc-version.sh $(CC)) +cur_name := $(word 1,$(cur_namever)) +cur_minor := $(shell expr $(word 2,$(cur_namever)) / 100) +PHONY += ext_compiler_check +ext_compiler_check: + @if [ $(orig_name) != $(cur_name) ] || [ $(orig_minor) != $(cur_minor) ]; then \ + echo >&2 "warning: The compiler differs from the version which was used to build the kernel."; \ + echo >&2 "warning: Some kernel features are compiler-dependent."; \ + echo >&2 "warning: It's recommended that you change your compiler to match the version in the .config file."; \ + fi + PHONY += modules_install modules_install: _emodinst_ _emodinst_post