Skip to content

Commit 22154e7

Browse files
Christophe Leroy (CS GROUP)maddy-kerneldev
authored andcommitted
powerpc/ptrace: Convert gpr32_set_common_user() to scoped user access
Commit 861574d ("powerpc/uaccess: Implement masked user access") provides optimised user access by avoiding the cost of access_ok(). Convert gpr32_set_common_user() to scoped user access to benefit from masked user access. Scoped user access also make the code simpler. Also changes label from Efault to efault to avoid checkpatch complaining about CamelCase. Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org> Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com> Link: https://patch.msgid.link/2409643daab08b4bc07004c2b88f42085d1ef45a.1773136838.git.chleroy@kernel.org
1 parent f19a2c6 commit 22154e7

1 file changed

Lines changed: 31 additions & 33 deletions

File tree

arch/powerpc/kernel/ptrace/ptrace-view.c

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -758,38 +758,37 @@ static int gpr32_set_common_user(struct task_struct *target,
758758
const void *kbuf = NULL;
759759
compat_ulong_t reg;
760760

761-
if (!user_read_access_begin(u, count))
762-
return -EFAULT;
763-
764-
pos /= sizeof(reg);
765-
count /= sizeof(reg);
766-
767-
for (; count > 0 && pos < PT_MSR; --count) {
768-
unsafe_get_user(reg, u++, Efault);
769-
regs[pos++] = reg;
770-
}
771-
772-
if (count > 0 && pos == PT_MSR) {
773-
unsafe_get_user(reg, u++, Efault);
774-
set_user_msr(target, reg);
775-
++pos;
776-
--count;
777-
}
778-
779-
for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) {
780-
unsafe_get_user(reg, u++, Efault);
781-
regs[pos++] = reg;
782-
}
783-
for (; count > 0 && pos < PT_TRAP; --count, ++pos)
784-
unsafe_get_user(reg, u++, Efault);
785-
786-
if (count > 0 && pos == PT_TRAP) {
787-
unsafe_get_user(reg, u++, Efault);
788-
set_user_trap(target, reg);
789-
++pos;
790-
--count;
761+
scoped_user_read_access_size(ubuf, count, efault) {
762+
u = ubuf;
763+
pos /= sizeof(reg);
764+
count /= sizeof(reg);
765+
766+
for (; count > 0 && pos < PT_MSR; --count) {
767+
unsafe_get_user(reg, u++, efault);
768+
regs[pos++] = reg;
769+
}
770+
771+
if (count > 0 && pos == PT_MSR) {
772+
unsafe_get_user(reg, u++, efault);
773+
set_user_msr(target, reg);
774+
++pos;
775+
--count;
776+
}
777+
778+
for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) {
779+
unsafe_get_user(reg, u++, efault);
780+
regs[pos++] = reg;
781+
}
782+
for (; count > 0 && pos < PT_TRAP; --count, ++pos)
783+
unsafe_get_user(reg, u++, efault);
784+
785+
if (count > 0 && pos == PT_TRAP) {
786+
unsafe_get_user(reg, u++, efault);
787+
set_user_trap(target, reg);
788+
++pos;
789+
--count;
790+
}
791791
}
792-
user_read_access_end();
793792

794793
ubuf = u;
795794
pos *= sizeof(reg);
@@ -798,8 +797,7 @@ static int gpr32_set_common_user(struct task_struct *target,
798797
(PT_TRAP + 1) * sizeof(reg), -1);
799798
return 0;
800799

801-
Efault:
802-
user_read_access_end();
800+
efault:
803801
return -EFAULT;
804802
}
805803

0 commit comments

Comments
 (0)