mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 02:32:09 -04:00
fs/proc, core/debug: Don't expose absolute kernel addresses via wchan
So the /proc/PID/stat 'wchan' field (the 30th field, which contains
the absolute kernel address of the kernel function a task is blocked in)
leaks absolute kernel addresses to unprivileged user-space:
seq_put_decimal_ull(m, ' ', wchan);
The absolute address might also leak via /proc/PID/wchan as well, if
KALLSYMS is turned off or if the symbol lookup fails for some reason:
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;
}
This isn't ideal, because 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
There's one compatibility quirk here: procps relies on whether the
absolute value is non-zero - and we can provide that functionality
by outputing "0" or "1" depending on whether the task is blocked
(whether there's a wchan address).
These days there appears to be 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.
So this patch sets all numeric output to "0" or "1" and keeps only
symbolic output, in /proc/PID/wchan.
( The absolute sleep address can generally still be profiled via
perf, by tasks with sufficient privileges. )
Reviewed-by: Thomas Gleixner <[email protected]>
Acked-by: Kees Cook <[email protected]>
Acked-by: Linus Torvalds <[email protected]>
Cc: <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Alexander Potapenko <[email protected]>
Cc: Andrey Konovalov <[email protected]>
Cc: Andrey Ryabinin <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Denys Vlasenko <[email protected]>
Cc: Dmitry Vyukov <[email protected]>
Cc: Kostya Serebryany <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Sasha Levin <[email protected]>
Cc: kasan-dev <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
This commit is contained in:
parent
3225031fbe
commit
b2f73922d1
3 changed files with 20 additions and 10 deletions
|
|
@ -375,7 +375,7 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
|
|||
static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
|
||||
struct pid *pid, struct task_struct *task, int whole)
|
||||
{
|
||||
unsigned long vsize, eip, esp, wchan = ~0UL;
|
||||
unsigned long vsize, eip, esp, wchan = 0;
|
||||
int priority, nice;
|
||||
int tty_pgrp = -1, tty_nr = 0;
|
||||
sigset_t sigign, sigcatch;
|
||||
|
|
@ -507,7 +507,19 @@ 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);
|
||||
|
||||
/*
|
||||
* We used to output the absolute kernel address, but that's an
|
||||
* information leak - so instead we show a 0/1 flag here, to signal
|
||||
* to user-space whether there's a wchan field in /proc/PID/wchan.
|
||||
*
|
||||
* This works with older implementations of procps as well.
|
||||
*/
|
||||
if (wchan)
|
||||
seq_puts(m, " 1");
|
||||
else
|
||||
seq_puts(m, " 0");
|
||||
|
||||
seq_put_decimal_ull(m, ' ', 0);
|
||||
seq_put_decimal_ull(m, ' ', 0);
|
||||
seq_put_decimal_ll(m, ' ', task->exit_signal);
|
||||
|
|
|
|||
|
|
@ -430,13 +430,10 @@ 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 (wchan && ptrace_may_access(task, PTRACE_MODE_READ) && !lookup_symbol_name(wchan, symname))
|
||||
seq_printf(m, "%s", symname);
|
||||
}
|
||||
else
|
||||
seq_putc(m, '0');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue