Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/unwind_user_types.h | 1 +
kernel/unwind/user.c | 24 ++++++++++++++++++++----
2 files changed, 21 insertions(+), 4 deletions(-)
--- a/include/linux/unwind_user_types.h
+++ b/include/linux/unwind_user_types.h
@@ -36,6 +36,7 @@ struct unwind_user_state {
unsigned long ip;
unsigned long sp;
unsigned long fp;
+ unsigned int ws;
enum unwind_user_type current_type;
unsigned int available_types;
bool done;
--- a/kernel/unwind/user.c
+++ b/kernel/unwind/user.c
@@ -15,6 +15,21 @@ static const struct unwind_user_frame fp
#define for_each_user_frame(state) \
for (unwind_user_start(state); !(state)->done; unwind_user_next(state))
+static inline int
+get_user_word(unsigned long *word, unsigned long base, int off, int size)
+{
+ unsigned long __user *addr = (void __user *)base + (off * size);
+#ifdef CONFIG_COMPAT
+ if (size == sizeof(int)) {
+ unsigned int data;
+ int ret = get_user(data, (unsigned int __user *)addr);
+ *word = data;
+ return ret;
+ }
+#endif
+ return get_user(*word, addr);
+}
+
static int unwind_user_next_fp(struct unwind_user_state *state)
{
const struct unwind_user_frame *frame = &fp_frame;
@@ -29,21 +44,21 @@ static int unwind_user_next_fp(struct un
}
/* Get the Canonical Frame Address (CFA) */
- cfa += frame->cfa_off;
+ cfa += state->ws * frame->cfa_off;
/* stack going in wrong direction? */
if (cfa <= state->sp)
return -EINVAL;
/* Make sure that the address is word aligned */
- if (cfa & (sizeof(long) - 1))
+ if (cfa & (state->ws - 1))
return -EINVAL;
/* Find the Return Address (RA) */
- if (get_user(ra, (unsigned long *)(cfa + frame->ra_off)))
+ if (get_user_word(&ra, cfa, frame->ra_off, state->ws))
return -EINVAL;
- if (frame->fp_off && get_user(fp, (unsigned long __user *)(cfa + frame->fp_off)))
+ if (frame->fp_off && get_user_word(&fp, cfa, frame->fp_off, state->ws))
return -EINVAL;
state->ip = ra;
@@ -100,6 +115,7 @@ static int unwind_user_start(struct unwi
state->ip = instruction_pointer(regs);
state->sp = user_stack_pointer(regs);
state->fp = frame_pointer(regs);
+ state->ws = compat_user_mode(regs) ? sizeof(int) : sizeof(long);
return 0;
}