linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eddy Wu <itseddy0402@gmail.com>
To: oleg@redhat.com
Cc: security@kernel.org, linux-kernel@vger.kernel.org,
	eddy_wu@trendmicro.com
Subject: [PATCH] fork: fix copy_process(CLONE_PARENT) race with the exiting ->real_parent
Date: Sat, 7 Nov 2020 14:47:22 +0800	[thread overview]
Message-ID: <20201107064722.GA139215@arch-e3.localdomain> (raw)

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 <eddy_wu@trendmicro.com>
---
 kernel/fork.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index da8d360fb032..7abda2a888a9 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -2142,14 +2142,9 @@ static __latent_entropy struct task_struct *copy_process(
 	/* 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;
 	}
@@ -2193,9 +2188,14 @@ static __latent_entropy struct task_struct *copy_process(
 	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);
-- 
2.17.1


             reply	other threads:[~2020-11-07  6:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-07  6:47 Eddy Wu [this message]
2020-11-08 19:19 ` [PATCH] fork: fix copy_process(CLONE_PARENT) race with the exiting ->real_parent Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201107064722.GA139215@arch-e3.localdomain \
    --to=itseddy0402@gmail.com \
    --cc=eddy_wu@trendmicro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=security@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).