linux-imx/ipc
Davidlohr Bueso afa870b96a ipc/shm: Fix shmat mmap nil-page protection
commit 95e91b831f upstream.

The issue is described here, with a nice testcase:

    https://bugzilla.kernel.org/show_bug.cgi?id=192931

The problem is that shmat() calls do_mmap_pgoff() with MAP_FIXED, and
the address rounded down to 0.  For the regular mmap case, the
protection mentioned above is that the kernel gets to generate the
address -- arch_get_unmapped_area() will always check for MAP_FIXED and
return that address.  So by the time we do security_mmap_addr(0) things
get funky for shmat().

The testcase itself shows that while a regular user crashes, root will
not have a problem attaching a nil-page.  There are two possible fixes
to this.  The first, and which this patch does, is to simply allow root
to crash as well -- this is also regular mmap behavior, ie when hacking
up the testcase and adding mmap(...  |MAP_FIXED).  While this approach
is the safer option, the second alternative is to ignore SHM_RND if the
rounded address is 0, thus only having MAP_SHARED flags.  This makes the
behavior of shmat() identical to the mmap() case.  The downside of this
is obviously user visible, but does make sense in that it maintains
semantics after the round-down wrt 0 address and mmap.

Passes shm related ltp tests.

Link: http://lkml.kernel.org/r/1486050195-18629-1-git-send-email-dave@stgolabs.net
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Reported-by: Gareth Evans <gareth.evans@contextis.co.uk>
Cc: Manfred Spraul <manfred@colorfullife.com>
Cc: Michael Kerrisk <mtk.manpages@googlemail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
2017-03-13 21:40:24 +01:00
..
compat_mq.c ipc: initialize structure memory to zero for compat functions 2010-10-27 18:03:13 -07:00
compat.c ipc/compat_sys_msgrcv: change msgtyp type from long to compat_long_t 2015-02-02 15:59:30 +01:00
ipc_sysctl.c ipc: always handle a new value of auto_msgmni 2014-11-19 18:38:25 +01:00
ipcns_notifier.c ipc: do not use a negative value to re-enable msgmni automatic recomputing 2008-07-25 10:53:42 -07:00
Makefile Add generic sys_ipc wrapper 2010-03-12 15:52:32 -08:00
mq_sysctl.c ipc,mqueue: remove limits for the amount of system-wide queues 2014-03-05 17:13:53 +01:00
mqueue.c ipc: modify message queue accounting to not take kernel data structures into account 2015-08-25 16:56:55 +02:00
msg.c ipc: remove use of seq_printf return value 2016-10-28 19:03:56 +02:00
msgutil.c ipc, msg: fix message length check for negative values 2013-12-04 11:05:22 -08:00
namespace.c ipc: drop ipc_lock_by_ptr 2013-09-11 15:59:44 -07:00
sem.c ipc/sem.c: fix complex_count vs. simple op race 2016-11-08 16:38:11 +01:00
shm.c ipc/shm: Fix shmat mmap nil-page protection 2017-03-13 21:40:24 +01:00
syscall.c get rid of union semop in sys_semctl(2) arguments 2013-03-05 15:14:16 -05:00
util.c ipc: remove use of seq_printf return value 2016-10-28 19:03:56 +02:00
util.h ipc, msg: fix message length check for negative values 2013-12-04 11:05:22 -08:00