From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 335B04A2043; Mon, 21 Sep 2026 13:45:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789998337; cv=none; b=H5s0Um4rq/4aVWqd9VUyicBoWDotauWVS8eV+Dbg5aoynLmZTCBAThR2dKqRWL6H9qvHGldEjfPYPfR/+w5QGuAAFtir1XY51xeBcOsc7Uf0XHqfm9DGp/E9+bgq+jU7DovAdv3U1XxHeADZQ8NpiqbzmkxgJuzn1RodDAXFWEw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789998337; c=relaxed/simple; bh=7KUzGKGrk7V1HZ7iUNzf5pjBye0tThbmUGx9Q6GKXVc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=E5x88TvtQ8XJGAmPt2pU4/BgLaJShADMXIVcZyKSlmrLKtpCpbZyw8HrDVLIZBzvKdZOl/wtsyvlun6PZ3zL1LSznemQObbapGcNv8QJKiNyS5xBW0FXKkSFNvA3ogMJgA51W47T6LEdHbId6ZZyRMH5cgsYzV1hApjgPTaIawM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TpW5IZj4; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TpW5IZj4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E00E71F000FF; Mon, 21 Sep 2026 13:45:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789998335; bh=uDFVbgvJ7xnyyLVrNwCFS2r46etfsHvtzm5ZhTttIBA=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=TpW5IZj4rtYbO7lCDv8Q6KmiwLq6HAR/i7W+BErM3FKlJkW9OaOgQ707omWL5/9c4 +a+zAPvP/tEereXm4zwjqCcpCdDjeR2RAKNJwtSGPDSHOgpBeDJk3dZ35ATe5TYLgw JtCoRGNNo7surhqgOFk6ZKHHjPqUqG6iM03saVORaEWzSuRGzm+f6rntLQpohhO5lk DZeFDLIQJVmGJ8zboy58GmFMnxLG12Y05OGTDYdkyrf/mVY0ADLwtjhy9geyg0lXJY lucpjqfBpxI+SB8HAwHkFtaKBFFMIY/zE4PBvgeOyDC19ROAoH/Q5DnDZ9cJLR4GwH 6SDoGwz2MDDSw== From: Christian Brauner Date: Mon, 21 Sep 2026 15:44:57 +0200 Subject: [PATCH v3 08/17] exit: hang up the tty before closing the files Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260921-work-coredump-fixes-v3-8-8e4adb1619e6@kernel.org> References: <20260921-work-coredump-fixes-v3-0-8e4adb1619e6@kernel.org> In-Reply-To: <20260921-work-coredump-fixes-v3-0-8e4adb1619e6@kernel.org> To: Oleg Nesterov , Chris Mason , linux-fsdevel@vger.kernel.org Cc: Jens Axboe , Alexander Viro , Jan Kara , NeilBrown , Ingo Molnar , Peter Zijlstra , linux-mm@kvack.org, io-uring@vger.kernel.org, "Christian Brauner (Amutable)" X-Mailer: b4 0.17-dev-db0b7 X-Developer-Signature: v=1; a=openpgp-sha256; l=2967; i=brauner@kernel.org; h=from:subject:message-id; bh=7KUzGKGrk7V1HZ7iUNzf5pjBye0tThbmUGx9Q6GKXVc=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWRtNLnz5PgfRi+mGLtds24IJjJ2zdO/ldP6upLXrjXK9 4IO30/3jlIWBjEuBlkxRRaHdpNwueU8FZuNMjVg5rAygQxh4OIUgIlU7mNk2Hn/cfH6PMsnjzZu Z43iicyXNSx6ocTyvXH6D1mHgF+RCxkZTh66purH4RJ4qev/Df7YfaHL+aJURbjExeQkdJOD1r5 kBQA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 do_exit() closes the task's files in exit_files() and hangs up the controlling tty of a session leader in disassociate_ctty(1) after that. Since commit d99d38540bf0 ("fs: make close_files() synchronous") the final __fput() of every file runs inside exit_files(). So when the session leader holds the last open of its tty the tty is released before disassociate_ctty() runs. tty_release() clears signal->tty for the whole session in session_clear_tty() once the count drops to zero and sends no signal doing so. disassociate_ctty(1) then finds neither a tty nor a tty_old_pgrp and does nothing. The foreground process group loses its SIGHUP: do_exit() exit_files() close_files() tty_release() tty->count == 0 session_clear_tty() signal->tty = NULL, no signal disassociate_ctty(1) get_current_tty() NULL signal->tty_old_pgrp NULL, nothing sent That only affects real ttys. For a pty the master's open keeps the slave's count above zero. And it only affects a foreground job that holds no descriptor to the tty anymore while its session leader exits. Everything else is unchanged. The DTR drop on the last close happens in tty_port_shutdown() regardless, stopped jobs get their SIGHUP from kill_orphaned_pgrp() and signal->tty is cleared either way. Before that commit the final __fput() ran from exit_task_work() which comes after disassociate_ctty(). That order isn't old. Until v3.14 exit_task_work() came right after exit_files() and before v3.6 fput() was synchronous, so the tty was always released first. Commit c39df5fa37b0 ("exit: call disassociate_ctty() before exit_task_namespaces()") moved disassociate_ctty() up to fix a pppd crash and in front of exit_task_work() as a side effect. The hangup in this case has worked since then and that's eleven years of userspace being able to rely on it. Hang the tty up before closing the files. This is the ordinary hangup with the file still open: __tty_hangup() swaps in hung_up_tty_fops and tty_release() runs from the close afterwards as it does when a modem drops the line. disassociate_ctty() stays in front of exit_task_namespaces() which the pppd fix needs. Reported-by: Chris Mason Signed-off-by: Christian Brauner (Amutable) --- kernel/exit.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index 55dbea3b242e..9ed5eb03d0e1 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -1003,10 +1003,11 @@ void __noreturn do_exit(long code) exit_sem(tsk); exit_shm(tsk); - exit_files(tsk); - exit_fs(tsk); + /* Hang the tty up before the last close of it can clear the session. */ if (group_dead) disassociate_ctty(1); + exit_files(tsk); + exit_fs(tsk); exit_nsproxy_namespaces(tsk); exit_task_work(tsk); exit_thread(tsk); -- 2.53.0