Module: xenomai-jki
Branch: maintenance-2.6
Commit: 2eceef4c62bc8d6b3713787c26882fdcd9b87842
URL:    
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=2eceef4c62bc8d6b3713787c26882fdcd9b87842

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Fri Dec 18 13:09:33 2015 +0100

x86: Fix rthal_strncpy_from_user for SMAP-enabled systems

If SMAP is on, we need to explicitly allow kernel access to userspace
memory via stac() and disallow it again once done (clac()). This fixes
oopses on recent Intel CPUs.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 include/asm-x86/wrappers.h    |   29 +++++++++++++++++++++++++++++
 include/asm-x86/wrappers_32.h |    1 -
 include/asm-x86/wrappers_64.h |    1 -
 ksrc/arch/x86/usercopy_32.c   |    3 +++
 ksrc/arch/x86/usercopy_64.c   |    3 +++
 5 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/include/asm-x86/wrappers.h b/include/asm-x86/wrappers.h
index 7046477..4c12fa7 100644
--- a/include/asm-x86/wrappers.h
+++ b/include/asm-x86/wrappers.h
@@ -1,5 +1,34 @@
+/*
+ * Copyright (C) 2007 Philippe Gerum <r...@xenomai.org>.
+ *
+ * Xenomai is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * Xenomai is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xenomai; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef _XENO_ASM_X86_WRAPPERS_H
+#define _XENO_ASM_X86_WRAPPERS_H
+
 #ifdef __i386__
 #include "wrappers_32.h"
 #else
 #include "wrappers_64.h"
 #endif
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0)
+static inline void clac(void) { }
+static inline void stac(void) { }
+#endif
+
+#endif /* _XENO_ASM_X86_WRAPPERS_H */
diff --git a/include/asm-x86/wrappers_32.h b/include/asm-x86/wrappers_32.h
index 2e6b21e..26014e0 100644
--- a/include/asm-x86/wrappers_32.h
+++ b/include/asm-x86/wrappers_32.h
@@ -19,7 +19,6 @@
 
 #ifndef _XENO_ASM_X86_WRAPPERS_32_H
 #define _XENO_ASM_X86_WRAPPERS_32_H
-#define _XENO_ASM_X86_WRAPPERS_H
 
 #ifndef __KERNEL__
 #error "Pure kernel header included from user-space!"
diff --git a/include/asm-x86/wrappers_64.h b/include/asm-x86/wrappers_64.h
index 3c190f1..24e3fd4 100644
--- a/include/asm-x86/wrappers_64.h
+++ b/include/asm-x86/wrappers_64.h
@@ -19,7 +19,6 @@
 
 #ifndef _XENO_ASM_X86_WRAPPERS_64_H
 #define _XENO_ASM_X86_WRAPPERS_64_H
-#define _XENO_ASM_X86_WRAPPERS_H
 
 #ifndef __KERNEL__
 #error "Pure kernel header included from user-space!"
diff --git a/ksrc/arch/x86/usercopy_32.c b/ksrc/arch/x86/usercopy_32.c
index 6890518..1594491 100644
--- a/ksrc/arch/x86/usercopy_32.c
+++ b/ksrc/arch/x86/usercopy_32.c
@@ -47,7 +47,10 @@ do {                                                         
           \
 long rthal_strncpy_from_user(char *dst, const char __user * src, long count)
 {
        long res;
+
+       stac();
        __do_strncpy_from_user(dst, src, count, res);
+       clac();
        return res;
 }
 
diff --git a/ksrc/arch/x86/usercopy_64.c b/ksrc/arch/x86/usercopy_64.c
index b17c0b4..b84a311 100644
--- a/ksrc/arch/x86/usercopy_64.c
+++ b/ksrc/arch/x86/usercopy_64.c
@@ -48,7 +48,10 @@ do {                                                         
           \
 long rthal_strncpy_from_user(char *dst, const char __user * src, long count)
 {
        long res;
+
+       stac();
        __do_strncpy_from_user(dst, src, count, res);
+       clac();
        return res;
 }
 


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to