[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20241217150913.GB29091@redhat.com>
Date: Tue, 17 Dec 2024 16:09:14 +0100
From: Oleg Nesterov <oleg@...hat.com>
To: Nam Cao <namcao@...utronix.de>
Cc: Shuah Khan <shuah@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Dylan Hatch <dylanbhatch@...gle.com>,
"Eric W . Biederman" <ebiederm@...ssion.com>,
John Ogness <john.ogness@...utronix.de>,
Kees Cook <kees@...nel.org>, linux-kernel@...r.kernel.org,
linux-fsdevel@...r.kernel.org, linux-kselftest@...r.kernel.org,
stable@...r.kernel.org
Subject: Re: [PATCH 1/2] fs/proc: do_task_stat: Fix ESP not readable during
coredump
On 12/17, Oleg Nesterov wrote:
>
> On 11/06, Nam Cao wrote:
> >
> > @@ -534,6 +517,23 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
> > ppid = task_tgid_nr_ns(task->real_parent, ns);
> > pgid = task_pgrp_nr_ns(task, ns);
> >
> > + /*
> > + * esp and eip are intentionally zeroed out. There is no
> > + * non-racy way to read them without freezing the task.
> > + * Programs that need reliable values can use ptrace(2).
>
> OK,
>
> but then:
>
> > + * The only exception is if the task is core dumping because
> > + * a program is not able to use ptrace(2) in that case. It is
> > + * safe because the task has stopped executing permanently.
> > + */
> > + if (permitted && task->signal->core_state) {
> > + if (try_get_task_stack(task)) {
> > + eip = KSTK_EIP(task);
> > + esp = KSTK_ESP(task);
> > + put_task_stack(task);
>
> How can the task->signal->core_state check help ?
>
> Suppose we have a task T1 with T1-pid == 100 and you read /proc/100/stat.
> It is possible that the T1's sub-thread T2 starts the coredumping and sets
> signal->core_state != NULL.
>
> But read(/proc/100/stat) can run before T1 gets SIGKILL from T2 and enters
> the kernel mode?
Can't the trivial patch below fix the problem?
Oleg.
--- xfs/proc/array.c
+++ x/fs/proc/array.c
@@ -500,7 +500,7 @@
* a program is not able to use ptrace(2) in that case. It is
* safe because the task has stopped executing permanently.
*/
- if (permitted && (task->flags & (PF_EXITING|PF_DUMPCORE))) {
+ if (permitted && (task->flags & (PF_EXITING|PF_DUMPCORE|PF_POSTCOREDUMP))) {
if (try_get_task_stack(task)) {
eip = KSTK_EIP(task);
esp = KSTK_ESP(task);
Powered by blists - more mailing lists