https://github.com/torvalds/linux
Revision 573a259336f8c57739bdaf035aa7abbae7d9a713 authored by Axel Rasmussen on 06 December 2020, 06:15:05 UTC, committed by Linus Torvalds on 06 December 2020, 18:19:07 UTC
The error handling in hugetlb_allocate_area() was incorrect for the
hugetlb_shared test case.

Previously the behavior was:

- mmap a hugetlb area
  - If this fails, set the pointer to NULL, and carry on
- mmap an alias of the same hugetlb fd
  - If this fails, munmap the original area

If the original mmap failed, it's likely the second one did too.  If
both failed, we'd blindly try to munmap a NULL pointer, causing a
SIGSEGV.  Instead, "goto fail" so we return before trying to mmap the
alias.

This issue can be hit "in real life" by forgetting to set
/proc/sys/vm/nr_hugepages (leaving it at 0), and then trying to run the
hugetlb_shared test.

Another small improvement is, when the original mmap fails, don't just
print "it failed": perror(), so we can see *why*.  :)

Signed-off-by: Axel Rasmussen <axelrasmussen@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Peter Xu <peterx@redhat.com>
Cc: Joe Perches <joe@perches.com>
Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: David Alan Gilbert <dgilbert@redhat.com>
Link: https://lkml.kernel.org/r/20201204203443.2714693-1-axelrasmussen@google.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d8cbe8b
History
Tip revision: 573a259336f8c57739bdaf035aa7abbae7d9a713 authored by Axel Rasmussen on 06 December 2020, 06:15:05 UTC
userfaultfd: selftests: fix SIGSEGV if huge mmap fails
Tip revision: 573a259
File Mode Size
.gitignore -rw-r--r-- 64 bytes
Kconfig -rw-r--r-- 3.7 KB
Makefile -rw-r--r-- 2.2 KB
arm_ssp_per_task_plugin.c -rw-r--r-- 2.8 KB
cyc_complexity_plugin.c -rw-r--r-- 1.7 KB
gcc-common.h -rw-r--r-- 23.7 KB
gcc-generate-gimple-pass.h -rw-r--r-- 4.1 KB
gcc-generate-ipa-pass.h -rw-r--r-- 7.4 KB
gcc-generate-rtl-pass.h -rw-r--r-- 4.1 KB
gcc-generate-simple_ipa-pass.h -rw-r--r-- 4.1 KB
gen-random-seed.sh -rw-r--r-- 305 bytes
latent_entropy_plugin.c -rw-r--r-- 16.6 KB
randomize_layout_plugin.c -rw-r--r-- 26.4 KB
sancov_plugin.c -rw-r--r-- 3.8 KB
stackleak_plugin.c -rw-r--r-- 17.9 KB
structleak_plugin.c -rw-r--r-- 7.4 KB

back to top