aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSahara <keun-o.park@darkmatter.ae>2017-02-16 13:29:15 -0500
committerKees Cook <keescook@chromium.org>2017-04-04 17:30:29 -0400
commit96dc4f9fb64690fc34410415fd1fc609cf803f61 (patch)
tree31971ed38668c7492910a70da3b6e1faf5f0509f
parent4495c08e84729385774601b5146d51d9e5849f81 (diff)
usercopy: Move enum for arch_within_stack_frames()
This patch moves the arch_within_stack_frames() return value enum up in the header files so that per-architecture implementations can reuse the same return values. Signed-off-by: Sahara <keun-o.park@darkmatter.ae> Signed-off-by: James Morse <james.morse@arm.com> [kees: adjusted naming and commit log] Signed-off-by: Kees Cook <keescook@chromium.org>
-rw-r--r--arch/x86/include/asm/thread_info.h13
-rw-r--r--include/linux/thread_info.h12
-rw-r--r--mm/usercopy.c8
3 files changed, 20 insertions, 13 deletions
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index ad6f5eb07a95..920ca1f7adea 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -168,9 +168,9 @@ static inline unsigned long current_stack_pointer(void)
168 * entirely contained by a single stack frame. 168 * entirely contained by a single stack frame.
169 * 169 *
170 * Returns: 170 * Returns:
171 * 1 if within a frame 171 * GOOD_FRAME if within a frame
172 * -1 if placed across a frame boundary (or outside stack) 172 * BAD_STACK if placed across a frame boundary (or outside stack)
173 * 0 unable to determine (no frame pointers, etc) 173 * NOT_STACK unable to determine (no frame pointers, etc)
174 */ 174 */
175static inline int arch_within_stack_frames(const void * const stack, 175static inline int arch_within_stack_frames(const void * const stack,
176 const void * const stackend, 176 const void * const stackend,
@@ -197,13 +197,14 @@ static inline int arch_within_stack_frames(const void * const stack,
197 * the copy as invalid. 197 * the copy as invalid.
198 */ 198 */
199 if (obj + len <= frame) 199 if (obj + len <= frame)
200 return obj >= oldframe + 2 * sizeof(void *) ? 1 : -1; 200 return obj >= oldframe + 2 * sizeof(void *) ?
201 GOOD_FRAME : BAD_STACK;
201 oldframe = frame; 202 oldframe = frame;
202 frame = *(const void * const *)frame; 203 frame = *(const void * const *)frame;
203 } 204 }
204 return -1; 205 return BAD_STACK;
205#else 206#else
206 return 0; 207 return NOT_STACK;
207#endif 208#endif
208} 209}
209 210
diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index 58373875e8ee..0dbe41be6181 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -22,6 +22,18 @@
22#endif 22#endif
23 23
24#include <linux/bitops.h> 24#include <linux/bitops.h>
25
26/*
27 * For per-arch arch_within_stack_frames() implementations, defined in
28 * asm/thread_info.h.
29 */
30enum {
31 BAD_STACK = -1,
32 NOT_STACK = 0,
33 GOOD_FRAME,
34 GOOD_STACK,
35};
36
25#include <asm/thread_info.h> 37#include <asm/thread_info.h>
26 38
27#ifdef __KERNEL__ 39#ifdef __KERNEL__
diff --git a/mm/usercopy.c b/mm/usercopy.c
index d155e12563b1..1eba99baf1cf 100644
--- a/mm/usercopy.c
+++ b/mm/usercopy.c
@@ -19,15 +19,9 @@
19#include <linux/sched.h> 19#include <linux/sched.h>
20#include <linux/sched/task.h> 20#include <linux/sched/task.h>
21#include <linux/sched/task_stack.h> 21#include <linux/sched/task_stack.h>
22#include <linux/thread_info.h>
22#include <asm/sections.h> 23#include <asm/sections.h>
23 24
24enum {
25 BAD_STACK = -1,
26 NOT_STACK = 0,
27 GOOD_FRAME,
28 GOOD_STACK,
29};
30
31/* 25/*
32 * Checks if a given pointer and length is contained by the current 26 * Checks if a given pointer and length is contained by the current
33 * stack frame (if possible). 27 * stack frame (if possible).