From: Yu-cheng Yu <yu-cheng.yu@intel.com> To: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, "H.J. Lu" <hjl.tools@gmail.com>, Vedvyas Shanbhogue <vedvyas.shanbhogue@intel.com>, "Ravi V. Shankar" <ravi.v.shankar@intel.com>, Dave Hansen <dave.hansen@linux.intel.com>, Andy Lutomirski <luto@amacapital.net>, Jonathan Corbet <corbet@lwn.net>, Oleg Nesterov <oleg@redhat.com>, Arnd Bergmann <arnd@arndb.de>, Mike Kravetz <mike.kravetz@oracle.com> Subject: [PATCH 5/7] x86: Insert endbr32/endbr64 to vDSO Date: Thu, 7 Jun 2018 07:38:53 -0700 [thread overview] Message-ID: <20180607143855.3681-6-yu-cheng.yu@intel.com> (raw) In-Reply-To: <20180607143855.3681-1-yu-cheng.yu@intel.com> From: "H.J. Lu" <hjl.tools@gmail.com> When Intel indirect branch tracking is enabled, functions in vDSO which may be called indirectly should have endbr32 or endbr64 as the first instruction. We try to compile vDSO with -fcf-protection=branch -mibt if possible. Otherwise, we insert endbr32 or endbr64 by hand to assembly codes generated by the compiler. Signed-off-by: H.J. Lu <hjl.tools@gmail.com> --- arch/x86/entry/vdso/.gitignore | 4 ++++ arch/x86/entry/vdso/Makefile | 34 ++++++++++++++++++++++++++++++++++ arch/x86/entry/vdso/endbr.sh | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 arch/x86/entry/vdso/endbr.sh diff --git a/arch/x86/entry/vdso/.gitignore b/arch/x86/entry/vdso/.gitignore index aae8ffdd5880..552941fdfae0 100644 --- a/arch/x86/entry/vdso/.gitignore +++ b/arch/x86/entry/vdso/.gitignore @@ -5,3 +5,7 @@ vdso32-sysenter-syms.lds vdso32-int80-syms.lds vdso-image-*.c vdso2c +vclock_gettime.S +vgetcpu.S +vclock_gettime.asm +vgetcpu.asm diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile index d998a487c9b1..cccafc36a831 100644 --- a/arch/x86/entry/vdso/Makefile +++ b/arch/x86/entry/vdso/Makefile @@ -118,6 +118,40 @@ $(obj)/%-x32.o: $(obj)/%.o FORCE targets += vdsox32.lds $(vobjx32s-y) +ifdef CONFIG_X86_INTEL_BRANCH_TRACKING_USER + ifeq ($(call cc-option-yn, -fcf-protection=branch -mibt), y) + $(obj)/vclock_gettime.o $(obj)/vgetcpu.o $(obj)/vdso32/vclock_gettime.o: KBUILD_CFLAGS += -fcf-protection=branch -mibt + else + endbr := $(srctree)/$(src)/endbr.sh + quiet_cmd_endbr = ENDBR $@ + cmd_endbr = $(CONFIG_SHELL) '$(endbr)' $< $@ + + quiet_cmd_cc_asm_c = CC $(quiet_modtag) $@ + cmd_cc_asm_c = $(CC) $(c_flags) $(DISABLE_LTO) -S -o $@ $< + +$(obj)/%.asm: $(src)/%.c + $(call if_changed_dep,cc_asm_c) + +$(obj)/vclock_gettime.S: $(obj)/vclock_gettime.asm + $(call if_changed,endbr) + +$(obj)/vgetcpu.S: $(obj)/vgetcpu.asm + $(call if_changed,endbr) + +$(obj)/vclock_gettime.o: $(obj)/vclock_gettime.S + $(call if_changed_rule,as_o_S) + +$(obj)/vgetcpu.o: $(obj)/vgetcpu.S + $(call if_changed_rule,as_o_S) + +$(obj)/vdso32/vclock_gettime.S: $(obj)/vdso32/vclock_gettime.asm + $(call if_changed,endbr) + +$(obj)/vdso32/vclock_gettime.o: $(obj)/vdso32/vclock_gettime.S + $(call if_changed_rule,as_o_S) + endif +endif + $(obj)/%.so: OBJCOPYFLAGS := -S $(obj)/%.so: $(obj)/%.so.dbg $(call if_changed,objcopy) diff --git a/arch/x86/entry/vdso/endbr.sh b/arch/x86/entry/vdso/endbr.sh new file mode 100644 index 000000000000..983dbec182f2 --- /dev/null +++ b/arch/x86/entry/vdso/endbr.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +in="$1" +out="$2" + +case "$in" in +*/vdso32/*) + endbr=".byte 0xf3,0x0f,0x1e,0xfb" + ;; +*) + endbr=".byte 0xf3,0x0f,0x1e,0xfa" + ;; +esac + +need_endbr=no +while IFS= read line ; do + case "$line" in + __vdso_clock_gettime:|__vdso_getcpu:|__vdso_gettimeofday:|__vdso_time:) + need_endbr=yes + ;; + " ."*) + ;; + " "*) + if [ "$need_endbr" = "yes" ]; then + need_endbr=no + echo " $endbr" + fi + ;; + esac + echo "$line" +done < "$in" > "$out" -- 2.15.1
WARNING: multiple messages have this Message-ID (diff)
From: Yu-cheng Yu <yu-cheng.yu@intel.com> To: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, "H.J. Lu" <hjl.tools@gmail.com>, Vedvyas Shanbhogue <vedvyas.shanbhogue@intel.com>, "Ravi V. Shankar" <ravi.v.shankar@intel.com>, Dave Hansen <dave.hansen@linux.intel.com>, Andy Lutomirski <luto@amacapital.net>, Jonathan Corbet <corbet@lwn.net>, Oleg Nesterov <oleg@redhat.com>, Arnd Bergmann <arnd@arndb.de>, Mike Kravetz <mike.kravetz@oracle.com> Subject: [PATCH 5/7] x86: Insert endbr32/endbr64 to vDSO Date: Thu, 7 Jun 2018 07:38:53 -0700 [thread overview] Message-ID: <20180607143855.3681-6-yu-cheng.yu@intel.com> (raw) In-Reply-To: <20180607143855.3681-1-yu-cheng.yu@intel.com> From: "H.J. Lu" <hjl.tools@gmail.com> When Intel indirect branch tracking is enabled, functions in vDSO which may be called indirectly should have endbr32 or endbr64 as the first instruction. We try to compile vDSO with -fcf-protection=branch -mibt if possible. Otherwise, we insert endbr32 or endbr64 by hand to assembly codes generated by the compiler. Signed-off-by: H.J. Lu <hjl.tools@gmail.com> --- arch/x86/entry/vdso/.gitignore | 4 ++++ arch/x86/entry/vdso/Makefile | 34 ++++++++++++++++++++++++++++++++++ arch/x86/entry/vdso/endbr.sh | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 arch/x86/entry/vdso/endbr.sh diff --git a/arch/x86/entry/vdso/.gitignore b/arch/x86/entry/vdso/.gitignore index aae8ffdd5880..552941fdfae0 100644 --- a/arch/x86/entry/vdso/.gitignore +++ b/arch/x86/entry/vdso/.gitignore @@ -5,3 +5,7 @@ vdso32-sysenter-syms.lds vdso32-int80-syms.lds vdso-image-*.c vdso2c +vclock_gettime.S +vgetcpu.S +vclock_gettime.asm +vgetcpu.asm diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile index d998a487c9b1..cccafc36a831 100644 --- a/arch/x86/entry/vdso/Makefile +++ b/arch/x86/entry/vdso/Makefile @@ -118,6 +118,40 @@ $(obj)/%-x32.o: $(obj)/%.o FORCE targets += vdsox32.lds $(vobjx32s-y) +ifdef CONFIG_X86_INTEL_BRANCH_TRACKING_USER + ifeq ($(call cc-option-yn, -fcf-protection=branch -mibt), y) + $(obj)/vclock_gettime.o $(obj)/vgetcpu.o $(obj)/vdso32/vclock_gettime.o: KBUILD_CFLAGS += -fcf-protection=branch -mibt + else + endbr := $(srctree)/$(src)/endbr.sh + quiet_cmd_endbr = ENDBR $@ + cmd_endbr = $(CONFIG_SHELL) '$(endbr)' $< $@ + + quiet_cmd_cc_asm_c = CC $(quiet_modtag) $@ + cmd_cc_asm_c = $(CC) $(c_flags) $(DISABLE_LTO) -S -o $@ $< + +$(obj)/%.asm: $(src)/%.c + $(call if_changed_dep,cc_asm_c) + +$(obj)/vclock_gettime.S: $(obj)/vclock_gettime.asm + $(call if_changed,endbr) + +$(obj)/vgetcpu.S: $(obj)/vgetcpu.asm + $(call if_changed,endbr) + +$(obj)/vclock_gettime.o: $(obj)/vclock_gettime.S + $(call if_changed_rule,as_o_S) + +$(obj)/vgetcpu.o: $(obj)/vgetcpu.S + $(call if_changed_rule,as_o_S) + +$(obj)/vdso32/vclock_gettime.S: $(obj)/vdso32/vclock_gettime.asm + $(call if_changed,endbr) + +$(obj)/vdso32/vclock_gettime.o: $(obj)/vdso32/vclock_gettime.S + $(call if_changed_rule,as_o_S) + endif +endif + $(obj)/%.so: OBJCOPYFLAGS := -S $(obj)/%.so: $(obj)/%.so.dbg $(call if_changed,objcopy) diff --git a/arch/x86/entry/vdso/endbr.sh b/arch/x86/entry/vdso/endbr.sh new file mode 100644 index 000000000000..983dbec182f2 --- /dev/null +++ b/arch/x86/entry/vdso/endbr.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +in="$1" +out="$2" + +case "$in" in +*/vdso32/*) + endbr=".byte 0xf3,0x0f,0x1e,0xfb" + ;; +*) + endbr=".byte 0xf3,0x0f,0x1e,0xfa" + ;; +esac + +need_endbr=no +while IFS= read line ; do + case "$line" in + __vdso_clock_gettime:|__vdso_getcpu:|__vdso_gettimeofday:|__vdso_time:) + need_endbr=yes + ;; + " ."*) + ;; + " "*) + if [ "$need_endbr" = "yes" ]; then + need_endbr=no + echo " $endbr" + fi + ;; + esac + echo "$line" +done < "$in" > "$out" -- 2.15.1 -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2018-06-07 15:37 UTC|newest] Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-06-07 14:38 [PATCH 0/7] Control Flow Enforcement - Part (4) Yu-cheng Yu 2018-06-07 14:38 ` Yu-cheng Yu 2018-06-07 14:38 ` [PATCH 1/7] x86/cet: Add Kconfig option for user-mode Indirect Branch Tracking Yu-cheng Yu 2018-06-07 14:38 ` Yu-cheng Yu 2018-06-07 16:43 ` Randy Dunlap 2018-06-07 16:43 ` Randy Dunlap 2018-06-07 14:38 ` [PATCH 2/7] x86/cet: User-mode indirect branch tracking support Yu-cheng Yu 2018-06-07 14:38 ` Yu-cheng Yu 2018-06-07 14:38 ` [PATCH 3/7] mm/mmap: Add IBT bitmap size to address space limit check Yu-cheng Yu 2018-06-07 14:38 ` Yu-cheng Yu 2018-06-07 18:39 ` Andy Lutomirski 2018-06-07 18:39 ` Andy Lutomirski 2018-06-07 14:38 ` [PATCH 4/7] x86/cet: add arcp_prctl functions for indirect branch tracking Yu-cheng Yu 2018-06-07 14:38 ` Yu-cheng Yu 2018-06-07 14:38 ` Yu-cheng Yu [this message] 2018-06-07 14:38 ` [PATCH 5/7] x86: Insert endbr32/endbr64 to vDSO Yu-cheng Yu 2018-06-07 20:50 ` Andy Lutomirski 2018-06-07 20:50 ` Andy Lutomirski 2018-06-07 22:03 ` H.J. Lu 2018-06-07 22:03 ` H.J. Lu 2018-06-07 23:00 ` Andy Lutomirski 2018-06-07 23:00 ` Andy Lutomirski 2018-06-08 0:31 ` H.J. Lu 2018-06-08 0:31 ` H.J. Lu 2018-06-08 0:47 ` Andy Lutomirski 2018-06-08 0:47 ` Andy Lutomirski 2018-06-07 14:38 ` [PATCH 6/7] tools: Add cetcmd Yu-cheng Yu 2018-06-07 14:38 ` Yu-cheng Yu 2018-06-07 14:38 ` [PATCH 7/7] x86/cet: Add PTRACE interface for CET Yu-cheng Yu 2018-06-07 14:38 ` Yu-cheng Yu 2018-06-07 18:32 ` Andy Lutomirski 2018-06-07 18:32 ` Andy Lutomirski
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180607143855.3681-6-yu-cheng.yu@intel.com \ --to=yu-cheng.yu@intel.com \ --cc=arnd@arndb.de \ --cc=corbet@lwn.net \ --cc=dave.hansen@linux.intel.com \ --cc=hjl.tools@gmail.com \ --cc=hpa@zytor.com \ --cc=linux-arch@vger.kernel.org \ --cc=linux-doc@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=luto@amacapital.net \ --cc=mike.kravetz@oracle.com \ --cc=mingo@redhat.com \ --cc=oleg@redhat.com \ --cc=ravi.v.shankar@intel.com \ --cc=tglx@linutronix.de \ --cc=vedvyas.shanbhogue@intel.com \ --cc=x86@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.