linux-hardened/Documentation/filesystems
Ingo Molnar b2f73922d1 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 <tglx@linutronix.de>
Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: <stable@vger.kernel.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Kostya Serebryany <kcc@google.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: kasan-dev <kasan-dev@googlegroups.com>
Cc: linux-kernel@vger.kernel.org
Link: http://lkml.kernel.org/r/20150930135917.GA3285@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-10-01 12:55:34 +02:00
..
caching FS-Cache: Count the number of initialised operations 2015-04-02 14:28:53 +01:00
cifs update CIFS TODO list 2014-08-02 01:26:07 -05:00
configfs configfs: convert to umode_t 2012-01-03 22:54:57 -05:00
nfs Revert "Documentation: NFS/RDMA: Document separate Kconfig symbols" 2015-07-20 14:58:46 -04:00
pohmelfs Documentation: Fix multiple typo in Documentation 2012-03-07 16:08:24 +01:00
.gitignore Documentation: update .gitignore files 2014-09-26 11:02:59 +02:00
00-INDEX dax: replace XIP documentation with DAX documentation 2015-02-16 17:56:03 -08:00
9p.txt 9p: update documentation 2014-01-24 10:55:21 -06:00
adfs.txt adfs: add hexadecimal filetype suffix option 2011-03-22 17:44:17 -07:00
affs.txt affs: add mount option to avoid filename truncates 2014-04-07 16:36:08 -07:00
afs.txt
autofs4-mount-control.txt doc: fix double words 2014-03-21 13:16:58 +01:00
autofs4.txt autofs: the documentation I wanted to read 2014-10-14 02:18:17 +02:00
automount-support.txt Documentation: remove outdated information from automount-support.txt 2015-05-15 01:10:38 -04:00
befs.txt Documentation: befs.txt: no maintainer, orphaned 2011-08-13 18:34:03 -07:00
bfs.txt
btrfs.txt Documentation: filesystems: btrfs: Fixed typos and whitespace 2015-07-09 14:31:06 -06:00
ceph.txt ceph: enable/disable dentry complete flags via mount option 2012-01-12 11:00:40 -08:00
coda.txt
cramfs.txt
dax.txt dax: add huge page fault support 2015-09-08 15:35:28 -07:00
debugfs.txt Documentation: Update filesystems/debugfs.txt 2015-07-24 15:05:56 +02:00
devpts.txt
directory-locking vfs: take i_mutex on renamed file 2013-11-09 00:16:40 -05:00
dlmfs.txt ocfs2: update web page + git tree in documentation 2015-02-28 09:57:50 -08:00
dnotify.txt
dnotify_test.c
ecryptfs.txt
efivarfs.txt efivarfs: Add documentation for the EFI variable filesystem 2012-10-30 10:39:18 +00:00
exofs.txt exofs: Add option to mount by osdname 2011-03-15 15:02:51 +02:00
ext2.txt fs: Remove ext3 filesystem driver 2015-07-23 20:59:40 +02:00
ext3.txt fs: Remove ext3 filesystem driver 2015-07-23 20:59:40 +02:00
ext4.txt ext4: add DAX functionality 2015-02-16 17:56:04 -08:00
f2fs.txt f2fs: add noextent_cache mount option 2015-08-04 14:09:55 -07:00
fiemap.txt fsioctl.c: make generic_block_fiemap() signal-tolerant 2015-02-10 14:30:30 -08:00
files.txt Wrap accesses to the fd_sets in struct fdtable 2012-02-19 10:30:52 -08:00
fuse.txt
gfs2-glocks.txt GFS2: Update glock doc to add new stats info 2012-05-10 12:41:40 +01:00
gfs2-uevents.txt Documentation: Fix multiple typo in Documentation 2012-03-07 16:08:24 +01:00
gfs2.txt GFS2: Update main gfs2 doc 2012-05-10 11:45:31 +01:00
hfs.txt Documentation: HFS is orphaned 2011-11-04 12:01:48 -07:00
hfsplus.txt Documentation: update URL to hfsplus Technote 1150 2014-02-20 14:48:51 +01:00
hpfs.txt
inotify.txt inotify: update documentation to reflect code changes 2015-02-10 14:30:28 -08:00
isofs.txt
jfs.txt doc: fix misspellings with 'codespell' tool 2013-05-28 12:02:12 +02:00
Locking pmem, dax: have direct_access use __pmem annotation 2015-08-20 14:07:24 -04:00
locks.txt doc: fix broken references 2011-09-27 18:08:04 +02:00
logfs.txt
Makefile Documentation: add makefiles for more targets 2014-09-26 11:02:56 +02:00
mandatory-locking.txt
ncpfs.txt
nilfs2.txt nilfs2: update project's web site in nilfs2.txt 2014-04-03 16:21:26 -07:00
ntfs.txt NTFS: Remove changelog from Documentation/filesystems/ntfs.txt. 2014-10-16 12:43:57 +01:00
ocfs2.txt ocfs2: update web page + git tree in documentation 2015-02-28 09:57:50 -08:00
omfs.txt
overlayfs.txt ovl: document lower layer ordering 2015-01-08 15:09:15 +01:00
path-lookup.txt Fix common misspellings 2011-03-31 11:26:23 -03:00
porting Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2015-07-04 19:36:06 -07:00
proc.txt fs/proc, core/debug: Don't expose absolute kernel addresses via wchan 2015-10-01 12:55:34 +02:00
qnx6.txt doc: filesystems : Fix typo in Documentations/filesystems 2013-08-20 13:45:56 +02:00
quota.txt quota: Update documentation 2015-05-18 11:23:07 +02:00
ramfs-rootfs-initramfs.txt initmpfs: use initramfs if rootfstype= or root= specified 2013-09-11 15:59:38 -07:00
relay.txt doc: Fix typo in doucmentations 2013-07-25 12:34:15 +02:00
romfs.txt Documentation/filesystems/romfs.txt: fixing link to genromfs 2011-02-17 22:04:46 +01:00
seq_file.txt Documentation: update seq_file 2014-12-29 15:40:18 -07:00
sharedsubtree.txt doc: spelling error changes 2014-05-05 15:32:05 +02:00
spufs.txt
squashfs.txt Squashfs: Add LZ4 compression configuration option 2014-11-27 18:48:44 +00:00
sysfs-pci.txt
sysfs-tagging.txt doc: Fix typo in doucmentations 2013-07-25 12:34:15 +02:00
sysfs.txt sysfs.txt: update show method notes about sprintf/snprintf/scnprintf usage 2015-08-05 15:13:21 -07:00
sysv-fs.txt
tmpfs.txt
ubifs.txt UBIFS: switch self-check knobs to debugfs 2011-07-04 10:54:28 +03:00
udf.txt
ufs.txt
vfat.txt fs/fat/: add support for DOS 1.x formatted volumes 2014-06-06 16:08:10 -07:00
vfs.txt fs: Remove ext3 filesystem driver 2015-07-23 20:59:40 +02:00
xfs-delayed-logging-design.txt Fix common misspellings 2011-03-31 11:26:23 -03:00
xfs-self-describing-metadata.txt xfs: add metadata CRC documentation 2013-04-27 13:27:43 -05:00
xfs.txt xfs: fix kernel version in docs 2015-06-01 07:15:38 +10:00