lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aa84cddb-9c04-3bad-49de-2fb3056ec44a@codethink.co.uk>
Date:   Tue, 2 Mar 2021 10:01:18 +0000
From:   Ben Dooks <ben.dooks@...ethink.co.uk>
To:     Tiezhu Yang <yangtiezhu@...ngson.cn>,
        Paul Walmsley <paul.walmsley@...ive.com>,
        Palmer Dabbelt <palmer@...belt.com>,
        Albert Ou <aou@...s.berkeley.edu>
Cc:     linux-riscv@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] riscv: Return -EFAULT if copy_to_user() failed in
 signal.c

On 02/03/2021 07:28, Tiezhu Yang wrote:
> copy_to_user() returns the amount left to copy, it should return -EFAULT
> if copy to user failed.

This looks technically correct, but the caller (only one)
will check for non-zero and will covert that to -EFAULT
in setup_rt_frame().

I expect if this change is done, it also needs to be done
for the callers too and there's a few others than assume
!=0 is an error.

I think it would be easier to define save_fp_state() to
return non-zero on error and note it does not return an
error code. It may be worth exiting the functio nif
the first __copy_to_user fails?

Note: setup_rt_frame -> setup_sigcontext -> save_fp_frame

> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@...ngson.cn>
> ---
>   arch/riscv/kernel/signal.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
> index 65942b3..2238fc5 100644
> --- a/arch/riscv/kernel/signal.c
> +++ b/arch/riscv/kernel/signal.c
> @@ -67,7 +67,7 @@ static long save_fp_state(struct pt_regs *regs,
>   	fstate_save(current, regs);
>   	err = __copy_to_user(state, &current->thread.fstate, sizeof(*state));
>   	if (unlikely(err))
> -		return err;
> +		return -EFAULT;
>   
>   	/* We support no other extension state at this time. */
>   	for (i = 0; i < ARRAY_SIZE(sc_fpregs->q.reserved); i++) {
> @@ -140,8 +140,12 @@ static long setup_sigcontext(struct rt_sigframe __user *frame,
>   {
>   	struct sigcontext __user *sc = &frame->uc.uc_mcontext;
>   	long err;
> +
>   	/* sc_regs is structured the same as the start of pt_regs */
>   	err = __copy_to_user(&sc->sc_regs, regs, sizeof(sc->sc_regs));
> +	if (unlikely(err))
> +		return -EFAULT;
> +
>   	/* Save the floating-point state. */
>   	if (has_fpu)
>   		err |= save_fp_state(regs, &sc->sc_fpregs);
> 


-- 
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ