Received: by 10.223.185.116 with SMTP id b49csp2516432wrg; Thu, 15 Feb 2018 12:52:31 -0800 (PST) X-Google-Smtp-Source: AH8x2253hTweQ+6Wq7eZ2v/VBoxxOffu6xx5h4CdBEiKuLHrLlj8HEhTJ9SLgWp/7jD28EmT89L/ X-Received: by 10.98.144.213 with SMTP id q82mr3835971pfk.37.1518727951891; Thu, 15 Feb 2018 12:52:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518727951; cv=none; d=google.com; s=arc-20160816; b=Ho2gq3r374mrGHkQK1WB5uEi1oxIK5Vx2WIpnyEj6xNxuZlFzT6MQEFaPHwnohaha4 PW+8RDATPmlQz25Rurk63SxM6jbjYKfAABpr4z0gB3sgiv4lSNsEJd3qoV4Bj1RZm9Dt ZYgo6mII0hdSUFGNRQX2SxJ61BHJkqS24iR6UiLQ7qfJO66ohAPSrNOnLouWkqeU2/MG E2JhvSDFOeOm0HNCH+v8P83pg8Fx9K1IJ4GiyOkUlEraJElw8pjBR49IlTpPkwLM0IDl ZpZfybMtZRu/5NUQl4SkyU4zOwvF1eQ6oxEP7S/8nxSJ90YjEBmm9llIWHqcv3t5KLLA qY8w== 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=PlJ0uL8JGIJOQORrmeurnRvVN1O0gtxua9RVckWxrvM=; b=RXYIOBgPnl3IbPmthFII2j3gVetwOHSBZI/YK2qjdWk1OO3bijPIWg/LUHe50N8tTf Jd2FnLUBQFfZXRDFaZ9D8uJP7q0riLsXt+NiE5IA/Sq2U/wzcUuG8eE5odSgeW7ZM1Uc 9/Qo0NU3eD5xppHPL5uocmQreUQikQU2qy0Zr1WyVTBWJtNRNurJuARMghvEOB7vwScM QUj0xWQY9iXAbDktl8QcoFUrvCambm++xWw+LLrjIAj+iJoeEoYlEXq2j+JVSLhXDOBy 4EDfMs4cs/EVEohi1ilnrwy/4XsCt7mrP8HcWlzm0O87+TjhoBZE0lR6VN89FQ83Zy9V FwvQ== 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 71-v6si3310624plc.713.2018.02.15.12.52.17; Thu, 15 Feb 2018 12:52:31 -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 S1162984AbeBOPYw (ORCPT + 99 others); Thu, 15 Feb 2018 10:24:52 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:51984 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033898AbeBOPYs (ORCPT ); Thu, 15 Feb 2018 10:24:48 -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 8EF73FEC; Thu, 15 Feb 2018 15:24:47 +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.4 098/108] alpha: fix crash if pthread_create races with signal delivery Date: Thu, 15 Feb 2018 16:17:35 +0100 Message-Id: <20180215151235.985833721@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151222.267507937@linuxfoundation.org> References: <20180215151222.267507937@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.4-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 @@ -273,12 +273,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;