Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3209499pxb; Mon, 9 Nov 2020 05:39:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJzLBLSoRTVBblPwraWa4oytwTZ7JCbXa5npbxSPg8lDvSxl/49zl9/UcXamc89V0K8T1XFE X-Received: by 2002:a17:906:2581:: with SMTP id m1mr14701714ejb.28.1604929183421; Mon, 09 Nov 2020 05:39:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604929183; cv=none; d=google.com; s=arc-20160816; b=QtoiEbcFJ5JAUuaMLQYApRHLjDyoZnUYokcnlI5CXSZ3qGNp3vOm/hdbQbGNoGfpyB +IJHRvxRrO8A/5RiOugEvgqZIWiDza8O7sydZzr85ZBAyqcqJgs0jxi3YhK2UA5F3aQj d4u4UM6QhrALJW63cRT+tf6eAKYW27y2eogK38GeobUx0FJHHnH/LqmjZ5bnhhiUcKIK caqlawQjsBediaJBtX/YAhzUgq9x32HpNDBpFDc2HeRC/fyLSYLszzni7U5QsZcJwQWW ohdn0dZWy63VpPtPQ8wR3Cncpt9Ve+Y8GHkmzqIgbR4VfkYLfW/eN1pS6d42QYH/K7oE zPsA== 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=AcDt1WkrKfT441WZ0W1FbiO6MQ/mcN4jrCRCvdDKGF4=; b=MXmYUeIqmDnXyOJyBaY/lgsDTAPNd9Vt7OM8a6ss7NcmElQ3Sw03kx6t/EtkVmgIe+ OGs4YQ5edIWWZpR1yyUNwy6j0hEWjRZ6oZ8GWDELtXyBBc19uDGJ/wf9K3J9CVULf8he iYl5UW1SJ1nCOy1QzBX1w9vEfoKdQlJrIRiMZWyNT+Uyppv18mSeZzmjiiO0A2aFq4hf 69a5ySMTQsqbfxuhJxUUrsvJ/MXxU144d1NYz63NIcN8vzoSBnh6jjnbgqnAeJ2ww0r/ 6znPTHfRNyMnMFCjqs1+mSTfAeJ8NuCwXwKBtmSJ2P9iD0nd24F0RW2zqpsUzIOFr0Ar 7yFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="WhH7I68/"; 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 n24si6778273ejz.56.2020.11.09.05.39.20; Mon, 09 Nov 2020 05:39:43 -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="WhH7I68/"; 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 S1730813AbgKINgH (ORCPT + 99 others); Mon, 9 Nov 2020 08:36:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:57976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729923AbgKINFA (ORCPT ); Mon, 9 Nov 2020 08:05:00 -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 0A5EE208FE; Mon, 9 Nov 2020 13:04:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927099; bh=ef9/qyGJ78ktTUhoZ/at448M9lx8y/92F3OfgmH8dqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WhH7I68/n76MrVkcIFZH1VMKdQvb5vidJxpKwxmOeUTOVHJk57XcVjb4TqpgB8XS5 sfDS7ISI/kYNlXxIKzZt9AQMKO+ZwzyMI9/CZipZ3E6jrfk+rc2B3jmQQzT8IbpdPO xO/u/fGYtUQjv66bSYlNSkACRCp4HO15m2h5jq5I= 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 4.9 109/117] fork: fix copy_process(CLONE_PARENT) race with the exiting ->real_parent Date: Mon, 9 Nov 2020 13:55:35 +0100 Message-Id: <20201109125030.872108197@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125025.630721781@linuxfoundation.org> References: <20201109125025.630721781@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 @@ -1734,14 +1734,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 = (clone_flags & CSIGNAL); p->group_leader = p; p->tgid = p->pid; } @@ -1786,9 +1781,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 = (clone_flags & CSIGNAL); } spin_lock(¤t->sighand->siglock);