diff options
author | Li Zefan <lizefan@huawei.com> | 2013-05-09 03:08:15 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-05-09 17:22:47 -0400 |
commit | 091d0d55b286c9340201b4ed4470be87fc568228 (patch) | |
tree | 5417ab8864fbabe1a9931f3a9a81355cd3d3ebaa | |
parent | de2657f94acd4f0df44626db7c4d2b71babc8cd3 (diff) |
shm: fix null pointer deref when userspace specifies invalid hugepage size
Dave reported an oops triggered by trinity:
BUG: unable to handle kernel NULL pointer dereference at 0000000000000008
IP: newseg+0x10d/0x390
PGD cf8c1067 PUD cf8c2067 PMD 0
Oops: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC
CPU: 2 PID: 7636 Comm: trinity-child2 Not tainted 3.9.0+#67
...
Call Trace:
ipcget+0x182/0x380
SyS_shmget+0x5a/0x60
tracesys+0xdd/0xe2
This bug was introduced by commit af73e4d9506d ("hugetlbfs: fix mmap
failure in unaligned size request").
Reported-by: Dave Jones <davej@redhat.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Li Zefan <lizfan@huawei.com>
Reviewed-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Acked-by: Rik van Riel <riel@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | ipc/shm.c | 8 | ||||
-rw-r--r-- | mm/mmap.c | 8 |
2 files changed, 13 insertions, 3 deletions
@@ -493,7 +493,13 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params) | |||
493 | if (shmflg & SHM_HUGETLB) { | 493 | if (shmflg & SHM_HUGETLB) { |
494 | struct hstate *hs = hstate_sizelog((shmflg >> SHM_HUGE_SHIFT) | 494 | struct hstate *hs = hstate_sizelog((shmflg >> SHM_HUGE_SHIFT) |
495 | & SHM_HUGE_MASK); | 495 | & SHM_HUGE_MASK); |
496 | size_t hugesize = ALIGN(size, huge_page_size(hs)); | 496 | size_t hugesize; |
497 | |||
498 | if (!hs) { | ||
499 | error = -EINVAL; | ||
500 | goto no_file; | ||
501 | } | ||
502 | hugesize = ALIGN(size, huge_page_size(hs)); | ||
497 | 503 | ||
498 | /* hugetlb_file_setup applies strict accounting */ | 504 | /* hugetlb_file_setup applies strict accounting */ |
499 | if (shmflg & SHM_NORESERVE) | 505 | if (shmflg & SHM_NORESERVE) |
@@ -1367,9 +1367,13 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, | |||
1367 | len = ALIGN(len, huge_page_size(hstate_file(file))); | 1367 | len = ALIGN(len, huge_page_size(hstate_file(file))); |
1368 | } else if (flags & MAP_HUGETLB) { | 1368 | } else if (flags & MAP_HUGETLB) { |
1369 | struct user_struct *user = NULL; | 1369 | struct user_struct *user = NULL; |
1370 | struct hstate *hs = hstate_sizelog((flags >> MAP_HUGE_SHIFT) & | ||
1371 | SHM_HUGE_MASK); | ||
1370 | 1372 | ||
1371 | len = ALIGN(len, huge_page_size(hstate_sizelog( | 1373 | if (!hs) |
1372 | (flags >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK))); | 1374 | return -EINVAL; |
1375 | |||
1376 | len = ALIGN(len, huge_page_size(hs)); | ||
1373 | /* | 1377 | /* |
1374 | * VM_NORESERVE is used because the reservations will be | 1378 | * VM_NORESERVE is used because the reservations will be |
1375 | * taken when vm_ops->mmap() is called | 1379 | * taken when vm_ops->mmap() is called |