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: 854731 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=sparclinux-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="JvakjjXX"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zB4p058Ffz9t3l for ; Wed, 3 Jan 2018 07:06:32 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751061AbeABUGa (ORCPT ); Tue, 2 Jan 2018 15:06:30 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:42304 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751023AbeABUGZ (ORCPT ); Tue, 2 Jan 2018 15:06:25 -0500 Received: by mail-wm0-f67.google.com with SMTP id b141so16415771wme.1 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=rBnl/btP7XMA2zvA5C3F4bpgoC4TG0OanekssNAXL3SleWb8neUnEed3wQV+ztb7/o oeDrejnR4/jfgjumwB/TfAtvRtSrQhleFGOiVwbiL8TrVSDbJ+F0qRyrxPM9jUzbetZk LrNeBWzDTwQflmAeyMMtIBlwLemv9NxvUcJf1prpnhAs76ctzFJQ+4Pt9euZuyg6oarP TY/ZP8teUKQPifFbmBon9NtW6fYr94DGZOIrfGLg/7cmYhVTlAcdymXcxAWfO+vEWZ2E 7T4NTM668jpim299IKahkatwaFhHs7yhhy53mNWREjrhta02UNNtdi9BguTpONhVmQPv J9NQ== X-Gm-Message-State: AKGB3mIJtx85cZ7COpx9ZmZclhEwv2OgIeVuuTD/0IFyl1fkRcW0MXA0 WbR88t0AHR88UdRiX8aNZAr0/A== X-Google-Smtp-Source: ACJfBosJ1YaW1H55WuPG4HZVNPR5sIYnqVBwvoCMpxmVYCKJYkCCK0WTpzNAV4SV0UZHkdO9ReayGQ== 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: sparclinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: sparclinux@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(-) 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