Skip to content

Commit

Permalink
h8300/ptrace: Fix incorrect register transfer count
Browse files Browse the repository at this point in the history
regs_set() and regs_get() are vulnerable to an off-by-1 buffer overrun
if CONFIG_CPU_H8S is set, since this adds an extra entry to
register_offset[] but not to user_regs_struct.

So, iterate over user_regs_struct based on its actual size, not based on
the length of register_offset[].

Signed-off-by: Dave Martin <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Dave Martin authored and torvalds committed Mar 29, 2017
1 parent fb411b8 commit 502585c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions arch/h8300/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ static int regs_get(struct task_struct *target,
long *reg = (long *)&regs;

/* build user regs in buffer */
for (r = 0; r < ARRAY_SIZE(register_offset); r++)
BUILD_BUG_ON(sizeof(regs) % sizeof(long) != 0);
for (r = 0; r < sizeof(regs) / sizeof(long); r++)
*reg++ = h8300_get_reg(target, r);

return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
Expand All @@ -113,7 +114,8 @@ static int regs_set(struct task_struct *target,
long *reg;

/* build user regs in buffer */
for (reg = (long *)&regs, r = 0; r < ARRAY_SIZE(register_offset); r++)
BUILD_BUG_ON(sizeof(regs) % sizeof(long) != 0);
for (reg = (long *)&regs, r = 0; r < sizeof(regs) / sizeof(long); r++)
*reg++ = h8300_get_reg(target, r);

ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
Expand All @@ -122,7 +124,7 @@ static int regs_set(struct task_struct *target,
return ret;

/* write back to pt_regs */
for (reg = (long *)&regs, r = 0; r < ARRAY_SIZE(register_offset); r++)
for (reg = (long *)&regs, r = 0; r < sizeof(regs) / sizeof(long); r++)
h8300_put_reg(target, r, *reg++);
return 0;
}
Expand Down

0 comments on commit 502585c

Please sign in to comment.