Re: [PATCH V2] MIPS: Add get_thread_area syscall

From: Arnd Bergmann
Date: Fri Dec 13 2019 - 04:12:50 EST


On Fri, Dec 13, 2019 at 9:30 AM Guoyun Sun <sunguoyun@xxxxxxxxxxx> wrote:

Thanks for fixing the numbers. On second look, I saw another problem:

> diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c
> index c333e57..20bf4c5 100644
> --- a/arch/mips/kernel/syscall.c
> +++ b/arch/mips/kernel/syscall.c
> @@ -94,6 +94,16 @@ SYSCALL_DEFINE1(set_thread_area, unsigned long, addr)
> return 0;
> }
>
> +SYSCALL_DEFINE1(get_thread_area, unsigned long __user *, u_info)
> +{
> + struct thread_info *ti = task_thread_info(current);
> +
> + if (copy_to_user(u_info, &(ti->tp_value), sizeof(ti->tp_value)))
> + return -EFAULT;
> +
> + return 0;
> +}
> +

This won't work for compat mode, when tp_value is a different size
in kernel and user space. You could either add a COMPAT_SYSCALL_DEFINE1()
variant, or handle it like

if (in_compat_syscall())
return put_user(ti->tp_value, (__u32 *)u_info);
return put_user(ti->tp_value, u_info);


Arnd