From patchwork Tue May 29 22:15:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 10437313 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 73F3C601C7 for ; Tue, 29 May 2018 22:21:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DBBA2891B for ; Tue, 29 May 2018 22:21:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 523A82893E; Tue, 29 May 2018 22:21:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 6E21528927 for ; Tue, 29 May 2018 22:21:22 +0000 (UTC) Received: (qmail 19553 invoked by uid 550); 29 May 2018 22:17:50 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 18409 invoked from network); 29 May 2018 22:17:45 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yfTDJZxpJxR2JVnv3MbjHwHdF17M0sGQ+fibxcMPKhg=; b=Rq888b6Gif+eS/MccgErmMZxtEoE9bnu2Pu/R+XgNsaAR2O1/OObCTnJ8wyNy5UtKw fSAR8WCzpyq3ut0dpQ0VRi230W/eKxrlABs6rjeQzzkuAu4W/nD9asrubxJdO4RzscSU qoiLBA/lDyHHZI5o4NdUUOmNenjHqk2NJH3FSvl05CTPElnzhaJDgVY4VmfmlGDE9hOZ ymmbWWlHbLe51xpgSi7jyP6wdUZbK30pM7vTE24pAsH6oiVeByZO5I76fMO+4babKBI3 NXhqAhcAcDhDOGIQ/ZBDp/kFvCXJe5A8vUhVIpEcq+S7wS0UZXhZ1mFEienFXaICtape YW5Q== 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=yfTDJZxpJxR2JVnv3MbjHwHdF17M0sGQ+fibxcMPKhg=; b=Bk79FuYsHQEu/+aGZ7mO9WrJFQLdTbV3caVcMGxZPQQDpGT6tEhXQDw3GQDhXBI4Pp ByyE++zmqE/9wcrqm9SDeFugUbis19ogHzUCS7m873jS51IXz6ovbsxC6Fma+Sqsff4j tH74hs38XLK+J2Wm54AyrT2B1WkDkiGJK3s5MI9sNCmRRjJAI5eCvt3GlIAF5WE/FAt3 oMo1aySnQQnPGTlYBs9Xks6UgN2RNGoMJg3uudbvzxEVT7YAAF8PLp1HraE/g4OnKRpv 6k0ASWsk/YEGHV3GlXNqgR5h3sB+6oPLMokTYDubpUOSzNe6MYL9SAGWMc7CV+mN34lE FTVQ== X-Gm-Message-State: ALKqPwdyhguxa+28PRrqoa3AW1Ll9Np7SjGjIQyu3g3xP8kOnKhTcRAy TUyYWfOTot94vSj9sXkNzfgKlwpoDPA= X-Google-Smtp-Source: ADUXVKKYakg15UFfbF51T32OjedNJerp7wCWu5o0lBiwH3EUhpRZ0iTNiyiRhol04jI1yP9CW2lo1g== X-Received: by 2002:a62:568f:: with SMTP id h15-v6mr197778pfj.131.1527632253476; Tue, 29 May 2018 15:17:33 -0700 (PDT) From: Thomas Garnier To: kernel-hardening@lists.openwall.com Cc: Thomas Garnier , Skip Frederic Weisbecker , Skip Mathieu Desnoyers , Skip Kees Cook , Skip Michael Forney , Skip Greg Kroah-Hartman , Ingo Molnar , "Paul E. McKenney" , Thomas Gleixner , Nicolas Pitre , Andrew Morton , Randy Dunlap , Nicholas Piggin , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v4 16/27] compiler: Option to add PROVIDE_HIDDEN replacement for weak symbols Date: Tue, 29 May 2018 15:15:17 -0700 Message-Id: <20180529221625.33541-17-thgarnie@google.com> X-Mailer: git-send-email 2.17.0.921.gf22659ad46-goog In-Reply-To: <20180529221625.33541-1-thgarnie@google.com> References: <20180529221625.33541-1-thgarnie@google.com> X-Virus-Scanned: ClamAV using ClamSMTP Provide an option to have a PROVIDE_HIDDEN (linker script) entry for each weak symbol. This option solves an error in x86_64 where the linker optimizes PIE generated code to be non-PIE because --emit-relocs was used instead of -pie (to reduce dynamic relocations). Signed-off-by: Thomas Garnier --- init/Kconfig | 7 +++++++ scripts/link-vmlinux.sh | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index f16247675f84..20e2bf2ae4b4 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1954,6 +1954,13 @@ config ASN1 inform it as to what tags are to be expected in a stream and what functions to call on what tags. +config WEAK_PROVIDE_HIDDEN + bool + help + Generate linker script PROVIDE_HIDDEN entries for all weak symbols. It + allows to prevent non-PIE code being replaced by the linker if the + emit-relocs option is used instead of PIE (useful for x86_64 PIE). + source "kernel/Kconfig.locks" config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 4bf811c09f59..f5d31119b9d7 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -142,6 +142,17 @@ kallsyms() ${CC} ${aflags} -c -o ${2} ${afile} } +gen_weak_provide_hidden() +{ + if [ -n "${CONFIG_WEAK_PROVIDE_HIDDEN}" ]; then + local pattern="s/^\s\+ w \(\w\+\)$/PROVIDE_HIDDEN(\1 = .);/gp" + echo -e "SECTIONS {\n. = _end;" > .tmp_vmlinux_hiddenld + ${NM} ${1} | sed -n "${pattern}" >> .tmp_vmlinux_hiddenld + echo "}" >> .tmp_vmlinux_hiddenld + LDFLAGS_vmlinux="${LDFLAGS_vmlinux} -T .tmp_vmlinux_hiddenld" + fi +} + # Create map file with all symbols from ${1} # See mksymap for additional details mksysmap() @@ -226,6 +237,9 @@ modpost_link vmlinux.o # modpost vmlinux.o to check for section mismatches ${MAKE} -f "${srctree}/scripts/Makefile.modpost" vmlinux.o +# Generate weak linker script +gen_weak_provide_hidden vmlinux.o + kallsymso="" kallsyms_vmlinux="" if [ -n "${CONFIG_KALLSYMS}" ]; then