From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756066AbbJAKQZ (ORCPT ); Thu, 1 Oct 2015 06:16:25 -0400 Received: from mail-la0-f44.google.com ([209.85.215.44]:36286 "EHLO mail-la0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751839AbbJAKQV (ORCPT ); Thu, 1 Oct 2015 06:16:21 -0400 Subject: Re: [PATCH v3] fs/proc, core/debug: Don't expose absolute kernel addresses via wchan To: Ingo Molnar References: <20150930071537.GA19048@gmail.com> <20150930135917.GA3285@gmail.com> <20151001075715.GA23430@gmail.com> <20151001092914.GC6543@gmail.com> Cc: Kees Cook , Thomas Gleixner , Andy Lutomirski , Dmitry Vyukov , Ingo Molnar , "H. Peter Anvin" , Andy Lutomirski , Borislav Petkov , Denys Vlasenko , "x86@kernel.org" , LKML , Kostya Serebryany , Alexander Potapenko , Andrey Konovalov , Sasha Levin , Andi Kleen , kasan-dev , Linus Torvalds , Peter Zijlstra , Andrew Morton , Al Viro From: Andrey Ryabinin Message-ID: <560D07FC.2000705@gmail.com> Date: Thu, 1 Oct 2015 13:16:28 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <20151001092914.GC6543@gmail.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/01/2015 12:29 PM, Ingo Molnar wrote: > > * Andrey Ryabinin wrote: > >> 2015-10-01 10:57 GMT+03:00 Ingo Molnar : >>> diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt >>> index d411ca63c8b6..db64f7d6492d 100644 >>> --- a/Documentation/filesystems/proc.txt >>> +++ b/Documentation/filesystems/proc.txt >>> @@ -140,7 +140,8 @@ Table 1-1: Process specific entries in /proc >>> stat Process status >>> statm Process memory status information >>> status Process status in human readable form >>> - wchan If CONFIG_KALLSYMS is set, a pre-decoded wchan >>> + wchan If CONFIG_KALLSYMS=y, wchan (the kernel function the process is >>> + blocked in) symbol string. "0" if not blocked or !KALLSYMS. >> >> /proc/PID/wchan is under #ifdef CONFIG_KALLSYMS. > > Yeah, indeed, so I clarified that text to now read: > > + wchan Present with CONFIG_KALLSYMS=y: it shows the kernel function > + symbol the task is blocked in - or "0" if not blocked. > >>> diff --git a/fs/proc/base.c b/fs/proc/base.c >>> index b25eee4cead5..6f05aabce3aa 100644 >>> --- a/fs/proc/base.c >>> +++ b/fs/proc/base.c >>> @@ -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 (!lookup_symbol_name(wchan, symname)) >>> seq_printf(m, "%s", symname); >>> - } >>> + else >>> + seq_putc(m, '0'); >> >> Maybe we should respect 'kptr_restrict' sysctl when we use '%ps', '%pB' etc. >> printk formats (AFAIK %ps just prints address if KALLSYMS=n, or lookup failed). >> In that case you could just do 'seq_printf(m, "%ps", wchan)'. >> >> OTOH, %ps, %pS are used mostly in debugging, so investigating some crash in >> production kernel with no !KALLSYMS and with kptr_restrict != 0 will be a >> nightmare. > > So this code does not use %pX, it prints the symbol. I think you misunderstood me. Yes, this code currently doesn't use %pX, but it could: diff --git a/fs/proc/base.c b/fs/proc/base.c index b25eee4..f58f66e 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -425,18 +425,7 @@ static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns, 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); - } + seq_printf(m, "%ps", get_wchan(task)); return 0; } There is a problem here, though. %ps will print absolute kernel address instead of symbol name if KALLSYMS=n or if resolution of address failed. So I was wondering, may be should just fix %ps ? i.e. print 0 instead of absolute address if KALLSYMS=n or lookup failure? > Yes, the symbol in itself is > 'information' about the execution of the task in itself - but /proc per se is all > about providing information about tasks in the system (including to unprivileged > users), so there's IMHO little point in restricting this output any further ... > > I think ktrp_restrict is mostly about not exposing absolute addresses. > Right, and '%ps' may expose absolute address if KALLSYMS=n or address lookup failed for some reason. > Thanks, > > Ingo >