]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: mmap: fix mapping beyond EOF on 64 bit
authorKen Brown <kbrown@cornell.edu>
Mon, 20 Jul 2020 12:59:09 +0000 (08:59 -0400)
committerKen Brown <kbrown@cornell.edu>
Mon, 20 Jul 2020 15:56:29 +0000 (11:56 -0400)
Commit 605bdcd410384dda6db66b9b8cd19e863702e1bb enabled mapping beyond
EOF in 64 bit environments.  But the variable 'orig_len' did not get
rounded up to a multiple of 64K.  This rounding was done on 32 bit
only.  Fix this by rounding up orig_len on 64 bit, in the same place
where 'len' is rounded up.

Rounding up is needed to make sigbus_page_len a multiple of the
allocation granularity.

In addition, failing to round up could cause orig_len to be smaller
than len.  Since these are both unsigned values, the statement
'orig_len -= len' could then cause orig_len to be huge, and mmap would
fail with errno EFBIG.

I observed this failure while debugging the problem reported in

  https://sourceware.org/pipermail/cygwin/2020-July/245557.html.

The failure can be seen by running the test case in that report under
gdb or strace.

winsup/cygwin/mmap.cc

index feb9e5d0edfdec4f92803cd4fffcad6555e76fa2..a08d00f83e918e9c00d600a33e97ef503d908a93 100644 (file)
@@ -1144,6 +1144,7 @@ go_ahead:
         ends in, but there's nothing at all we can do about that. */
 #ifdef __x86_64__
       len = roundup2 (len, wincap.allocation_granularity ());
+      orig_len = roundup2 (orig_len, wincap.allocation_granularity ());
 #else
       len = roundup2 (len, wincap.is_wow64 () ? wincap.allocation_granularity ()
                                              : wincap.page_size ());
This page took 0.034013 seconds and 5 git commands to generate.