From patchwork Mon Jun 25 22:39:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 10488283 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 04513601A0 for ; Tue, 26 Jun 2018 08:43:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E482C287E1 for ; Tue, 26 Jun 2018 08:43:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D898E287E5; Tue, 26 Jun 2018 08:43:05 +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 0B516287E1 for ; Tue, 26 Jun 2018 08:43:04 +0000 (UTC) Received: (qmail 26425 invoked by uid 550); 26 Jun 2018 08:39:37 -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 Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 11801 invoked from network); 25 Jun 2018 22:42:10 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:in-reply-to:message-id:references:subject:from:to :cc; bh=JDe7omNGF3EhS1Wwn935GAPXMwY/I1wPiV41ZNKc+ik=; b=URfh8ucVQbWWC7LKzOUu783w72U62KYdfnmIDP3rKVYheqbAW+MgjqjLl7ZE/91lfy erUDfSfrmUrd9lcxra8yzLeBiwBRwlcuK34i5c7GBe5iMz72JRmTBTXUhyGdD/Qsty+b Kcwx1WR6o+NprV28iDuUBv4KDBl9nBBo24SrV6J5hm+Urm99RWyuKw+XDK6SLsqhUO90 beOXEo9kO1yuls6OSOfiIw58ANYQVmM7mPmzCbqrJC7rfrkqhWISSpcJTJOhyoIsJL62 cBwfNQZkaw2HcluQLM6Zoadyu7jjDB9VKZ3eslI+TssWcFJ9VLxcmQqEKQIr+r9vxyYX pb0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:in-reply-to:message-id :references:subject:from:to:cc; bh=JDe7omNGF3EhS1Wwn935GAPXMwY/I1wPiV41ZNKc+ik=; b=EqHDKS42/Qw6Eter+LauIoV6aUmqpccBloKOyBDSYubrKD5KryG6CuE1DUB+6YoyHb FQiWBFLXkiO1Qb6hlXgVbnM4P7+XY1hqpuW48m3cJFe0OJJXbj+B9lcTWO84fy2brS4M q5LNEgNnlXsPsL7noHBGIakV5CetoRWkw7yq01lyrTlUL2UxzGjOBPTb9mWN4do0Q9id MimNgfUjP4kKHv/OWpCX57ISwKSCz+1+zeESO3UHehXORqlCFr725Keh+8lfznjgGRTQ 0b0k/VdLQP2Sk4ra25rAuVrLRnLzshE8GMoSzrYS0zwt3EGyUdCmU/jDDLJ2sLFzgzhu D8Bw== X-Gm-Message-State: APt69E0Z9KjLn2nPSgU0ouZQTFCHT9n1IrRqx2vdX1JnUUH4DcAitGVo HB6FGOOKMP7nes5YPiMDD1gJ4ZZBdh5Hg4zS9nyY/lf8ORgv7i79+Lps+8a5su9+Wf76+IoHFYG oGBuaZAhBl4YtiM7DvLoCzWYLWyfMxoqUDfkj4qWpXfy0x90hYxzYOjYvPktbdwFIKF5GYB7Lt2 TuAXw/NIDS X-Google-Smtp-Source: AAOMgpcafAqwUr9zdDE+lnCGR+mD+hrmqfpzgn75GOsICJZdayq/2nQbMCl1jhMrQE6+JPqebA/0ZQqn/tn89Q== MIME-Version: 1.0 X-Received: by 2002:a24:5f84:: with SMTP id r126-v6mr1155993itb.42.1529966518814; Mon, 25 Jun 2018 15:41:58 -0700 (PDT) Date: Mon, 25 Jun 2018 15:39:04 -0700 In-Reply-To: <20180625224014.134829-1-thgarnie@google.com> Message-Id: <20180625224014.134829-17-thgarnie@google.com> References: <20180625224014.134829-1-thgarnie@google.com> X-Mailer: git-send-email 2.18.0.rc2.346.g013aa6912e-goog Subject: [PATCH v5 16/27] compiler: Option to add PROVIDE_HIDDEN replacement for weak symbols From: Thomas Garnier To: kernel-hardening@lists.openwall.com Cc: Thomas Garnier , Ingo Molnar , Masahiro Yamada , Thomas Gleixner , Kees Cook , "Peter Zijlstra (Intel)" , Mathieu Desnoyers , Randy Dunlap , Nicholas Piggin , linux-kernel@vger.kernel.org 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 d4f90cc38ede..2d7431a8b108 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1974,6 +1974,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