Skip to content

Commit d547175

Browse files
author
Al Viro
committed
arm64: sanitize compat_ptrace_write_user()
don't bother with copy_regset_from_user() (not to mention set_fs()) Signed-off-by: Al Viro <[email protected]>
1 parent b44f384 commit d547175

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

arch/arm64/kernel/ptrace.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,23 +1553,34 @@ static int compat_ptrace_read_user(struct task_struct *tsk, compat_ulong_t off,
15531553
static int compat_ptrace_write_user(struct task_struct *tsk, compat_ulong_t off,
15541554
compat_ulong_t val)
15551555
{
1556-
int ret;
1557-
mm_segment_t old_fs = get_fs();
1556+
struct pt_regs newregs = *task_pt_regs(tsk);
1557+
unsigned int idx = off / 4;
15581558

15591559
if (off & 3 || off >= COMPAT_USER_SZ)
15601560
return -EIO;
15611561

15621562
if (off >= sizeof(compat_elf_gregset_t))
15631563
return 0;
15641564

1565-
set_fs(KERNEL_DS);
1566-
ret = copy_regset_from_user(tsk, &user_aarch32_view,
1567-
REGSET_COMPAT_GPR, off,
1568-
sizeof(compat_ulong_t),
1569-
&val);
1570-
set_fs(old_fs);
1565+
switch (idx) {
1566+
case 15:
1567+
newregs.pc = val;
1568+
break;
1569+
case 16:
1570+
newregs.pstate = compat_psr_to_pstate(val);
1571+
break;
1572+
case 17:
1573+
newregs.orig_x0 = val;
1574+
break;
1575+
default:
1576+
newregs.regs[idx] = val;
1577+
}
1578+
1579+
if (!valid_user_regs(&newregs.user_regs, tsk))
1580+
return -EINVAL;
15711581

1572-
return ret;
1582+
*task_pt_regs(tsk) = newregs;
1583+
return 0;
15731584
}
15741585

15751586
#ifdef CONFIG_HAVE_HW_BREAKPOINT

0 commit comments

Comments
 (0)