From: Oleg Nesterov <oleg@redhat.com>
To: chen zhang <chenzhang@kylinos.cn>
Cc: chenzhang_0901@163.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] ptrace: disable single step in __ptrace_unlink for protecting init task
Date: Tue, 25 Oct 2022 12:19:00 +0200 [thread overview]
Message-ID: <20221025101858.GB17158@redhat.com> (raw)
In-Reply-To: <20221025051032.280352-1-chenzhang@kylinos.cn>
On 10/25, chen zhang wrote:
>
> Thanks for your reply. I think kernel should not panic when the
> application has a bug, or a fault operation such as ctrl+c,
a) init is special. If it exits, the kernel panics. This is
by design.
b) debugger can always crash the tracee. In particular if it
exits without ptrace(PTRACE_DETACH) which implies
user_disable_single_step().
> This patch can really prevent kernel panic on
> my x86 machine.
Really? You ignored this part of my previous email,
Not to mention I don't understand how your patch can actually help. If nothing
else,
- debugger does ptrace(PTRACE_SINGLESTEP), this wakes the tracee up
- the tracee enters force_sig_info_to_task(SIGTRAP) after single step
- debugger exits, __ptrace_unlink() clears ptrace/TIF_SINGLESTEP
- force_sig_info_to_task() clears SIGNAL_UNKILLABLE, the traced init
will be killed.
Am I wrong?
Finally,
> --- a/kernel/ptrace.c
> +++ b/kernel/ptrace.c
> @@ -130,6 +130,8 @@ void __ptrace_unlink(struct task_struct *child)
> put_cred(old_cred);
>
> spin_lock(&child->sighand->siglock);
> + if (unlikely(child->signal->flags & SIGNAL_UNKILLABLE))
> + user_disable_single_step(child);
> child->ptrace = 0;
> /*
I don't understnd why do you call user_disable_single_step() with ->siglock
held, but this is minor.
user_disable_single_step(child) assumes that child is stopped and frozen,
see ptrace_freeze_traced(). This is not necessarily true if __ptrace_unlink()
is called by the exiting tracer, so the patch is wrong in any case.
Nack, sorry.
Oleg.
prev parent reply other threads:[~2022-10-25 10:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-25 5:10 chen zhang
2022-10-25 10:19 ` Oleg Nesterov [this message]
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=20221025101858.GB17158@redhat.com \
--to=oleg@redhat.com \
--cc=chenzhang@kylinos.cn \
--cc=chenzhang_0901@163.com \
--cc=linux-kernel@vger.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
all inboxes | Powered by JetHome®