1
0
Fork 0
remarkable-linux/fs/proc
Mathias Krause 93c4863f44 proc: prevent accessing /proc/<PID>/environ until it's ready
[ Upstream commit 8148a73c99 ]

If /proc/<PID>/environ gets read before the envp[] array is fully set up
in create_{aout,elf,elf_fdpic,flat}_tables(), we might end up trying to
read more bytes than are actually written, as env_start will already be
set but env_end will still be zero, making the range calculation
underflow, allowing to read beyond the end of what has been written.

Fix this as it is done for /proc/<PID>/cmdline by testing env_end for
zero.  It is, apparently, intentionally set last in create_*_tables().

This bug was found by the PaX size_overflow plugin that detected the
arithmetic underflow of 'this_len = env_end - (env_start + src)' when
env_end is still zero.

The expected consequence is that userland trying to access
/proc/<PID>/environ of a not yet fully set up process may get
inconsistent data as we're in the middle of copying in the environment
variables.

Fixes: https://forums.grsecurity.net/viewtopic.php?f=3&t=4363
Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=116461
Signed-off-by: Mathias Krause <minipli@googlemail.com>
Cc: Emese Revfy <re.emese@gmail.com>
Cc: Pax Team <pageexec@freemail.hu>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Mateusz Guzik <mguzik@redhat.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Jarod Wilson <jarod@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
2016-07-10 23:07:18 -04:00
..
Kconfig kcore: add Kconfig help text 2013-11-13 12:09:33 +09:00
Makefile proc: Implement /proc/thread-self to point at the directory of the current thread 2014-08-04 10:07:11 -07:00
array.c ptrace: use fsuid, fsgid, effective creds for fs access checks 2016-04-11 22:07:35 -04:00
base.c proc: prevent accessing /proc/<PID>/environ until it's ready 2016-07-10 23:07:18 -04:00
cmdline.c fs/proc: don't use module_init for non-modular core code 2014-01-23 16:37:02 -08:00
consoles.c fs/proc: don't use module_init for non-modular core code 2014-01-23 16:37:02 -08:00
cpuinfo.c fs/proc: don't use module_init for non-modular core code 2014-01-23 16:37:02 -08:00
devices.c fs/proc: don't use module_init for non-modular core code 2014-01-23 16:37:02 -08:00
fd.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2015-04-26 17:22:07 -07:00
fd.h proc: Move proc_fd() to fs/proc/fd.h 2013-05-01 17:29:39 -04:00
generic.c proc: Allow creating permanently empty directories that serve as mount points 2015-07-21 10:10:00 -07:00
inode.c proc: Allow creating permanently empty directories that serve as mount points 2015-07-21 10:10:00 -07:00
internal.h proc: Allow creating permanently empty directories that serve as mount points 2015-07-21 10:10:00 -07:00
interrupts.c fs/proc: don't use module_init for non-modular core code 2014-01-23 16:37:02 -08:00
kcore.c fs/proc/kcore.c: don't add modules range to kcore if it's equal to vmcore range 2014-10-09 22:25:50 -04:00
kmsg.c fs/proc: don't use module_init for non-modular core code 2014-01-23 16:37:02 -08:00
loadavg.c fs/proc: don't use module_init for non-modular core code 2014-01-23 16:37:02 -08:00
meminfo.c fs/proc/meminfo.c: include cma info in proc/meminfo 2014-12-18 19:08:10 -08:00
namespaces.c ptrace: use fsuid, fsgid, effective creds for fs access checks 2016-04-11 22:07:35 -04:00
nommu.c fs/proc: don't use module_init for non-modular core code 2014-01-23 16:37:02 -08:00
page.c mm:add KPF_ZERO_PAGE flag for /proc/kpageflags 2015-02-11 17:06:00 -08:00
proc_net.c VFS: normal filesystems (and lustre): d_inode() annotations 2015-04-15 15:06:57 -04:00
proc_sysctl.c sysctl: Allow creating permanently empty directories that serve as mountpoints. 2015-07-21 10:10:00 -07:00
proc_tty.c proc: remove proc_tty_ldisc variable 2014-08-08 15:57:22 -07:00
root.c proc: prevent stacking filesystems on top 2016-06-18 16:47:32 -04:00
self.c VFS: normal filesystems (and lustre): d_inode() annotations 2015-04-15 15:06:57 -04:00
softirqs.c fs/proc: don't use module_init for non-modular core code 2014-01-23 16:37:02 -08:00
stat.c genirq: Prevent proc race against freeing of irq descriptors 2014-12-13 13:33:07 +01:00
task_mmu.c pagemap: do not leak physical addresses to non-privileged userspace 2015-03-17 09:31:30 -07:00
task_nommu.c proc/maps: make vm_is_stack() logic namespace-friendly 2014-10-09 22:25:50 -04:00
thread_self.c VFS: normal filesystems (and lustre): d_inode() annotations 2015-04-15 15:06:57 -04:00
uptime.c cputime: Default implementation of nsecs -> cputime conversion 2014-03-13 15:56:43 +01:00
version.c fs/proc: don't use module_init for non-modular core code 2014-01-23 16:37:02 -08:00
vmcore.c vmcore: fix PT_NOTE n_namesz, n_descsz overflow issue 2015-02-17 14:34:52 -08:00