1
0
Fork 0
remarkable-linux/ipc
Kirill A. Shutemov 5d0e8394db ipc/shm: handle removed segments gracefully in shm_mmap()
[ Upstream commit 15db15e2f10ae12d021c9a2e9edd8a03b9238551 ]

commit 1ac0b6dec6 upstream.

remap_file_pages(2) emulation can reach file which represents removed
IPC ID as long as a memory segment is mapped.  It breaks expectations of
IPC subsystem.

Test case (rewritten to be more human readable, originally autogenerated
by syzkaller[1]):

	#define _GNU_SOURCE
	#include <stdlib.h>
	#include <sys/ipc.h>
	#include <sys/mman.h>
	#include <sys/shm.h>

	#define PAGE_SIZE 4096

	int main()
	{
		int id;
		void *p;

		id = shmget(IPC_PRIVATE, 3 * PAGE_SIZE, 0);
		p = shmat(id, NULL, 0);
		shmctl(id, IPC_RMID, NULL);
		remap_file_pages(p, 3 * PAGE_SIZE, 0, 7, 0);

	        return 0;
	}

The patch changes shm_mmap() and code around shm_lock() to propagate
locking error back to caller of shm_mmap().

[1] http://github.com/google/syzkaller

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Manfred Spraul <manfred@colorfullife.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
2016-03-04 10:25:45 -05:00
..
Makefile ipc/msg: increase MSGMNI, remove scaling 2014-12-13 12:42:52 -08:00
compat.c ipc: resolve shadow warnings 2014-10-14 02:18:23 +02:00
compat_mq.c ipc, kernel: use Linux headers 2014-06-06 16:08:14 -07:00
ipc_sysctl.c ipc/msg: increase MSGMNI, remove scaling 2014-12-13 12:42:52 -08:00
mq_sysctl.c ipc: convert use of typedef ctl_table to struct ctl_table 2014-06-06 16:08:16 -07:00
mqueue.c ipc: modify message queue accounting to not take kernel data structures into account 2015-08-16 20:52:22 -07:00
msg.c Initialize msg/shm IPC objects before doing ipc_addid() 2015-10-22 14:43:20 -07:00
msgutil.c ipc: convert invalid scenarios to use WARN_ON 2016-03-04 10:25:45 -05:00
namespace.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2014-12-16 15:53:03 -08:00
sem.c ipc/sem.c: update/correct memory barriers 2015-09-13 09:07:38 -07:00
shm.c ipc/shm: handle removed segments gracefully in shm_mmap() 2016-03-04 10:25:45 -05:00
syscall.c get rid of union semop in sys_semctl(2) arguments 2013-03-05 15:14:16 -05:00
util.c Initialize msg/shm IPC objects before doing ipc_addid() 2015-10-22 14:43:20 -07:00
util.h ipc, kernel: clear whitespace 2014-06-06 16:08:14 -07:00