From: Ingo Molnar <mingo@kernel.org>
To: Andy Lutomirski <luto@amacapital.net>, Kees Cook <keescook@chromium.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Dmitry Vyukov <dvyukov@google.com>,
Andrey Ryabinin <ryabinin.a.a@gmail.com>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
Andy Lutomirski <luto@kernel.org>, Borislav Petkov <bp@alien8.de>,
Denys Vlasenko <dvlasenk@redhat.com>,
"x86@kernel.org" <x86@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Kostya Serebryany <kcc@google.com>,
Alexander Potapenko <glider@google.com>,
Andrey Konovalov <andreyknvl@google.com>,
Sasha Levin <sasha.levin@oracle.com>,
Andi Kleen <ak@linux.intel.com>,
kasan-dev <kasan-dev@googlegroups.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Andrew Morton <akpm@linux-foundation.org>,
Kees Cook <keescook@chromium.org>,
Al Viro <viro@zeniv.linux.org.uk>
Subject: [PATCH] fs/proc: Don't expose absolute kernel addresses via wchan
Date: Wed, 30 Sep 2015 09:15:37 +0200 [thread overview]
Message-ID: <20150930071537.GA19048@gmail.com> (raw)
In-Reply-To: <CALCETrWWsFB+aWKhadoaftNNjU=gRa15+7PXOR=3yrVzXuar6w@mail.gmail.com>
* Andy Lutomirski <luto@amacapital.net> wrote:
> > + * ----------- bottom = start + sizeof(thread_info)
> > + * thread_info
> > + * ----------- start
> > + *
> > + * The tasks stack pointer points at the location where the
> > + * framepointer is stored. The data on the stack is:
> > + * ... IP FP ... IP FP
> > + *
> > + * We need to read FP and IP, so we need to adjust the upper
> > + * bound by another unsigned long.
> > + */
> > + top = start + THREAD_SIZE - 2 * sizeof(unsigned long);
> > + bottom = start + sizeof(struct thread_info);
> > +
> > + sp = p->thread.sp;
> > + if (sp < bottom || sp > top)
> > + return 0;
> > +
> > + fp = *(unsigned long *)sp;
> > do {
> > - if (fp < (unsigned long)stack ||
> > - fp >= (unsigned long)stack+THREAD_SIZE)
> > + if (fp < bottom || fp > top)
> > return 0;
> > - ip = *(u64 *)(fp+8);
> > + ip = *(unsigned long *)(fp + sizeof(unsigned long));
> > if (!in_sched_functions(ip))
> > return ip;
> > - fp = *(u64 *)fp;
> > + fp = *(unsigned long *)fp;
> > } while (count++ < 16);
>
> I'm be vaguely amazed if this isn't an exploitable info leak even
> without the out of bounds thing. Can we really not find a way to do
> this without walking the stack?
So wchan leaks absolute kernel addresses to unprivileged user-space, of kernel
functions that sleep:
static int proc_pid_wchan(struct seq_file *m, struct pid_namespace *ns,
struct pid *pid, struct task_struct *task)
{
unsigned long wchan;
char symname[KSYM_NAME_LEN];
wchan = get_wchan(task);
if (lookup_symbol_name(wchan, symname) < 0) {
if (!ptrace_may_access(task, PTRACE_MODE_READ))
return 0;
seq_printf(m, "%lu", wchan);
} else {
seq_printf(m, "%s", symname);
}
return 0;
}
So for example it trivially leaks the KASLR offset to any local attacker:
fomalhaut:~> printf "%016lx\n" $(cat /proc/$$/stat | cut -d' ' -f35)
ffffffff8123b380
Most real-life uses of wchan are symbolic:
ps -eo pid:10,tid:10,wchan:30,comm
and procps uses /proc/PID/wchan, not the absolute address in /proc/PID/stat:
triton:~/tip> strace -f ps -eo pid:10,tid:10,wchan:30,comm 2>&1 | grep wchan | tail -1
open("/proc/30833/wchan", O_RDONLY) = 6
So shouldn't we try to set all numeric output to 0 and only allow symbolic output
via /proc/PID/wchan?
These days there's very little legitimate reason user-space would be interested in
the absolute address. The absolute address is mostly historic: from the days when
we didn't have kallsyms and user-space procps had to do the decoding itself via
the System.map.
( The absolute sleep address can generally still be profiled via perf, by tasks
with sufficient privileges. )
I.e. how about something like the patch below? (completely untested.)
Thanks,
Ingo
======================>
fs/proc/array.c | 2 +-
fs/proc/base.c | 7 +------
2 files changed, 2 insertions(+), 7 deletions(-)
diff --git a/fs/proc/array.c b/fs/proc/array.c
index f60f0121e331..99082730b2ac 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -507,7 +507,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
seq_put_decimal_ull(m, ' ', task->blocked.sig[0] & 0x7fffffffUL);
seq_put_decimal_ull(m, ' ', sigign.sig[0] & 0x7fffffffUL);
seq_put_decimal_ull(m, ' ', sigcatch.sig[0] & 0x7fffffffUL);
- seq_put_decimal_ull(m, ' ', wchan);
+ seq_puts(m, " 0"); /* Used to be numeric wchan - replaced by /proc/PID/wchan */
seq_put_decimal_ull(m, ' ', 0);
seq_put_decimal_ull(m, ' ', 0);
seq_put_decimal_ll(m, ' ', task->exit_signal);
diff --git a/fs/proc/base.c b/fs/proc/base.c
index b25eee4cead5..2fdbf303e3eb 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -430,13 +430,8 @@ static int proc_pid_wchan(struct seq_file *m, struct pid_namespace *ns,
wchan = get_wchan(task);
- if (lookup_symbol_name(wchan, symname) < 0) {
- if (!ptrace_may_access(task, PTRACE_MODE_READ))
- return 0;
- seq_printf(m, "%lu", wchan);
- } else {
+ if (!lookup_symbol_name(wchan, symname))
seq_printf(m, "%s", symname);
- }
return 0;
}
next prev parent reply other threads:[~2015-09-30 7:15 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-28 9:00 [PATCH] arch/x86: fix out-of-bounds in get_wchan() Dmitry Vyukov
2015-09-28 9:37 ` Borislav Petkov
2015-09-28 9:49 ` Dmitry Vyukov
2015-09-28 10:23 ` Borislav Petkov
2015-09-28 10:33 ` Dmitry Vyukov
2015-09-28 10:51 ` Borislav Petkov
2015-09-28 9:54 ` Dmitry Vyukov
2015-09-28 10:32 ` Borislav Petkov
2015-09-28 15:40 ` Andrey Ryabinin
2015-09-28 16:08 ` Dmitry Vyukov
2015-09-28 16:32 ` Thomas Gleixner
2015-09-29 18:15 ` Andy Lutomirski
2015-09-29 18:30 ` Andy Lutomirski
2015-09-29 18:41 ` Borislav Petkov
2015-09-30 7:15 ` Ingo Molnar [this message]
2015-09-30 7:35 ` [PATCH] fs/proc: Don't expose absolute kernel addresses via wchan Thomas Gleixner
2015-09-30 13:59 ` [PATCH v2] " Ingo Molnar
2015-09-30 20:36 ` Thomas Gleixner
2015-09-30 21:21 ` Kees Cook
2015-09-30 21:38 ` Thomas Gleixner
2015-10-01 7:57 ` [PATCH v3] fs/proc, core/debug: " Ingo Molnar
2015-10-01 8:57 ` Andrey Ryabinin
2015-10-01 9:29 ` Ingo Molnar
2015-10-01 10:16 ` Andrey Ryabinin
2015-10-01 10:39 ` Ingo Molnar
2015-10-01 10:47 ` Andrey Ryabinin
2015-10-01 10:57 ` [PATCH v5] " Ingo Molnar
2015-10-01 9:37 ` [PATCH v4] " Ingo Molnar
2015-10-01 12:49 ` [tip:core/debug] fs/proc, core/debug: Don' t " tip-bot for Ingo Molnar
2015-09-30 8:07 ` [PATCH] arch/x86: fix out-of-bounds in get_wchan() Thomas Gleixner
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=20150930071537.GA19048@gmail.com \
--to=mingo@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@google.com \
--cc=bp@alien8.de \
--cc=dvlasenk@redhat.com \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=hpa@zytor.com \
--cc=kasan-dev@googlegroups.com \
--cc=kcc@google.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=ryabinin.a.a@gmail.com \
--cc=sasha.levin@oracle.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
--cc=x86@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;
as well as URLs for NNTP newsgroup(s).