diff mbox series

[v2,2/3] MIPS: signal: Return immediately if call fails

Message ID 1639974460-3278-3-git-send-email-yangtiezhu@loongson.cn (mailing list archive)
State Accepted
Headers show
Series MIPS: signal: Modify some code | expand

Commit Message

Tiezhu Yang Dec. 20, 2021, 4:27 a.m. UTC
When debug sigaltstack(), copy_siginfo_to_user() fails first in
setup_rt_frame() if the alternate signal stack is too small, so
it should return immediately if call fails, no need to call the
following functions.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 arch/mips/kernel/signal.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

Comments

Thomas Bogendoerfer Jan. 2, 2022, 1:31 p.m. UTC | #1
On Mon, Dec 20, 2021 at 12:27:39PM +0800, Tiezhu Yang wrote:
> When debug sigaltstack(), copy_siginfo_to_user() fails first in
> setup_rt_frame() if the alternate signal stack is too small, so
> it should return immediately if call fails, no need to call the
> following functions.
> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> ---
>  arch/mips/kernel/signal.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
> index c1632e8..5bce782 100644
> --- a/arch/mips/kernel/signal.c
> +++ b/arch/mips/kernel/signal.c
> @@ -754,23 +754,25 @@ static int setup_rt_frame(void *sig_return, struct ksignal *ksig,
>  			  struct pt_regs *regs, sigset_t *set)
>  {
>  	struct rt_sigframe __user *frame;
> -	int err = 0;
>  
>  	frame = get_sigframe(ksig, regs, sizeof(*frame));
>  	if (!access_ok(frame, sizeof (*frame)))
>  		return -EFAULT;
>  
>  	/* Create siginfo.  */
> -	err |= copy_siginfo_to_user(&frame->rs_info, &ksig->info);
> +	if (copy_siginfo_to_user(&frame->rs_info, &ksig->info))
> +		return -EFAULT;
>  
>  	/* Create the ucontext.	 */
> -	err |= __put_user(0, &frame->rs_uc.uc_flags);
> -	err |= __put_user(NULL, &frame->rs_uc.uc_link);
> -	err |= __save_altstack(&frame->rs_uc.uc_stack, regs->regs[29]);
> -	err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext);
> -	err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set));
> -
> -	if (err)
> +	if (__put_user(0, &frame->rs_uc.uc_flags))
> +		return -EFAULT;
> +	if (__put_user(NULL, &frame->rs_uc.uc_link))
> +		return -EFAULT;
> +	if (__save_altstack(&frame->rs_uc.uc_stack, regs->regs[29]))
> +		return -EFAULT;
> +	if (setup_sigcontext(regs, &frame->rs_uc.uc_mcontext))
> +		return -EFAULT;
> +	if (__copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set)))
>  		return -EFAULT;
>  
>  	/*
> -- 
> 2.1.0

applied to mips-next.

Thomas.
diff mbox series

Patch

diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index c1632e8..5bce782 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -754,23 +754,25 @@  static int setup_rt_frame(void *sig_return, struct ksignal *ksig,
 			  struct pt_regs *regs, sigset_t *set)
 {
 	struct rt_sigframe __user *frame;
-	int err = 0;
 
 	frame = get_sigframe(ksig, regs, sizeof(*frame));
 	if (!access_ok(frame, sizeof (*frame)))
 		return -EFAULT;
 
 	/* Create siginfo.  */
-	err |= copy_siginfo_to_user(&frame->rs_info, &ksig->info);
+	if (copy_siginfo_to_user(&frame->rs_info, &ksig->info))
+		return -EFAULT;
 
 	/* Create the ucontext.	 */
-	err |= __put_user(0, &frame->rs_uc.uc_flags);
-	err |= __put_user(NULL, &frame->rs_uc.uc_link);
-	err |= __save_altstack(&frame->rs_uc.uc_stack, regs->regs[29]);
-	err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext);
-	err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set));
-
-	if (err)
+	if (__put_user(0, &frame->rs_uc.uc_flags))
+		return -EFAULT;
+	if (__put_user(NULL, &frame->rs_uc.uc_link))
+		return -EFAULT;
+	if (__save_altstack(&frame->rs_uc.uc_stack, regs->regs[29]))
+		return -EFAULT;
+	if (setup_sigcontext(regs, &frame->rs_uc.uc_mcontext))
+		return -EFAULT;
+	if (__copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set)))
 		return -EFAULT;
 
 	/*