Received: by 10.223.185.116 with SMTP id b49csp2578600wrg; Thu, 15 Feb 2018 14:01:48 -0800 (PST) X-Google-Smtp-Source: AH8x226ur3Uwh6LFfb7cC8cu3zlxiSVBeneViwpyO0r0wqJ22JGd71m3SsMOlcIPpoOxSbGs3V+I X-Received: by 2002:a17:902:7006:: with SMTP id y6-v6mr3816166plk.37.1518732108122; Thu, 15 Feb 2018 14:01:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518732108; cv=none; d=google.com; s=arc-20160816; b=LrjWjXja2LWu0yHlOA0A3qgG24A2Rr7PdmynRd2VWzDF7HNTb/ocbNEzGZIWLd61ge xdd1WhKIROg7Ts8m5wwcf8Dtv6g0ny5nS1HwKoZ+LFwugf10A9is+epiIDxSWoxz/Sw3 Zm3Tk5zCmr7rsWpbqK333vQMYY3yI5KSYdmku9CB/q/725P9Vsi06gPGhTa9PEQxPvU2 GK4mSgjw47ycDhhZi0NQtus887HC6R0f9nVNSd1jj+Vizlm82N12FFSfwjAs0cTpgB8t ym+dwaheCb0wdF45uYKPQgAQmT31ETW/jTx0+N1mVF+q6zW3LP8JY6uak0NZad/uQLKd KpOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ZdHEMg9XkGSkTr4bHjEHHt2GHgGAThJOj1i+6TzhA9k=; b=btVpyf12C0IuLW2vmCzhExQSvd1hU7V66z0yL8+MtWPpTFrCuseLkEY9WZ8KwlQknU egXYqIRglcw78dE99XlhZCPMxWEiVXmiD0XPaRrC6v0Mb5Ul//HhFDVUJCfmFGK1UhTS gbLjq6rnT9lgzn3ZBv250oEZV3EnHJikvTdWh5NasRqByPfJ8uLB3rfUSowH6wYSLfpK Wg3vN1AAy2SvR5uOdj0+DKdv/wD0jCw5auM8BGwfvX1mt/fxLOr0p+kqGto07gHAVbgs 5z/TYdOdKkZXB6SI9EiXX70Q2RkAGnyixtPjra6YkULqpHQFP56mQTYqCbiLgSM62DV+ JiZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 91-v6si100271plh.570.2018.02.15.14.01.33; Thu, 15 Feb 2018 14:01:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1163861AbeBOP2m (ORCPT + 99 others); Thu, 15 Feb 2018 10:28:42 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:53886 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1163370AbeBOP2k (ORCPT ); Thu, 15 Feb 2018 10:28:40 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 42BB41075; Thu, 15 Feb 2018 15:28:39 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikulas Patocka , Matt Turner Subject: [PATCH 4.9 72/88] alpha: fix crash if pthread_create races with signal delivery Date: Thu, 15 Feb 2018 16:17:39 +0100 Message-Id: <20180215151232.467437894@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151222.437136975@linuxfoundation.org> References: <20180215151222.437136975@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mikulas Patocka commit 21ffceda1c8b3807615c40d440d7815e0c85d366 upstream. 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 = 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 Signed-off-by: Matt Turner Signed-off-by: Greg Kroah-Hartman --- arch/alpha/kernel/process.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/arch/alpha/kernel/process.c +++ b/arch/alpha/kernel/process.c @@ -265,12 +265,13 @@ copy_thread(unsigned long clone_flags, u application calling fork. */ if (clone_flags & CLONE_SETTLS) childti->pcb.unique = regs->r20; + else + regs->r20 = 0; /* OSF/1 has some strange fork() semantics. */ childti->pcb.usp = usp ?: rdusp(); *childregs = *regs; childregs->r0 = 0; childregs->r19 = 0; childregs->r20 = 1; /* OSF/1 has some strange fork() semantics. */ - regs->r20 = 0; stack = ((struct switch_stack *) regs) - 1; *childstack = *stack; childstack->r26 = (unsigned long) ret_from_fork;