Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Thu,  2 Feb 2017 16:50:22 +0400
From: kpark3469@...il.com
To: kernel-hardening@...ts.openwall.com
Cc: catalin.marinas@....com,
	keescook@...omium.org,
	will.deacon@....com,
	mark.rutland@....com,
	james.morse@....com,
	panand@...hat.com,
	keun-o.park@...kmatter.ae
Subject: [PATCH v2 1/3] usercopy: create usercopy.h and move enum stack_type

From: Sahara <keun-o.park@...kmatter.ae>

This patch creates linux/usercopy.h and moves the enum which is
only used in usercopy.c so as to make it usable to x86 and other
architecture's thread_info.h, which may have arch_within_stack_frames().

Signed-off-by: Sahara <keun-o.park@...kmatter.ae>
Suggested-by: James Morse <james.morse@....com>
---
 arch/x86/include/asm/thread_info.h | 20 +++++++++++---------
 include/linux/usercopy.h           | 11 +++++++++++
 mm/usercopy.c                      |  8 +-------
 3 files changed, 23 insertions(+), 16 deletions(-)
 create mode 100644 include/linux/usercopy.h

diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index ad6f5eb0..c991126 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -51,6 +51,7 @@
 struct task_struct;
 #include <asm/cpufeature.h>
 #include <linux/atomic.h>
+#include <linux/usercopy.h>
 
 struct thread_info {
 	unsigned long		flags;		/* low level flags */
@@ -168,13 +169,13 @@ static inline unsigned long current_stack_pointer(void)
  * entirely contained by a single stack frame.
  *
  * Returns:
- *		 1 if within a frame
- *		-1 if placed across a frame boundary (or outside stack)
- *		 0 unable to determine (no frame pointers, etc)
+ *	GOOD_FRAME	if within a frame
+ *	BAD_STACK	if placed across a frame boundary (or outside stack)
+ *	NOT_STACK	unable to determine (no frame pointers, etc)
  */
-static inline int arch_within_stack_frames(const void * const stack,
-					   const void * const stackend,
-					   const void *obj, unsigned long len)
+static inline enum stack_type arch_within_stack_frames(const void * const stack,
+					const void * const stackend,
+					const void *obj, unsigned long len)
 {
 #if defined(CONFIG_FRAME_POINTER)
 	const void *frame = NULL;
@@ -197,13 +198,14 @@ static inline int arch_within_stack_frames(const void * const stack,
 		 * the copy as invalid.
 		 */
 		if (obj + len <= frame)
-			return obj >= oldframe + 2 * sizeof(void *) ? 1 : -1;
+			return obj >= oldframe + 2 * sizeof(void *) ?
+				GOOD_FRAME : BAD_STACK;
 		oldframe = frame;
 		frame = *(const void * const *)frame;
 	}
-	return -1;
+	return BAD_STACK;
 #else
-	return 0;
+	return NOT_STACK;
 #endif
 }
 
diff --git a/include/linux/usercopy.h b/include/linux/usercopy.h
new file mode 100644
index 0000000..974859e
--- /dev/null
+++ b/include/linux/usercopy.h
@@ -0,0 +1,11 @@
+#ifndef __LINUX_USERCOPY_H
+#define __LINUX_USERCOPY_H
+
+enum stack_type {
+	BAD_STACK = -1,
+	NOT_STACK = 0,
+	GOOD_FRAME,
+	GOOD_STACK,
+};
+
+#endif
diff --git a/mm/usercopy.c b/mm/usercopy.c
index 3c8da0a..ee7bced 100644
--- a/mm/usercopy.c
+++ b/mm/usercopy.c
@@ -16,15 +16,9 @@
 
 #include <linux/mm.h>
 #include <linux/slab.h>
+#include <linux/usercopy.h>
 #include <asm/sections.h>
 
-enum {
-	BAD_STACK = -1,
-	NOT_STACK = 0,
-	GOOD_FRAME,
-	GOOD_STACK,
-};
-
 /*
  * Checks if a given pointer and length is contained by the current
  * stack frame (if possible).
-- 
2.7.4

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.