Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3194007pxb; Mon, 9 Nov 2020 05:18:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJyJrHIX51KnBcaGXAMZ6Sj3ysu5DM/3v6rc5QOT1SAIbctV+z/krPwGXIedygOepM+MToyi X-Received: by 2002:aa7:cd56:: with SMTP id v22mr15858379edw.245.1604927891784; Mon, 09 Nov 2020 05:18:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604927891; cv=none; d=google.com; s=arc-20160816; b=zowaMrfR0jkSHv5SoHQzxlDRZrW72RHvFqlSWckc0ToIgYpRgCYfTOphkMggGrRaB9 VzNPCqy7KmbSEMMOTms/eVTjAdK18r/JrS2uv55/jgPnsyduy3thfXO1kJQvY0ORJbK3 7vleVPmD2XVLKotpHQpqJplw+VhWdoJB7FqFcEaOs2nwJdaGT+48T8sUPND2gDeKdX/l e30kWL6SDaCmmhnQ3vn0d7yfSc2S1xPgmlMOkEUW/3iIjjdsLCuRTWD88+Frfah5EI4N o/J/vwyrZo3mfrGY8ClBVh6Tc8CaPna7oZsCxy1OxFR18KBEcEX2x+7XCVqWdx3CCnjD snog== 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=X7VRSGfyxAbMh/ETlPksWGy88wS9TNmx2ROS4wpowJo=; b=kaEkLX3GPFeVerQbY66JRZlIrHRqz56BZfSHKWP0Dk18jZHt3XLJi12jS7hSCw3WrP kaejkRz2ePrVi0FKddE2D3qE8OLLv+EXeGiy1iCAP/yNn/fMv7QIoMxfoW+j0RWjh/XE 9XIpDDGq/YyRIOijmPRYdRf04aaFee9/IVr+OwSF0SGzmcBANVjTwgCC8OpJnSYthlnH iuxv4kO4y/HtRDe+TiIuiwHK8JEc4pj4lfw/Nz6Q16wpCFCKbs/lzvfpwCnACyMmt6CW aSE0+1KWq25Evsa3er9h3kzPrUvaKe3Wnp6MaFr4G5Nl+soaRmgUh2auAAQVqlRuZ3bD Bdyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1QiTqq+6; 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 b21si7904762ejz.183.2020.11.09.05.17.49; Mon, 09 Nov 2020 05:18:11 -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=1QiTqq+6; 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 S1730879AbgKINPj (ORCPT + 99 others); Mon, 9 Nov 2020 08:15:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:42388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731747AbgKINPc (ORCPT ); Mon, 9 Nov 2020 08:15:32 -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 57B0F20663; Mon, 9 Nov 2020 13:15:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927732; bh=9BZkkRYeoLO3NL6o/mrCxp7EIqeom7WzrhpCxzTC3w0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1QiTqq+6qTZlzncS7twOHvnvGPxOa9+86ZecDvebGwQGJ1J/+HioifTlsxGnU5rPa otok+zubvKsCh+IE/OgLvcaQE0hMZAIXRKBgDMiOQLnANfijD8iWfM7X1KGmXWb3B4 VkqQp/+01wSsetH6zRbVxTIGbgKOlwT72GnPJCPQ= 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.4 65/85] fork: fix copy_process(CLONE_PARENT) race with the exiting ->real_parent Date: Mon, 9 Nov 2020 13:56:02 +0100 Message-Id: <20201109125025.691526755@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125022.614792961@linuxfoundation.org> References: <20201109125022.614792961@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 @@ -2100,14 +2100,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; } @@ -2152,9 +2147,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);