From patchwork Sun Mar 11 12:38:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 131348 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp3056218lja; Sun, 11 Mar 2018 05:40:16 -0700 (PDT) X-Google-Smtp-Source: AG47ELt3t4Kl812KUqOavmvAqm8pnZJgeRwUj7VDlg/wxErKv0gLc1EbUbPii2LLDxpkYTbDgqUq X-Received: by 2002:a17:902:6ecd:: with SMTP id l13-v6mr4775336pln.374.1520772015860; Sun, 11 Mar 2018 05:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520772015; cv=none; d=google.com; s=arc-20160816; b=k7yS30deBuYRBuM8A0m+U2aYOHdSC9niKRhm8MIMecszJOO8c2wot+TBFFshjIdNaK nd3PaO55Fb14SaJbUUrFfzQ1AIyYZwZ5pv6M4xbRSAKY98BjZ0VWFZGql9wZZiuoVIre iBLquMjN8oACjw6Wmhplgm6gVxCOQ41BRedxuvR2kaEJ63IBTp5EuoGmB/SgNQuY3LLy yzkayIa5eR7gQdWPAe4x6Fbl0m+A7Dxim2WKpP7uQpqnMKxAgvwFVSsaAJLi5vrHpqwR 5XTxzmZxzd67rZpSAgK41Q+eOIWExe1axnF+6k4lM91jrKERHSH5JVlzH5vm04xU+ql3 Vu0g== 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=J6NwNeKEJnTS9CbN6SiQmSD17aI7GednBlkCHTWkumc=; b=tG0FWhYshKyal3HelrSGJTYVCjdmllKH6CK7DZLGkh24SMLKvAmE9E9MNCcwfFUkWj aAXwtQ1C1wf8nKKOdfrSfZaIcKX9pMLyjQ6dqFK4rvjUyJGkdgRbl6Cnh09YQHOSHYpp SQT3IDN8QnUy4bsGLtulocBSRXjx6s1/0Ev9d+hjx9ZwsPyzRSrAvyicxK+FRk6ilJcO LZQXmTL60AYiNoVSJ7fpIjbHO3BHMD+bM6ykznlt4a94GIx7oqQhjloDKZPj6vwccCre EaRx2U2JNzqVyOqttZdiYZmcfv6kp9heIqUZtL0lJDJpDLXp/MgvvKjdNQ8XfRzUDLAH Qzaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KFxDY1xU; 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 q11si3643507pgv.144.2018.03.11.05.40.15; Sun, 11 Mar 2018 05:40:15 -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=KFxDY1xU; 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 S932361AbeCKMkL (ORCPT + 28 others); Sun, 11 Mar 2018 08:40:11 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:34189 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932180AbeCKMjE (ORCPT ); Sun, 11 Mar 2018 08:39:04 -0400 Received: by mail-wr0-f193.google.com with SMTP id o8so13038974wra.1 for ; Sun, 11 Mar 2018 05:39:02 -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=J6NwNeKEJnTS9CbN6SiQmSD17aI7GednBlkCHTWkumc=; b=KFxDY1xUwCHPfI/HYAwbLhwkm4HxWX4FmjwJot7iIWaF6N/Pen6NsBwEcF7Oh0vU6m UQt3FJgyzqWs6lU/rH6LxqsDQLJh6Ip5x3kSOvIi4DXohBSKxP26ileZsXg0ToAsOS9v YEHAiDbEHMVu8SPuARLuSm/HGsrN/klNmkrFo= 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=J6NwNeKEJnTS9CbN6SiQmSD17aI7GednBlkCHTWkumc=; b=tXLDkVf3cdtWyej1EVlLdAwb5rGH/VnHc8nkxs6emSp/5XCnQHWyLS5A1NSC+wsaKR 85IHOtyxG8c5cx594r8XQDshxDLhN9OTbBVt2r+YAW4Nq2zdjGbd2hjl4VoeHMvFEO4M BjK2w00j8526ku3+Nl5Anu/7+M57xcTSz7Hzr0i7tCYFM0pT+BXxOaX7bO2+noGx0m9b ju+KWS6cEcoYlfn3TIqQ2fkqNAcrqjbdj2qmGvqTzz/8tVrQ/MJajmEPagELT28tUgt6 8MiWmBlVdqR6iVm3hjeJ5I0UUmgdah3VNjCyfLDXOOUHxYlTxd4tyvYr01+jvbs87VNf xpYA== X-Gm-Message-State: AElRT7ERk74rHEyDHxM8xq74PZoxrZmv0UPaT12hMirGTvokF8SEfc/p lmpJ3i9I/vUNmZflkY8XMoR6Pw== X-Received: by 10.223.161.195 with SMTP id v3mr3573692wrv.184.1520771942134; Sun, 11 Mar 2018 05:39:02 -0700 (PDT) Received: from localhost.localdomain ([105.148.128.186]) by smtp.gmail.com with ESMTPSA id h188sm2569103wmf.37.2018.03.11.05.38.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Mar 2018 05:39:01 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.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-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: [PATCH v8 2/6] module: allow symbol exports to be disabled Date: Sun, 11 Mar 2018 12:38:11 +0000 Message-Id: <20180311123815.17916-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180311123815.17916-1-ard.biesheuvel@linaro.org> References: <20180311123815.17916-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. 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.15.1 Acked-by: Nicolas Pitre 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 7b3ba40f0745..896a882c89f4 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..25005b55b079 100644 --- a/include/linux/export.h +++ b/include/linux/export.h @@ -72,7 +72,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