Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3197147pxb; Mon, 9 Nov 2020 05:22:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJwh5WCUAx/lH7DDa4TS/V9fU8ioBQvrMTAvcISH/nDHpkOfa8BHagEiH86qFcu6x9pfB2+r X-Received: by 2002:a17:906:3e8f:: with SMTP id a15mr6814506ejj.57.1604928144650; Mon, 09 Nov 2020 05:22:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604928144; cv=none; d=google.com; s=arc-20160816; b=Vxo232cJnaSYzF4HtLZA6sLOUZ5I31b4atp0OBg/w2uGg8hq9GSX2NExE4/MWENj45 VI9foo5mij1Gun1/ZYmFGogipFnC86J9FTqOLeRPSY0MsWZY+O0JD7tybLsQ9AWz9I03 rD6LIPgz0lbJh/kr48FTCtmQ/Tqxv+J+40ej/Bkhh6Vtovsot0koogkPsZvlxgOBuHIa ZGaG3fpnAtq1Ms7I8QDbasnLntbrNcsIN+KSbfn0wfphP1bwTyoedl6G/Ld8fvp49yTK mB98YwmtoH5rS1IeYZBEfpwDEbdeS7IJ7TCH/zzmeg8oyOdYuRBpqmIifCgxbS9a5mj2 YZ+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GRMhbfw3QvlB3k0Qd8Y36ZzSIOl0rQR4i4Yu3nIe62s=; b=Vo/gc9II8iLBCudQuyJvus61uvRSQScU0Hkp3H7WsQgWBoX2JLx1b2lsFzfMegFKWg xBkIM2/q9WkzqDWrn496yOQdWC7cWpR7G0IgtBRXo2A6IdGmAlB0gauNTOouTB+1KxtS xN3cN7EsfhWNcUW7k9RRJY96Nzhc93PzjbwGi5V08j4IFFBqxDwskBRx0Zji9SrPyqjs 5AYtVTKlBpJaIu9Q4/6cLQLhhl0Jz8VzT5UV4ZDuwghZQ1DXbepGmcBOR2hexMy+8x8K XeeqIL9WUEhiR+KuQJ3q0Ek5ohS5+yRkwzwdjiAFmsVkrg4EzHzEZrWGBDpyftdgLot7 +etw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P7WpGmib; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z11si6816064ejr.354.2020.11.09.05.21.59; Mon, 09 Nov 2020 05:22:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P7WpGmib; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733269AbgKINUq (ORCPT + 99 others); Mon, 9 Nov 2020 08:20:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:48364 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387960AbgKINUn (ORCPT ); Mon, 9 Nov 2020 08:20:43 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9BAEF2083B; Mon, 9 Nov 2020 13:20:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604928042; bh=/t+3jZHJb1n+jV2ThxdF7BUzZJwvGnf3gsuDXnIyPRA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P7WpGmibd1r1lJTdmsuHr4WkGG4Ttunn7QREomqOxVmSdA6Mk3LRjhd1oqD8wzwzl 2dsYGWGipB/nuD7QdJD0NU3pQPks129cWrFSm4XCyTu8Iygez2ZV+f5/pKdt3/B9gd qkCbjQFvKdAmLKlSsVYym8UwuCunVJQCawKWu3iI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eddy Wu , Oleg Nesterov , Linus Torvalds Subject: [PATCH 5.9 108/133] fork: fix copy_process(CLONE_PARENT) race with the exiting ->real_parent Date: Mon, 9 Nov 2020 13:56:10 +0100 Message-Id: <20201109125035.885276818@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125030.706496283@linuxfoundation.org> References: <20201109125030.706496283@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eddy Wu commit b4e00444cab4c3f3fec876dc0cccc8cbb0d1a948 upstream. current->group_leader->exit_signal may change during copy_process() if current->real_parent exits. Move the assignment inside tasklist_lock to avoid the race. Signed-off-by: Eddy Wu Acked-by: Oleg Nesterov Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- kernel/fork.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2167,14 +2167,9 @@ static __latent_entropy struct task_stru /* ok, now we should be set up.. */ p->pid = pid_nr(pid); if (clone_flags & CLONE_THREAD) { - p->exit_signal = -1; p->group_leader = current->group_leader; p->tgid = current->tgid; } else { - if (clone_flags & CLONE_PARENT) - p->exit_signal = current->group_leader->exit_signal; - else - p->exit_signal = args->exit_signal; p->group_leader = p; p->tgid = p->pid; } @@ -2218,9 +2213,14 @@ static __latent_entropy struct task_stru if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) { p->real_parent = current->real_parent; p->parent_exec_id = current->parent_exec_id; + if (clone_flags & CLONE_THREAD) + p->exit_signal = -1; + else + p->exit_signal = current->group_leader->exit_signal; } else { p->real_parent = current; p->parent_exec_id = current->self_exec_id; + p->exit_signal = args->exit_signal; } klp_copy_process(p);