Received: by 10.223.185.116 with SMTP id b49csp237479wrg; Thu, 15 Feb 2018 20:49:26 -0800 (PST) X-Google-Smtp-Source: AH8x225zIPql1L9Ewa2ydFhWlm7epuE/0d6MpL/X5PUr+ip/8XRre4ml60n/3Pvhj14rIaolj8E1 X-Received: by 10.99.43.73 with SMTP id r70mr4237640pgr.316.1518756566719; Thu, 15 Feb 2018 20:49:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518756566; cv=none; d=google.com; s=arc-20160816; b=cO6eeLvMEGAAWhd9dBEJEQPQvFGuQv2g94b/FSwIoo/l4QDd59sFDoiN/mJs5rmP0g nUv1BnOcCa74DG9q/7fXlRzVZ56KA4L/rdktwNUJF05fb2jxZKBDeP7m6iRkAfd1i6iA hAyXnH97nHEDR1eHU3JKq3/K4fXrIe5P3gURBWgPzTuPomF8Er+E1C0sBheU2HDvf6xa p4U8YL0+EmYxV6qQx1H2zPphe21Ly+fs+FFbDm/lzDVwMAVXlklst9ZV42ctdLV71Er3 pV5Fp+GNf0pXb1xgQRcfKb/mEhmedYpR9unWq+cTNHWrZKh2dMYUXZyE5ULpkJa7ntZh rR6Q== 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=7MjV7CmF9j/weCNRcn0fI4D9fBfUusRbERoubk/z9ro=; b=yKF0gaq2OHTt3k5XO53i+vU3QEmaty5LHeSVO7bzFO4LXngDRL4mpD3SIm4/sneFAw AjYq8wYCHYQs9zDxbcuIHonlfGWWJL0T2Y0FJTYBEHIAXfP+Di+b/KePlzjdDV37svjh yr3AXccDcCkgFAIrThkZINVqrkFKUsYs9KRKh773LmKI4j8O3axncj4EtpCizzF4HcJC wOakGD2Q+/qtjKE0d2lkVeH2JmRCROhy8B4tVGCrGLGNaJyIqHU1CJpbfBOuVbycTQvR Lktbd3XNf1eo4U1xMp/mEaHCMId0KbUV7MkT8o9pfXU4NnxreY8Tq0XS4P/DfAtIP3Iv BbMw== 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 d2si2310384pgc.758.2018.02.15.20.49.12; Thu, 15 Feb 2018 20:49:26 -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 S1425007AbeBOPsB (ORCPT + 99 others); Thu, 15 Feb 2018 10:48:01 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:36398 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424419AbeBOPr7 (ORCPT ); Thu, 15 Feb 2018 10:47:59 -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 9D5AD107D; Thu, 15 Feb 2018 15:47:58 +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.15 168/202] alpha: fix crash if pthread_create races with signal delivery Date: Thu, 15 Feb 2018 16:17:48 +0100 Message-Id: <20180215151721.658590860@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151712.768794354@linuxfoundation.org> References: <20180215151712.768794354@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.15-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 @@ -269,12 +269,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;