Received: by 10.223.185.116 with SMTP id b49csp2177006wrg; Thu, 15 Feb 2018 07:40:23 -0800 (PST) X-Google-Smtp-Source: AH8x226jCtkAbZKUF4g1W/O6Dm7kRM5ytF35jvBKYQNaVCZHhP+xzrU2WsaAKxF5lThD/VlpFRkf X-Received: by 2002:a17:902:718e:: with SMTP id b14-v6mr3005969pll.38.1518709223753; Thu, 15 Feb 2018 07:40:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518709223; cv=none; d=google.com; s=arc-20160816; b=AZnElqABDT776dAiAOwblXrgS92wcGdPrXcueo2KcU8PELvrUtEjzPdCsUJ0Vwg0qG QawZw+AyUPpi5IRqhabFVY0TmdhCQHFnGG4PPr+br8/JTCN7bjga2hXCaHxBSHP3kZmi i78V+ufoDCrFL8IQjoqPMfiNeQiPxsKeczwofiTS1q0ICJPoQ7nEFAJxacMHDjWdsOVC kbatyEhWALvrG1yDdc0KG7wc4vPJl7X+QorGgvxUiCb4CV/VZzjQWmMl8BNS47bvXb4z 8GrOy0sCvlK9wSExdvu1PdyO9xi5Su1Mhr5Oufvyx9Px1PvENw/NHD2QZKpOuftf7o7/ G7hQ== 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=3nBQeZJPeITtwgmFzuOLRpZfe25t+gYPUspvMUwcKD8=; b=hgQzmowdeeanV6C7kaZ56ENhGxnsokV0lBHuNWYU47vZAOwb4P+q3g8kTzY1qfRpi5 TXV64Ax4e5nWhOHr3q0Se52xgw0gG9D6xFjG5o8XrJwwHasKkXRevBnuM7vRvzWe7UPL AqgGnn5SHDCTLg2X/wltAd3IIPaxjxeNUMGjFWP0fLO+VQajntB5B7+3GY7VfRHwGXnz c27C52rzRtQXuAFoAWn7STG6Ym+ePqULsT/jPyDvbM60PtGNOpwWQ91ylt17Y4sj7Dtd VzDIxcinNKU70M2lZYCYqs0c2j6SVCLesPWlbdcWIUnd53jxWhg/fX68s+GNVuTZzSIE tgKw== 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 f30-v6si1530034plj.436.2018.02.15.07.40.08; Thu, 15 Feb 2018 07:40:23 -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 S1423415AbeBOPiv (ORCPT + 99 others); Thu, 15 Feb 2018 10:38:51 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:59504 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423360AbeBOPij (ORCPT ); Thu, 15 Feb 2018 10:38:39 -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 3687A1104; Thu, 15 Feb 2018 15:38: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.14 164/195] alpha: fix crash if pthread_create races with signal delivery Date: Thu, 15 Feb 2018 16:17:35 +0100 Message-Id: <20180215151714.169728341@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151705.738773577@linuxfoundation.org> References: <20180215151705.738773577@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.14-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;