Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2331373imm; Thu, 7 Jun 2018 08:55:31 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJbtAVhzUEJH/5lBXGmLzjnciLK1tbHC7R6bCxSmal6SPjY639uXhMCnhlJLkCQA0OQVQSx X-Received: by 2002:a17:902:543:: with SMTP id 61-v6mr2608301plf.47.1528386931622; Thu, 07 Jun 2018 08:55:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528386931; cv=none; d=google.com; s=arc-20160816; b=o6OPGziMUa5qpxmGFCmj0nKVHe3jrVzkt0O8TzpqtwnK4vC9E6JxQbwkKMJeUaAVF4 u7f9XTj86i+26gNJJSYPIBTHxNl1jkDMC/3w0x9B6uxgw2P4F/Sxa5fAvk7kp/JwDaQW 3i68ZjHYoCLsuc26GdX0wTV/qjJlXv0ofyd8YQ9EB0Ohm0lEJiUvlu5x/Xpcs7LsLdEM hzRE/yJAqKfUNXXJWnV2CRH0hMLi+2Lpb0dE+stEghvwgrapdRH9gnR9uiEkzQx7ICxs dnygDEYUJEBme/ou4tmlt9/sfIbREdJr+RFKWl+/h1a1Hwv4oW9iKIAYAP8Uu5ftNZJk y6Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=+zmV9r9YEBEa9fAuyVSNVBAnnJzHt5J8RZf/0ZFemSU=; b=N2pB/vHNTdwS/YUW0A02QcKyd3u2Evb6eEinbwl8fTk8OCwN/hXL+c1YHfNksm3Zj6 chLEldr7avf15Wgr/k/PRGhm2oAMPgTPwQCrZluR1ZZjT2wTwp2UPjGi5Ig/WXKsFPM7 qXtoG+fkCPTzOHjeo9X/1Zl2E8KzDvH6N16n3DeaanK1yjPzx8M+WrmHaTm9B5JnAaTm k5hNGbygxPJVNNPUKSno4Q7MDPzgbhxHIsaLHFAVl+lgSmosi4ypMH1QF8L1qg6QkXyY tQ2Mles5L4DUOxLIuOJ6ZbSURT86Ou69TimuAXnmTr2J54aUmj8y/HO60w7WAWY5eYj5 Gr/A== 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 v12-v6si52725957plo.264.2018.06.07.08.55.17; Thu, 07 Jun 2018 08:55:31 -0700 (PDT) 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 S933958AbeFGOeI (ORCPT + 99 others); Thu, 7 Jun 2018 10:34:08 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:40331 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933937AbeFGOeE (ORCPT ); Thu, 7 Jun 2018 10:34:04 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbm-0005Zw-5k; Thu, 07 Jun 2018 15:09:46 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb3-0002uM-Dv; Thu, 07 Jun 2018 15:09:01 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Mikulas Patocka" , "Matt Turner" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 147/410] alpha: fix crash if pthread_create races with signal delivery In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 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: Ben Hutchings --- 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;