From patchwork Tue Jan 2 20:05:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 123215 Delivered-To: patch@linaro.org Received: by 10.80.135.92 with SMTP id 28csp4761041edv; Tue, 2 Jan 2018 12:06:38 -0800 (PST) X-Google-Smtp-Source: ACJfBotqLT7FWwxaA+vKN0cz35RT4VreWlv6P1vyW+G72zuq52JOU6cBEI8obRahGliLCNFkK2m9 X-Received: by 10.159.198.10 with SMTP id f10mr45807868plo.356.1514923598016; Tue, 02 Jan 2018 12:06:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514923598; cv=none; d=google.com; s=arc-20160816; b=Eu4cx5LwXrA8mY25leRyJsfiXj8EI/ozjtYTFaUH6b1UaTzkH9/lhTnrC9AmsP/7Iu NVBCSywjihUHxZ6fqJWoBeKbEZYNLu4CpQOwu2iO3W4qMGGMlPVnEZ9ryJcocXIlBoxI K3H8YFsN0cS3Fv/vuelX7rST7Nt7KN+l5COOvu0S9b5nRg2IAWLbR9padwXDHPf4dgSR +TfkmHu20Pdd0ISlB2tLLy6b0y/3sJat1/80WicUYFeaW9YePrD5ZkxLdEGJrOe33Fxu lzCfWXbpH2AOrwzWJwPGRw8DZO9/12+bm2qRh1vf3NcIKbLhsoSD43OXjVtaxGuUXT6c FlaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=9pf2nmv48uHqsDbsl+hfOY5WaUyvrm1nnNGc9/9m6Qg=; b=T7qXe5l6sp2B+R2a5vhmEHXuZcgYPK6Pc/nz/dZeuwmgbiIkj9Eijx9v9agDzEfM76 94bf/OAHYjQP/1MfJcP3iF4Rz9V4jWcSGwyZGlQcrSurShTWKiwhGEpLmZUMXORrApwG fUzCaU7ll119QlSLo9Ke0yDdJzspwOTRJ44YYNljqOyQft6a1sw3/GMHkXIRoKZMdJCD JUlualbWmoo13cQWju1oq3xzbPTX6qRVUeaJI4djo6K38CWXXOLth0kt2XMHZpr98v9F tu2ia3DruyOFgmrsVZQWYU0Egb3KzrQi+XD1Pt0zA7xh0Y34ZEEoLqJL3I/c8yETSDjJ QyLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JvakjjXX; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o14si4476037pgq.631.2018.01.02.12.06.37; Tue, 02 Jan 2018 12:06:38 -0800 (PST) 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=@linaro.org header.s=google header.b=JvakjjXX; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751099AbeABUGa (ORCPT + 28 others); Tue, 2 Jan 2018 15:06:30 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:41910 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751061AbeABUG0 (ORCPT ); Tue, 2 Jan 2018 15:06:26 -0500 Received: by mail-wm0-f67.google.com with SMTP id g75so63337433wme.0 for ; Tue, 02 Jan 2018 12:06:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9pf2nmv48uHqsDbsl+hfOY5WaUyvrm1nnNGc9/9m6Qg=; b=JvakjjXXh2ftac/uQdStpmRnyog8dVy1B1dV3/FBRYhclGcwN1Nf1ULl77WmER9ry4 qNvpqUIkOxaXMPtj6B3oJYPN87PgdaiNOi0rNpCB5XAS3BaMGwa31IA7QPoscn3u7sb0 uOQNLx6iterfuYqWKriCvDY/4G6QygREzc7s0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9pf2nmv48uHqsDbsl+hfOY5WaUyvrm1nnNGc9/9m6Qg=; b=Newx9+Mz59U4kOGNBIBAMoHew4qWP2J4iyr7F07UhtO8ZWmwYTClRXkggSxBSzoupe T5wtjKKBppP0YHhG1NikrDDJD6ZKZjmiVGO1uTxm69T/e/P4ufCd4rs6E/EFPcHqyjo2 sPziKBTlgYOLMkF0U9sCfpKCLhpRaaTrylVRhLdpoSd6rg4tWGyXCdoqHo5T2Z6EDsYh 2eiAness/vBtIAMatyQcM/xxGkrHrSxgP/dAcscMs9Q4iKwLkl5/zuPK4NyYOJX1GlDa AVLOO2pz+HXGhpkb7QFBW7ZAZAQI8v+u10MJoemcPcbzcuIlHdcH17u+8zdRNt58pGjc UhQA== X-Gm-Message-State: AKGB3mLiQqKAsKCrwh92FdOr54GQe9pLFUFPmn/WIkSOmuWtLsVYsree gHxvjaA2NaCHUFVNwMHnZ/i2uI4plZQ= X-Received: by 10.28.97.194 with SMTP id v185mr11849434wmb.21.1514923584444; Tue, 02 Jan 2018 12:06:24 -0800 (PST) Received: from localhost.localdomain ([160.89.138.198]) by smtp.gmail.com with ESMTPSA id m70sm19128526wma.36.2018.01.02.12.06.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 12:06:23 -0800 (PST) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , "H. Peter Anvin" , Ralf Baechle , Arnd Bergmann , Heiko Carstens , Kees Cook , Will Deacon , Michael Ellerman , Thomas Garnier , Thomas Gleixner , "Serge E. Hallyn" , Bjorn Helgaas , Benjamin Herrenschmidt , Russell King , Paul Mackerras , Catalin Marinas , "David S. Miller" , Petr Mladek , Ingo Molnar , James Morris , Andrew Morton , Nicolas Pitre , Josh Poimboeuf , Steven Rostedt , Martin Schwidefsky , Sergey Senozhatsky , Linus Torvalds , Jessica Yu , linux-arm-kernel@lists.infradead.org, linux-mips@linux-mips.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, x86@kernel.org, matt@codeblueprint.co.uk Subject: [PATCH v7 02/10] module: allow symbol exports to be disabled Date: Tue, 2 Jan 2018 20:05:41 +0000 Message-Id: <20180102200549.22984-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180102200549.22984-1-ard.biesheuvel@linaro.org> References: <20180102200549.22984-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To allow existing C code to be incorporated into the decompressor or the UEFI stub, introduce a CPP macro that turns all EXPORT_SYMBOL_xxx declarations into nops, and #define it in places where such exports are undesirable. Note that this gets rid of a rather dodgy redefine of linux/export.h's header guard. Cc: matt@codeblueprint.co.uk Cc: keescook@chromium.org Cc: jeyu@kernel.org Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/kaslr.c | 5 +---- drivers/firmware/efi/libstub/Makefile | 3 ++- include/linux/export.h | 9 +++++++++ 3 files changed, 12 insertions(+), 5 deletions(-) -- 2.11.0 diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c index 8199a6187251..3a2a6d7049e4 100644 --- a/arch/x86/boot/compressed/kaslr.c +++ b/arch/x86/boot/compressed/kaslr.c @@ -23,11 +23,8 @@ * _ctype[] in lib/ctype.c is needed by isspace() of linux/ctype.h. * While both lib/ctype.c and lib/cmdline.c will bring EXPORT_SYMBOL * which is meaningless and will cause compiling error in some cases. - * So do not include linux/export.h and define EXPORT_SYMBOL(sym) - * as empty. */ -#define _LINUX_EXPORT_H -#define EXPORT_SYMBOL(sym) +#define __DISABLE_EXPORTS #include "misc.h" #include "error.h" diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index adaa4a964f0c..312bd0b64a61 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -20,7 +20,8 @@ cflags-$(CONFIG_EFI_ARMSTUB) += -I$(srctree)/scripts/dtc/libfdt KBUILD_CFLAGS := $(cflags-y) -DDISABLE_BRANCH_PROFILING \ -D__NO_FORTIFY \ $(call cc-option,-ffreestanding) \ - $(call cc-option,-fno-stack-protector) + $(call cc-option,-fno-stack-protector) \ + -D__DISABLE_EXPORTS GCOV_PROFILE := n KASAN_SANITIZE := n diff --git a/include/linux/export.h b/include/linux/export.h index 1a1dfdb2a5c6..6dba2fb08f77 100644 --- a/include/linux/export.h +++ b/include/linux/export.h @@ -83,6 +83,15 @@ extern struct module __this_module; */ #define __EXPORT_SYMBOL(sym, sec) === __KSYM_##sym === +#elif defined(__DISABLE_EXPORTS) + +/* + * Allow symbol exports to be disabled completely so that C code may + * be reused in other execution contexts such as the UEFI stub or the + * decompressor. + */ +#define __EXPORT_SYMBOL(sym, sec) + #elif defined(CONFIG_TRIM_UNUSED_KSYMS) #include