Received: by 10.223.185.116 with SMTP id b49csp2395624wrg; Thu, 15 Feb 2018 10:58:42 -0800 (PST) X-Google-Smtp-Source: AH8x227tHt3inIjpMAo5xc81Mvgvh0xzkXjjz2MhurUSKYGMu0+Ewn31wzclROLwNfOREcUxbqEL X-Received: by 2002:a17:902:42a3:: with SMTP id h32-v6mr3484190pld.231.1518721122267; Thu, 15 Feb 2018 10:58:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518721122; cv=none; d=google.com; s=arc-20160816; b=jN6RuJK9j8H6SEsnRbDdpfwyPzPqj8Engucf6sTnwsHWjaGkAAvQ5l+bWPOFDAN811 O69dVtVpju7vZYh5U++gMz1AXKOyeYjfCIekRV+v2cRQi2QXi/0ItWnuoIbLrWSZyWkD E4gF2CyUQPDjEkKQ54JjhxcMU+MRJfvyWSmQrSsZbxmHrzQPDcHXxhFUlznb2NH3fDYL 1xcEuXhCakOa1VSrdTDVfx3vbjtmjBxvWJQ6LhRNPrSHJrZ99jeWEExbSCUhcRvbBpvp Xom30Lv81AfIMFWLm/EFA0zLRHQTuFnu0XVn5k/36vB/lF5uzGsvtqvtoS0EkrSURMfc +9ig== 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=Z1Y+cZZZbz3WJFEZpDgVNtt7Ul1SaKmbzaw5xk5W4Uo=; b=G88ihmRS4m07QsUA7BGrdBKGYoqmcaW1ibZx/nheav1NB4kmZhJFbLqK/zlFRCnYfm 4fWtn7+WB866cMreRLdFe78sHM/NSOr5WDTLNftQW3Z6peKNQsr/3rAKoHIPxwWxd3LE 8ySUUheB9VaZ46RpkD0vLltp+ihQFeXsDlR1LfNmEFD5YFeZZsgbTxYj/5dRPbfBV9fd WgLaiLgXhUK5FqZh+NvAes7cWWEOzWmn1XjJgtw9PO6j9FfNBceADG/BCT6nkNi06g/y 2pgJhpAvyJW1vG7EpD2LecAClnPUCdtfptGMTGo5wNS62L4vRhaDb3EBLdCkiY9W7Y3H IcOA== 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 m7si3156490pgp.542.2018.02.15.10.58.27; Thu, 15 Feb 2018 10:58:42 -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 S1162319AbeBOS50 (ORCPT + 99 others); Thu, 15 Feb 2018 13:57:26 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:48144 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161497AbeBOPUA (ORCPT ); Thu, 15 Feb 2018 10:20:00 -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 C7F001025; Thu, 15 Feb 2018 15:19:59 +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 3.18 39/45] alpha: fix crash if pthread_create races with signal delivery Date: Thu, 15 Feb 2018 16:17:30 +0100 Message-Id: <20180215144124.185475467@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215144115.863307741@linuxfoundation.org> References: <20180215144115.863307741@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 3.18-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 @@ -274,12 +274,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;