From: Oleg Nesterov <oleg@redhat.com>
To: Kees Cook <keescook@chromium.org>
Cc: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
"Serge E. Hallyn" <serge@hallyn.com>,
syzbot <syzbot+a9ac39bf55329e206219@syzkaller.appspotmail.com>,
James Morris <jmorris@namei.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-security-module <linux-security-module@vger.kernel.org>,
syzkaller-bugs@googlegroups.com
Subject: Re: KASAN: use-after-free Read in task_is_descendant
Date: Mon, 29 Oct 2018 13:23:56 +0100 [thread overview]
Message-ID: <20181029122356.GA29883@redhat.com> (raw)
In-Reply-To: <CAGXu5jJDkt0vR28Rzhi2gmb=9S7BwWkiMuVrN98AOABgngYY4A@mail.gmail.com>
On 10/26, Kees Cook wrote:
>
> On Thu, Oct 25, 2018 at 2:01 PM, Oleg Nesterov <oleg@redhat.com> wrote:
> > On 10/25, Oleg Nesterov wrote:
> >> perhaps it needs some changes too. I even have a vague feeling that I have already
> >> blamed this function some time ago...
> >
> > Heh, yes, 3 years ago ;)
> >
> > https://lore.kernel.org/lkml/20150106184427.GA18153@redhat.com/
> >
> > I can't understand my email today, but note that I tried to point out that
> > task_is_descendant() can dereference the freed mem.
>
> Instead of:
>
> while (walker->pid > 0) {
>
> should it simply be "while (pid_liave(walker)) {"?
No, this would be wrong. Probably walker->pid > 0 is not the best check,
but we do not need to change it for correctness.
> And add a
> pid_alive(parent) after rcu_read_lock()?
So you too do not read my emails ;)
I still think we need a single pid_alive() check and I even sent the patch.
Attached again at the end.
To clarify, let me repeat that ptracer_exception_found() may need some fixes
too, right now I am only talking about task_is_descendant().
> > And yes, task_is_descendant() is overcompicated for no reason, afaics.
>
> Yeah, agreed. I'll fix this up.
I have already posted this code, this is what I think it should do.
static int task_is_descendant(struct task_struct *parent,
struct task_struct *child)
{
struct task_struct *walker;
for (walker = child; walker->pid; walker = rcu_dereference(walker->real_parent)) {
if (same_thread_group(parent, walker))
return 1;
}
return 0;
}
This version differs in that I removed the parent/child != NULL at the start
and rcu_read_lock(), it should be held by the caller anyway.
> Just to make sure I'm not crazy: the
> real_parent of all tasks in a thread group are the same, yes?
Well, yes and no. So if
same_thread_group(t1, t2) == T
then
same_thread_group(t1->real_parent, t2->real_parent) == T
which means that real_parent of all tasks in a thread group is the same
_process_.
But t1->real_parent and t2->real_parent are not necessarily the same task.
Oleg.
--- x/security/yama/yama_lsm.c
+++ x/security/yama/yama_lsm.c
@@ -368,7 +368,8 @@ static int yama_ptrace_access_check(stru
break;
case YAMA_SCOPE_RELATIONAL:
rcu_read_lock();
- if (!task_is_descendant(current, child) &&
+ if (!pid_alive(child) ||
+ !task_is_descendant(current, child) &&
!ptracer_exception_found(current, child) &&
!ns_capable(__task_cred(child)->user_ns, CAP_SYS_PTRACE))
rc = -EPERM;
next prev parent reply other threads:[~2018-10-29 12:24 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-21 7:10 KASAN: use-after-free Read in task_is_descendant syzbot
2018-10-21 7:12 ` Tetsuo Handa
2018-10-22 9:54 ` Oleg Nesterov
2018-10-22 10:06 ` Tetsuo Handa
2018-10-22 13:46 ` Oleg Nesterov
2018-10-25 2:15 ` Tetsuo Handa
2018-10-25 11:13 ` Oleg Nesterov
2018-10-25 11:36 ` Kees Cook
2018-10-25 12:05 ` Oleg Nesterov
2018-10-25 11:47 ` Tetsuo Handa
2018-10-25 12:17 ` Oleg Nesterov
2018-10-25 13:01 ` Oleg Nesterov
2018-10-26 16:09 ` Kees Cook
2018-10-29 12:23 ` Oleg Nesterov [this message]
2018-10-29 15:05 ` yama: unsafe usage of ptrace_relation->tracer Oleg Nesterov
2019-01-10 11:05 ` Tetsuo Handa
2019-01-10 18:47 ` Kees Cook
2019-01-16 17:40 ` Oleg Nesterov
2018-10-25 13:14 ` KASAN: use-after-free Read in task_is_descendant Tetsuo Handa
2018-10-25 15:55 ` Oleg Nesterov
2018-10-25 16:25 ` Oleg Nesterov
2018-10-26 12:23 ` Tetsuo Handa
2018-10-26 13:04 ` Oleg Nesterov
2018-10-26 13:51 ` Tetsuo Handa
2018-10-26 14:39 ` Oleg Nesterov
2018-10-26 15:04 ` Tetsuo Handa
2018-10-26 15:22 ` Oleg Nesterov
2018-10-25 8:19 ` Kees Cook
2018-10-25 11:52 ` Oleg Nesterov
2018-11-10 3:25 ` syzbot
2018-11-10 11:46 ` syzbot
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=20181029122356.GA29883@redhat.com \
--to=oleg@redhat.com \
--cc=jmorris@namei.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=penguin-kernel@i-love.sakura.ne.jp \
--cc=serge@hallyn.com \
--cc=syzbot+a9ac39bf55329e206219@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
/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).