remarkable-linux/fs/proc
Djalal Harouni e8905ec27e proc: environ_read() make sure offset points to environment address range
Currently the following offset and environment address range check in
environ_read() of /proc/<pid>/environ is buggy:

  int this_len = mm->env_end - (mm->env_start + src);
  if (this_len <= 0)
    break;

Large or negative offsets on /proc/<pid>/environ converted to 'unsigned
long' may pass this check since '(mm->env_start + src)' can overflow and
'this_len' will be positive.

This can turn /proc/<pid>/environ to act like /proc/<pid>/mem since
(mm->env_start + src) will point and read from another VMA.

There are two fixes here plus some code cleaning:

1) Fix the overflow by checking if the offset that was converted to
   unsigned long will always point to the [mm->env_start, mm->env_end]
   address range.

2) Remove the truncation that was made to the result of the check,
   storing the result in 'int this_len' will alter its value and we can
   not depend on it.

For kernels that have commit b409e578d ("proc: clean up
/proc/<pid>/environ handling") which adds the appropriate ptrace check and
saves the 'mm' at ->open() time, this is not a security issue.

This patch is taken from the grsecurity patch since it was just made
available.

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Brad Spengler <spender@grsecurity.net>
Acked-by: Kees Cook <keescook@chromium.org>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-07-30 17:25:20 -07:00
..
array.c c/r: procfs: add arg_start/end, env_start/end and exit_code members to /proc/$pid/stat 2012-05-31 17:49:32 -07:00
base.c proc: environ_read() make sure offset points to environment address range 2012-07-30 17:25:20 -07:00
cmdline.c
consoles.c console: rename acquire/release_console_sem() to console_lock/unlock() 2011-01-26 10:50:06 +10:00
cpuinfo.c
devices.c proc: use seq_puts()/seq_putc() where possible 2011-01-13 08:03:16 -08:00
generic.c stop passing nameidata to ->lookup() 2012-07-14 16:34:32 +04:00
inode.c avoid iput() from flusher thread 2012-05-28 09:54:45 -07:00
internal.h stop passing nameidata to ->lookup() 2012-07-14 16:34:32 +04:00
interrupts.c
Kconfig kconfig: rename CONFIG_EMBEDDED to CONFIG_EXPERT 2011-01-20 17:02:05 -08:00
kcore.c fs/proc/kcore.c: make get_sparsemem_vmemmap_info() static 2012-03-23 16:58:42 -07:00
kmsg.c
loadavg.c
Makefile ns: proc files for namespace naming policy. 2011-05-10 14:31:44 -07:00
meminfo.c fs/proc/meminfo.c: fix compilation error 2011-12-09 07:50:28 -08:00
mmu.c
namespaces.c stop passing nameidata to ->lookup() 2012-07-14 16:34:32 +04:00
nommu.c
page.c pagemap: export KPF_THP 2012-03-21 17:54:57 -07:00
proc_devtree.c of: Improve prom_update_property() function 2012-07-11 15:26:51 +10:00
proc_net.c stop passing nameidata to ->lookup() 2012-07-14 16:34:32 +04:00
proc_sysctl.c stop passing nameidata to ->lookup() 2012-07-14 16:34:32 +04:00
proc_tty.c proc: use seq_puts()/seq_putc() where possible 2011-01-13 08:03:16 -08:00
root.c VFS: Pass mount flags to sget() 2012-07-14 16:38:34 +04:00
softirqs.c proc: use seq_puts()/seq_putc() where possible 2011-01-13 08:03:16 -08:00
stat.c proc: stats: Use arch_idle_time for idle and iowait times if available 2012-03-30 15:43:33 +02:00
task_mmu.c proc/smaps: show amount of nonlinear ptes in vma 2012-05-31 17:49:29 -07:00
task_nommu.c proc: remove mm_for_maps() 2012-05-31 17:49:28 -07:00
uptime.c Merge branch 'sched/core' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip into cputime-tip 2011-12-19 19:23:15 +01:00
version.c
vmcore.c fadump: Introduce cleanup routine to invalidate /proc/vmcore. 2012-02-23 10:50:02 +11:00