WSL2-Linux-Kernel/tools
Axel Rasmussen 573a259336 userfaultfd: selftests: fix SIGSEGV if huge mmap fails
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>
2020-12-06 10:19:07 -08:00
..
accounting
arch tools arch: Update arch/x86/lib/mem{cpy,set}_64.S copies used in 'perf bench mem memcpy' 2020-11-12 17:55:41 -03:00
bootconfig tools/bootconfig: Store size and checksum in footer as le32 2020-11-30 23:22:11 -05:00
bpf bpftool: Fix error return value in build_btf_type_table 2020-11-24 23:19:18 +01:00
build tools feature: Fixup fast path feature detection 2020-11-03 09:24:20 -03:00
cgroup
debugging
edid
firewire
firmware
gpio
hv
iio
include tools include UAPI: Update linux/mount.h copy 2020-11-03 08:52:11 -03:00
io_uring
kvm/kvm_stat
laptop
leds
lib libbpf: Fix VERSIONED_SYM_COUNT number parsing 2020-11-19 08:45:12 -08:00
memory-model
objtool
pci
pcmcia
perf perf probe: Change function definition check due to broken DWARF 2020-11-27 14:36:15 -03:00
power Merge branch 'turbostat' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux 2020-11-10 10:02:31 -08:00
scripts
spi
testing userfaultfd: selftests: fix SIGSEGV if huge mmap fails 2020-12-06 10:19:07 -08:00
thermal/tmon
time
usb
virtio
vm
wmi
Makefile