From patchwork Tue Jul 10 01:35:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 141504 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3282821ljj; Mon, 9 Jul 2018 18:36:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcnp0dVBbq/e2cL4Chy+sOWH2dCe7uGMo6xtY7os3jE8EYDcy+Diqf9tWScpZA76KxdU+VL X-Received: by 2002:a62:3b89:: with SMTP id w9-v6mr23536519pfj.80.1531186616303; Mon, 09 Jul 2018 18:36:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531186616; cv=none; d=google.com; s=arc-20160816; b=uS7yK/DCLYB4yHJ4W6lMUSosroslE+zOaqhUzvWgNSu4VW2Xrfi/9xLsfXVry8TKzA MgwDIn4KT22qYkHVNYZ+4aroTYoA/xRwRrPZX7iPmLzyyrO64gD6t+cZ61lcJvo9QUHo lUjMGz7GtqgjeKe899CCR2BKqnfri5UcQUvq3PW4Q0Si6FR0JTUUzrUwBAhMlSrjt5YI QPmR17KRhDm+AMStFNimaK62mksVgPgz37+KA1MISyK4yEdLoa97Wj+lj86CVF+/bZtI rhs/XQL2BJBEPkIq98WACqhdKMyRhGcza8rPm1dpKM3LEoi0Bynx9sQj3cmpN6npvDAe D7Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter:arc-authentication-results; bh=jnGQr9wGQbDJeGs5a28ylyB4ALcWW0obUjiDpiiJCT0=; b=FmgX1R8dMsxE8w6pu6aP1U258lJcpnbRn6BeFdjan+/qXvbgKhkdkrz7Bv9Z3iQl1A Qpoek5Qqjr6It1VkpWrMkzG1R2psF74l4NkvupEbyv1CmylA6ihD75aXOy6GfpTMvWiU mKiJQw8ndW97vxZ3OWXgwD0ozAx/IhLIdWm4u2US/NGup8St+xQWsWymkfWbRl7YtFr3 0+OyVRz9XGw0uVvOkjrh1R5be6AWNH43eA9rJ4YxdIDhAWOygD/sB4YE9+mphhmx7ckn PtKDPFmOHV4uNL/gfgsiqz0QwPYSkzfRVuyFXL6ogahfMC0EGmsYNJg9/6GRnuG6/TGJ zhEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=KGBjRQKu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r127-v6si13336094pfr.154.2018.07.09.18.36.56; Mon, 09 Jul 2018 18:36:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=KGBjRQKu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933304AbeGJBgu (ORCPT + 12 others); Mon, 9 Jul 2018 21:36:50 -0400 Received: from conuserg-08.nifty.com ([210.131.2.75]:30112 "EHLO conuserg-08.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754580AbeGJBgn (ORCPT ); Mon, 9 Jul 2018 21:36:43 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id w6A1ZWJu027668; Tue, 10 Jul 2018 10:35:33 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com w6A1ZWJu027668 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1531186533; bh=jnGQr9wGQbDJeGs5a28ylyB4ALcWW0obUjiDpiiJCT0=; h=From:To:Cc:Subject:Date:From; b=KGBjRQKu/iLrQPlqe1d1cD5Exsnc8r8yUYZiVa51edOpN6ZIJJiBHF19A0PpEDzPf +IofkOjAaGsNgYoRLkoxXaejC2b/GPaF7i2PjN8TK5LxMHkeCBXcL5F8m+zNfR2lc0 7kuqLXPltjedS+pQJI5zYEZYi6SH5dAGdG3UDoTch9qy5gtwmGnFGmOIpnMIoRG+tV 1lcypGlLDZ+s/aUSMbOiMjVlhF2TRSjq8exKvJ6ZUgaUtAUwaFLYi072rwU0p4Evx/ h3Fj7poYLSqtM6fODMGl4GHxznN15SJ1yN4bLT7AZPqKsuFR+IcwH9j7RbdGujz5ev 5WYsPUJD4NhXg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Ingo Molnar , Thomas Gleixner , Josh Poimboeuf , x86@kernel.org Cc: Linus Torvalds , Masahiro Yamada , "H. Peter Anvin" , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Michal Marek Subject: [PATCH v2] objtool: move libelf detection to Kconfig from Makefile Date: Tue, 10 Jul 2018 10:35:16 +0900 Message-Id: <1531186516-15764-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, users are allowed to enable STACK_VALIDATION regardless of the compiler capability. The top-level Makefile warns or breaks the build if it turns out that the host compiler cannot link libelf. Move the libelf test to Kconfig so that users can enable the feature only when the host compiler can build the objtool. The ugly check in the Makefile will go away. Signed-off-by: Masahiro Yamada Acked-by: Josh Poimboeuf --- Changes in v2: - Move package information to help of STACK_VALIDATION Makefile | 14 +------------- arch/x86/Kconfig | 2 +- arch/x86/Kconfig.debug | 2 +- lib/Kconfig.debug | 6 +++++- scripts/Makefile.build | 2 -- 5 files changed, 8 insertions(+), 18 deletions(-) -- 2.7.4 diff --git a/Makefile b/Makefile index 925c55f..65befa0 100644 --- a/Makefile +++ b/Makefile @@ -927,19 +927,7 @@ endif export mod_sign_cmd ifdef CONFIG_STACK_VALIDATION - has_libelf := $(call try-run,\ - echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf -,1,0) - ifeq ($(has_libelf),1) - objtool_target := tools/objtool FORCE - else - ifdef CONFIG_UNWINDER_ORC - $(error "Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel") - else - $(warning "Cannot use CONFIG_STACK_VALIDATION=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel") - endif - SKIP_STACK_VALIDATION := 1 - export SKIP_STACK_VALIDATION - endif + objtool_target := tools/objtool endif diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index f1dbb4e..c1ded99 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -434,7 +434,7 @@ config GOLDFISH config RETPOLINE bool "Avoid speculative indirect branches in kernel" default y - select STACK_VALIDATION if HAVE_STACK_VALIDATION + imply STACK_VALIDATION help Compile kernel with the retpoline compiler options to guard against kernel-to-user data leaks by avoiding speculative indirect diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug index c6dd1d9..4713b3c 100644 --- a/arch/x86/Kconfig.debug +++ b/arch/x86/Kconfig.debug @@ -364,7 +364,7 @@ choice config UNWINDER_ORC bool "ORC unwinder" depends on X86_64 - select STACK_VALIDATION + depends on STACK_VALIDATION ---help--- This option enables the ORC (Oops Rewind Capability) unwinder for unwinding kernel stack traces. It uses a custom data format which is diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 8838d11..f4d48af 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -364,7 +364,7 @@ config FRAME_POINTER config STACK_VALIDATION bool "Compile-time stack metadata validation" depends on HAVE_STACK_VALIDATION - default n + depends on $(success,echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf -) help Add compile-time checks to validate stack metadata, including frame pointers (if CONFIG_FRAME_POINTER is enabled). This helps ensure @@ -373,6 +373,10 @@ config STACK_VALIDATION This is also a prerequisite for generation of ORC unwind data, which is needed for CONFIG_UNWINDER_ORC. + To enable this, the host compiler needs to be able to link libelf. + If it is missing on your system, please install libelf-dev, + libelf-devel or elfutils-libelf-devel. + For more information, see tools/objtool/Documentation/stack-validation.txt. diff --git a/scripts/Makefile.build b/scripts/Makefile.build index e7889f4..154205b 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -243,7 +243,6 @@ endif # -record-mcount endif # CONFIG_FTRACE_MCOUNT_RECORD ifdef CONFIG_STACK_VALIDATION -ifneq ($(SKIP_STACK_VALIDATION),1) __objtool_obj := $(objtree)/tools/objtool/objtool @@ -282,7 +281,6 @@ objtool_obj = $(if $(patsubst y%,, \ $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \ $(__objtool_obj)) -endif # SKIP_STACK_VALIDATION endif # CONFIG_STACK_VALIDATION # Rebuild all objects when objtool changes, or is enabled/disabled.