From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2861C433FF for ; Tue, 6 Aug 2019 21:38:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 727912189E for ; Tue, 6 Aug 2019 21:38:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565127492; bh=OSDZjGF/Qz2AU+ibnMfKOlSobEgeyAk25LXtXkBD0/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=GpNhdrocfhYoXhWhK8Mz7qERWZO2LCLE1YEZScGlAgBhb8KI3OObqX16ZkBGj5igI GPJy8rbKZMZLYgU1Ek0olTZfFej8IWbx6niUt+2++zXxfH2NwrA4O9HwBCGs0NKN4J pqwUhYoxS9pxRh9+69HwWTs18Z1SDbMnm/JTCWsA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729652AbfHFViK (ORCPT ); Tue, 6 Aug 2019 17:38:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:55770 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729604AbfHFViG (ORCPT ); Tue, 6 Aug 2019 17:38:06 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9A78A20C01; Tue, 6 Aug 2019 21:38:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565127485; bh=OSDZjGF/Qz2AU+ibnMfKOlSobEgeyAk25LXtXkBD0/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sIC4Hrm4Y2b+mH5yJDEVLMA77c6ylNgSUugPw+W+suic9OHrVDjoUTI+zEyAuYlQx u019R9iPJSSUJjDiwfMZdlVeDz7fhuuhlvSHkBfaDu6JL/L+WdsnP49MDD3GbNS+68 UlwWoztCqnxTWBrodu668XvYQ4sZPpJ6W42jo6sI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Christian Brauner , Oleg Nesterov , Linus Torvalds , Sasha Levin Subject: [PATCH AUTOSEL 4.4 08/14] exit: make setting exit_state consistent Date: Tue, 6 Aug 2019 17:37:42 -0400 Message-Id: <20190806213749.20689-8-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190806213749.20689-1-sashal@kernel.org> References: <20190806213749.20689-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christian Brauner [ Upstream commit 30b692d3b390c6fe78a5064be0c4bbd44a41be59 ] Since commit b191d6491be6 ("pidfd: fix a poll race when setting exit_state") we unconditionally set exit_state to EXIT_ZOMBIE before calling into do_notify_parent(). This was done to eliminate a race when querying exit_state in do_notify_pidfd(). Back then we decided to do the absolute minimal thing to fix this and not touch the rest of the exit_notify() function where exit_state is set. Since this fix has not caused any issues change the setting of exit_state to EXIT_DEAD in the autoreap case to account for the fact hat exit_state is set to EXIT_ZOMBIE unconditionally. This fix was planned but also explicitly requested in [1] and makes the whole code more consistent. /* References */ [1]: https://lore.kernel.org/lkml/CAHk-=wigcxGFR2szue4wavJtH5cYTTeNES=toUBVGsmX0rzX+g@mail.gmail.com Signed-off-by: Christian Brauner Acked-by: Oleg Nesterov Cc: Linus Torvalds Signed-off-by: Sasha Levin --- kernel/exit.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index 03f6722302b54..14c2f0717ee4b 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -619,9 +619,10 @@ static void exit_notify(struct task_struct *tsk, int group_dead) autoreap = true; } - tsk->exit_state = autoreap ? EXIT_DEAD : EXIT_ZOMBIE; - if (tsk->exit_state == EXIT_DEAD) + if (autoreap) { + tsk->exit_state = EXIT_DEAD; list_add(&tsk->ptrace_entry, &dead); + } /* mt-exec, de_thread() is waiting for group leader */ if (unlikely(tsk->signal->notify_count < 0)) -- 2.20.1