Return-Path: Received: from mail-by2nam03on0090.outbound.protection.outlook.com ([104.47.42.90]:61856 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032422AbeCAPfD (ORCPT ); Thu, 1 Mar 2018 10:35:03 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Mikulas Patocka , Matt Turner , Sasha Levin Subject: [added to the 4.1 stable tree] alpha: fix crash if pthread_create races with signal delivery Date: Thu, 1 Mar 2018 15:26:16 +0000 Message-ID: <20180301152116.1486-349-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Mikulas Patocka This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 21ffceda1c8b3807615c40d440d7815e0c85d366 ] On alpha, a process will crash if it attempts to start a thread and a signal is delivered at the same time. The crash can be reproduced with this program: https://cygwin.com/ml/cygwin/2014-11/msg00473.html The reason for the crash is this: * we call the clone syscall * we go to the function copy_process * copy process calls copy_thread_tls, it is a wrapper around copy_thread * copy_thread sets the tls pointer: childti->pcb.unique =3D regs->r20 * copy_thread sets regs->r20 to zero * we go back to copy_process * copy process checks "if (signal_pending(current))" and returns -ERESTARTNOINTR * the clone syscall is restarted, but this time, regs->r20 is zero, so the new thread is created with zero tls pointer * the new thread crashes in start_thread when attempting to access tls The comment in the code says that setting the register r20 is some compatibility with OSF/1. But OSF/1 doesn't use the CLONE_SETTLS flag, so we don't have to zero r20 if CLONE_SETTLS is set. This patch fixes the bug by zeroing regs->r20 only if CLONE_SETTLS is not set. Signed-off-by: Mikulas Patocka Cc: stable@vger.kernel.org Signed-off-by: Matt Turner Signed-off-by: Sasha Levin --- arch/alpha/kernel/process.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/alpha/kernel/process.c b/arch/alpha/kernel/process.c index 84d13263ce46..8095fb2c5c94 100644 --- a/arch/alpha/kernel/process.c +++ b/arch/alpha/kernel/process.c @@ -273,12 +273,13 @@ copy_thread(unsigned long clone_flags, unsigned long = usp, application calling fork. */ if (clone_flags & CLONE_SETTLS) childti->pcb.unique =3D regs->r20; + else + regs->r20 =3D 0; /* OSF/1 has some strange fork() semantics. */ childti->pcb.usp =3D usp ?: rdusp(); *childregs =3D *regs; childregs->r0 =3D 0; childregs->r19 =3D 0; childregs->r20 =3D 1; /* OSF/1 has some strange fork() semantics. */ - regs->r20 =3D 0; stack =3D ((struct switch_stack *) regs) - 1; *childstack =3D *stack; childstack->r26 =3D (unsigned long) ret_from_fork; --=20 2.14.1