Skip to content

Commit 5b835d4

Browse files
committed
xtensa: use XCHAL_NUM_AREGS as pt_regs::areg size
struct pt_regs is used to access both kernel and user exception frames. User exception frames may contain up to XCHAL_NUM_AREG registers that task creation and signal delivery code may access, but pt_regs::areg array has only 16 entries that cover only the kernel exception frame. This results in the following build error: arch/xtensa/kernel/process.c: In function 'copy_thread': arch/xtensa/kernel/process.c:262:52: error: array subscript 53 is above array bounds of 'long unsigned int[16]' [-Werror=array-bounds] 262 | put_user(regs->areg[caller_ars+1], Change struct pt_regs::areg size to XCHAL_NUM_AREGS so that it covers the whole user exception frame. Adjust task_pt_regs and drop additional register copying code from copy_thread now that the whole user exception stack frame is copied. Reported-by: Kees Cook <keescook@chromium.org> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com> Reviewed-by: Kees Cook <keescook@chromium.org>
1 parent 6fad9dd commit 5b835d4

2 files changed

Lines changed: 3 additions & 14 deletions

File tree

arch/xtensa/include/asm/ptrace.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#ifndef __ASSEMBLY__
4545

4646
#include <asm/coprocessor.h>
47+
#include <asm/core.h>
4748

4849
/*
4950
* This struct defines the way the registers are stored on the
@@ -77,14 +78,12 @@ struct pt_regs {
7778
/* current register frame.
7879
* Note: The ESF for kernel exceptions ends after 16 registers!
7980
*/
80-
unsigned long areg[16];
81+
unsigned long areg[XCHAL_NUM_AREGS];
8182
};
8283

83-
#include <asm/core.h>
84-
8584
# define arch_has_single_step() (1)
8685
# define task_pt_regs(tsk) ((struct pt_regs*) \
87-
(task_stack_page(tsk) + KERNEL_STACK_SIZE - (XCHAL_NUM_AREGS-16)*4) - 1)
86+
(task_stack_page(tsk) + KERNEL_STACK_SIZE) - 1)
8887
# define user_mode(regs) (((regs)->ps & 0x00000020)!=0)
8988
# define instruction_pointer(regs) ((regs)->pc)
9089
# define return_pointer(regs) (MAKE_PC_FROM_RA((regs)->areg[0], \

arch/xtensa/kernel/process.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,6 @@ int copy_thread(unsigned long clone_flags, unsigned long usp_thread_fn,
232232
p->thread.ra = MAKE_RA_FOR_CALL(
233233
(unsigned long)ret_from_fork, 0x1);
234234

235-
/* This does not copy all the regs.
236-
* In a bout of brilliance or madness,
237-
* ARs beyond a0-a15 exist past the end of the struct.
238-
*/
239235
*childregs = *regs;
240236
childregs->areg[1] = usp;
241237
childregs->areg[2] = 0;
@@ -265,14 +261,8 @@ int copy_thread(unsigned long clone_flags, unsigned long usp_thread_fn,
265261
childregs->wmask = 1;
266262
childregs->windowstart = 1;
267263
childregs->windowbase = 0;
268-
} else {
269-
int len = childregs->wmask & ~0xf;
270-
memcpy(&childregs->areg[XCHAL_NUM_AREGS - len/4],
271-
&regs->areg[XCHAL_NUM_AREGS - len/4], len);
272264
}
273265

274-
childregs->syscall = regs->syscall;
275-
276266
if (clone_flags & CLONE_SETTLS)
277267
childregs->threadptr = tls;
278268
} else {

0 commit comments

Comments
 (0)