MIPS: VDSO: Prevent use of smp_processor_id()

This change “MIPS: VDSO: Prevent use of smp_processor_id()” in Linux kernel is authored by Paul Burton <paul.burton [at] mips.com> on Tue Dec 12 09:57:47 2017 +0000.

MIPS: VDSO: Prevent use of smp_processor_id()

VDSO code should not be using smp_processor_id(), since it is executed
in user mode.
Introduce a VDSO-specific path which will cause a compile-time
or link-time error (depending upon support for __compiletime_error) if
the VDSO ever incorrectly attempts to use smp_processor_id().

[Matt Redfearn <matt.redfearn@imgtec.com>: Move before change to
smp_processor_id in series]

Signed-off-by: Paul Burton <paul.burton@mips.com>
Signed-off-by: Matt Redfearn <matt.redfearn@mips.com>
Patchwork: https://patchwork.linux-mips.org/patch/17932/
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: James Hogan <jhogan@kernel.org>
Cc: linux-mips@linux-mips.org

This Linux change may have been applied to various maintained Linux releases and you can find Linux releases including commit 351fddd.

There are 15 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 arch/mips/include/asm/smp.h | 12 +++++++++++-
 arch/mips/vdso/Makefile     |  3 ++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/arch/mips/include/asm/smp.h b/arch/mips/include/asm/smp.h
index 88ebd83..056a6bf 100644
--- a/arch/mips/include/asm/smp.h
+++ b/arch/mips/include/asm/smp.h
@@ -25,7 +25,17 @@
 extern cpumask_t cpu_core_map[];
 extern cpumask_t cpu_foreign_map[];
 
-#define raw_smp_processor_id() (current_thread_info()->cpu)
+static inline int raw_smp_processor_id(void)
+{
+#if defined(__VDSO__)
+	extern int vdso_smp_processor_id(void)
+		__compiletime_error("VDSO should not call smp_processor_id()");
+	return vdso_smp_processor_id();
+#else
+	return current_thread_info()->cpu;
+#endif
+}
+#define raw_smp_processor_id raw_smp_processor_id
 
 /* Map from cpu id to sequential logical cpu number.  This will only
    not be idempotent when cpus failed to come on-line.	*/
diff --git a/arch/mips/vdso/Makefile b/arch/mips/vdso/Makefile
index ce196046..477c463 100644
--- a/arch/mips/vdso/Makefile
+++ b/arch/mips/vdso/Makefile
@@ -7,7 +7,8 @@ ccflags-vdso := 
 	$(filter -I%,$(KBUILD_CFLAGS)) 
 	$(filter -E%,$(KBUILD_CFLAGS)) 
 	$(filter -mmicromips,$(KBUILD_CFLAGS)) 
-	$(filter -march=%,$(KBUILD_CFLAGS))
+	$(filter -march=%,$(KBUILD_CFLAGS)) 
+	-D__VDSO__
 cflags-vdso := $(ccflags-vdso) 
 	$(filter -W%,$(filter-out -Wa$(comma)%,$(KBUILD_CFLAGS))) 
 	-O2 -g -fPIC -fno-strict-aliasing -fno-common -fno-builtin -G 0 

The commit for this change in Linux stable tree is 351fddd (patch).

Leave a Reply

Your email address will not be published. Required fields are marked *