From patchwork Tue Jun 26 18:27:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 140077 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp5574408lji; Tue, 26 Jun 2018 11:30:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKScWIx3957ZTUn4/n/zEvykloNbqp7hmk8tyM+lpgLoSmMv0cbNFMmbcrejWMQ+/NDd+QL X-Received: by 2002:a65:6455:: with SMTP id s21-v6mr2270577pgv.394.1530037830813; Tue, 26 Jun 2018 11:30:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530037830; cv=none; d=google.com; s=arc-20160816; b=K99GQAc1g5uMfG83MKKltAa4wI6aDwXMIqvBHfqLgaYq1zStFsa/T5xm2DnbXtcl/x +nHuKTDFgBvwbYbLFjJ7J6Qh3T4H48Dv7WN+dDrWYEURdiWoxQg698NlykhFx0MSH+vI /x9syZYgPLj8gpRfsiwJVO77Aqpnd3H2ZTOHQZKY31oYUhuUuLm4aiq/vSwvOrx5uCc3 s0hOpQApnslayKcTymDWAS2bXGwqTVLnNHpIYmnFjnsPJiHkpPsC7llIk5DCDQKf2PBs 96KTW32Yq3Uxn/B1+s/V7dX+Yb+px1LwsPMwXHMU0LFdZ06Be78OIPGr/K2Ih7f/sJS5 sY0A== 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=0rtlaTwu4CCqZ4xjhd2DpZMexFkKmZwXAJxYNg8GKrI=; b=X9fGz/phbald/EJ6HbobWbLAT0kWLUTlwKM/NdXbwdkwWFobhSkCXc5Wck9sXu2S6C a6xJgMZTzh4pgMUL7bdKUu6Dxr2sKmu6qVDIA1iB4KSfxMCruIhUan5/f5dNee5iBZqb GvapjiSnUTPcpdu0jvLbBZmwesTkAQPVm8PCmgp9Z+mQUmUzV5w9avNVQtRja2BahygJ Fq87VRaI+7ZBgYF58+5Wc3Zg1m1edAWicTzgno+dmqkmuAakwyRlGfmQfhot2pSomT7w mci5C1zJ7RvAvr3OWPcRFoFqO583Ig7LLi3qcEljjqt3v5sjTVLzMt6LBnUiFVKcbRy8 rH8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kWQofeSW; 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 l1-v6si1890773pgb.187.2018.06.26.11.30.30; Tue, 26 Jun 2018 11:30:30 -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=@linaro.org header.s=google header.b=kWQofeSW; 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 S1754908AbeFZSa0 (ORCPT + 31 others); Tue, 26 Jun 2018 14:30:26 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:47062 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751121AbeFZS2q (ORCPT ); Tue, 26 Jun 2018 14:28:46 -0400 Received: by mail-wr0-f194.google.com with SMTP id l14-v6so13143197wrq.13 for ; Tue, 26 Jun 2018 11:28:45 -0700 (PDT) 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=0rtlaTwu4CCqZ4xjhd2DpZMexFkKmZwXAJxYNg8GKrI=; b=kWQofeSWgXoFjz/j8asPkjzideKiaqYlr9d9vbu/r2+CWpyREDbBaoDmBUxiu0peFH HPq9AnjbD8tgNgl/vBzBFgNM5iwiBgZc2u4TDt0NhyvsxqwUZQNyAQ7opJ3P/nUOKwvH PTdbLXYvfUfdjZZ95APglwOGZ39x0iuVko2X4= 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=0rtlaTwu4CCqZ4xjhd2DpZMexFkKmZwXAJxYNg8GKrI=; b=PItl72HI+6VlGSrsXcHZbvp/U2BtT9zE3wP5ZRkgf368rq7VvOXap6XVVm8IJrrLSk 8w9SmDw6gOR+FSjhA8CgTF2a1JVO8yaN9j9RZAEIApYXsEFxoz7UvDb/qMARw5TRARzO 4Ff8Ii8Rr+hcW/9SJEk06kLKoj37rjeCb1ZA+5WXtwjykgB+SJB1iCx2goXL5gkR/5GQ kbI+WV0em52SgSW41WnJF5q1rCtUNMu1UXwH2it4t0gg+cARvrv666AcrMxnI/2cypvS ZJWxItKNWieCo5lxEINktgde0ORiYZ5sdQtbtwDxoOhmM7rX88FaQfPBU5/BnAh0BwFd XaEg== X-Gm-Message-State: APt69E1QGin5pzoTMf1jpEvBIvNIuOBII6lEK8d7kBSvqT8WdHFO4HHe q9AaIEpzu8SW6SwIydUHcuKzutw6K9I= X-Received: by 2002:adf:ebc3:: with SMTP id v3-v6mr2414460wrn.33.1530037724454; Tue, 26 Jun 2018 11:28:44 -0700 (PDT) Received: from rev02.home ([2a01:cb1d:112:6f00:d037:e907:f0a2:a5ea]) by smtp.gmail.com with ESMTPSA id s17-v6sm1707664wmc.34.2018.06.26.11.28.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 11:28:43 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Arnd Bergmann , Kees Cook , Will Deacon , Michael Ellerman , Thomas Garnier , Thomas Gleixner , "Serge E. Hallyn" , Bjorn Helgaas , Benjamin Herrenschmidt , Russell King , Paul Mackerras , Catalin Marinas , Petr Mladek , Ingo Molnar , James Morris , Andrew Morton , Nicolas Pitre , Josh Poimboeuf , Steven Rostedt , Sergey Senozhatsky , Linus Torvalds , Jessica Yu , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: [PATCH v9 2/6] module: allow symbol exports to be disabled Date: Tue, 26 Jun 2018 20:27:57 +0200 Message-Id: <20180626182802.19932-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180626182802.19932-1-ard.biesheuvel@linaro.org> References: <20180626182802.19932-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. Acked-by: Nicolas Pitre Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/kaslr.c | 5 +---- drivers/firmware/efi/libstub/Makefile | 3 ++- include/linux/export.h | 11 ++++++++++- 3 files changed, 13 insertions(+), 6 deletions(-) -- 2.11.0 diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c index b87a7582853d..ed7a123bba42 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 a34e9290a699..0d0d3483241c 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 b768d6dd3c90..ea7df303d68d 100644 --- a/include/linux/export.h +++ b/include/linux/export.h @@ -66,7 +66,16 @@ extern struct module __this_module; __attribute__((section("___ksymtab" sec "+" #sym), used)) \ = { (unsigned long)&sym, __kstrtab_##sym } -#if defined(__KSYM_DEPS__) +#if 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(__KSYM_DEPS__) /* * For fine grained build dependencies, we want to tell the build system