From patchwork Wed Jul 4 08:36:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141027 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp543604ljj; Wed, 4 Jul 2018 01:41:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd2j96qr4U6dO+pRB1fVD9LiuiWMNQrjgIDt3TfJ5CENy+Ll89YRBHHMuxbMipRo+K4Wifs X-Received: by 2002:a17:902:e00a:: with SMTP id ca10-v6mr1203497plb.224.1530693702637; Wed, 04 Jul 2018 01:41:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530693702; cv=none; d=google.com; s=arc-20160816; b=DLsj8OGq1qfaRQ3LBuQ2wnTxX8ypUZbh+ISI6Nj1L9pGn7wFL+yxpCXfASvhHfiKjf IHwbrbe7r9gnvi9DUquQIN7LjNtH4OxvAcpsvA4LnfbkSmzmUnRSvhX+9vPxUL5T6XEp CoQMgDmdsw1p0tivrAmxPRVTNn2hdbdKSJu8AgfImOXTWehQ2Nf/pUmEqxuJW2LB8OWk 6TbeKh1uhOYAoE1/N8Gkznv9tVDQ37WfxSV5l+n98vpIED0bAFiwKMu1fZlF76ogjGRp DgeubNN35RsjTz8FECllr5mx/E7doOCcklfgcu/1jCvvCauyq3RIXYRRWcxvuQrxh3nV sLiw== 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=WwDzIwe447IcZCAIGu+8yb3n66DKqmjIylDR9Nx0qlM=; b=MGFkbqYZf0b6IpDt8mCOFLJKh5NuQF3taCnrdN0KS5XZjYshEX0thPNsD8yD40Ao6f C1OWMfOBPGYtM/BUCK29Jp1Y1xiyn5uaLgX3gyEgvYkQsJ+hKJWKkaomuEELaBcaM8Jl w6BKxs+sPG59MGfgg7oS3Boqbcrx8ww35KwBOjwRAZUaBcih0NqGZZVFPEvaq2SDumyM xc80POhVV9swIFB4L0uSJLzbpnLcRoyqna7xCmhJGXo1Ia0TwMQagrn7GB4FL2LvQ101 eWUawxt+aIEX6mHVkL8m2NSTBs5bTxrXCP4ucA77tuu3Vcim4ojA9REuhIqW52kWgCi7 9CRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iETq0ghz; 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 u6-v6si3149899plr.437.2018.07.04.01.41.42; Wed, 04 Jul 2018 01:41:42 -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=iETq0ghz; 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 S934346AbeGDIlU (ORCPT + 31 others); Wed, 4 Jul 2018 04:41:20 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:36936 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933324AbeGDIiv (ORCPT ); Wed, 4 Jul 2018 04:38:51 -0400 Received: by mail-ed1-f67.google.com with SMTP id v22-v6so3464603edq.4 for ; Wed, 04 Jul 2018 01:38:50 -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=WwDzIwe447IcZCAIGu+8yb3n66DKqmjIylDR9Nx0qlM=; b=iETq0ghz2rcIjYDEH/K2UNHIhKkUiwML5a0df6hgI4a7Nx4F7NBPxcz3ngH7Y9oa1L L44DDfe5KlmSEncVAizmGhIjM0rtsKzkUH/13i8+M8NTQdiXYhV+oHUV00DqiUUisZYU aNvd6P4F8rohT+ixA21/ID5MCu88JTnWThcsA= 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=WwDzIwe447IcZCAIGu+8yb3n66DKqmjIylDR9Nx0qlM=; b=rd4Ecg56QfvMBdUsvsTBF+zkfrNExz8AGJRNSuQJ4uJxm6bTdUsu+LnFMs4jTsn1Yc Dp38GHYN6QS7gLKimYW3Y1UqM/wUfRN6L9jqtIPO8c52Qv1HYA94+NHP18FoU4WyR9bp 8Lp5b1NsByzFPZBDT7P4jUW+YBFN/B6hRtyHwSYugwycjKdiR/ROTylX2RJ/N6YSAka/ LlQOfRJ9OBKEAMLYwkIs+dwpIUqiXtdyOUjwRH7THyIsIhH2l3RiNdXxA9suZQT1CH2e /3oBFyEMUXoUf4H+bOUNxK2R/yyC0UGGCikGWMNyqvwkjwS8qMnBE8jG8upCtf6JJ6JW rQNw== X-Gm-Message-State: APt69E2ZiUpsxTENvpgSyT/ZcM35GEA/S1uI+Qr25jppFnR/qo3PCEBC F76R3OnJlqPBlrTekS/ixhpTKtqcNg0= X-Received: by 2002:a50:81a4:: with SMTP id 33-v6mr1701948ede.200.1530693529463; Wed, 04 Jul 2018 01:38:49 -0700 (PDT) Received: from ards-mac-mini.arnhem.chello.nl (dhcp-077-251-017-237.chello.nl. [77.251.17.237]) by smtp.gmail.com with ESMTPSA id k13-v6sm1821740edj.55.2018.07.04.01.38.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jul 2018 01:38:48 -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 v10 2/6] module: allow symbol exports to be disabled Date: Wed, 4 Jul 2018 10:36:47 +0200 Message-Id: <20180704083651.24360-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180704083651.24360-1-ard.biesheuvel@linaro.org> References: <20180704083651.24360-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 Acked-by: Michael Ellerman Reviewed-by: Will Deacon Acked-by: Ingo Molnar 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.17.1 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