| delorie.com/archives/browse.cgi | search |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| DomainKey-Signature: | a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id |
| :list-unsubscribe:list-subscribe:list-archive:list-post | |
| :list-help:sender:mime-version:date:message-id:subject:from:to | |
| :content-type; q=dns; s=default; b=aXkJyWH2y5mFgIlz6+dyzMQPqX6xS | |
| 4HRJnzJLDgmGLV2MZVXmFzrz9iEIGgiq24bak2kFmh36NgA+alF46v1ZLOcu4RV7 | |
| NAzriL5fgiJHmgO1tI1R9nMIazWlnDZVsTJ9lKORIhI09L2380/qC4mbXxoiJtaw | |
| Ukgmn4Tqn3le3Q= | |
| DKIM-Signature: | v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id |
| :list-unsubscribe:list-subscribe:list-archive:list-post | |
| :list-help:sender:mime-version:date:message-id:subject:from:to | |
| :content-type; s=default; bh=/vzCPEVjtZuCqzgyHR7Ee6qFrbc=; b=S4n | |
| CkZz8h30RZFJyJyI95vn6FYxFFhs9GOMcbRJ1cEL9mJ/a4De3opHX9boUtyjFsPD | |
| zKgLYYqqhy+ZA6i0C6yHOBuykQo9JHZRaIn1Hq95G6GIaO+ez96OuG48uxRI9nch | |
| Z5ajpjLl+Pa0T659Bz8zN10gkCbuv2JTsVOQ0Byw= | |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Id: | <cygwin.cygwin.com> |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sourceware.org/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
| Sender: | cygwin-owner AT cygwin DOT com |
| Mail-Followup-To: | cygwin AT cygwin DOT com |
| Delivered-To: | mailing list cygwin AT cygwin DOT com |
| Authentication-Results: | sourceware.org; auth=none |
| X-Virus-Found: | No |
| X-Spam-SWARE-Status: | No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=erik, *top, reserves, offer |
| X-HELO: | mail-lb0-f174.google.com |
| X-Google-DKIM-Signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to; bh=iCETWe7aJqR96C/63pyOudnNJ7ws/KEmdULKY1XGl1E=; b=fx4ZUuOnGSIsd8DAVMvOSdnJUhmFXgq3DizdL4Sp30i1p6vnKV7G65wsnDfdGIY6E/ 02crbry8rgSibmn9VMYH3fh9vbB9W983MZCM1AbrVNks6jCkrXj3akWS21a8G2Hag/a7 7qo0T7VZJPfKU94lQwN3Hhchvhd/9hRrU/F9rBqDVStOANbuuKWngO2JNV9madkCd+3l ulhDf363heMM+srA/vAqzVD40u3G2LNjLsjnHGK6n6kgKb9aeu8m0cVtalVZUXHdkwil U/B2TLBdyP2OmTKykXwFzQFiX4wSwbYn8tUZeZP8O3QlnfPe2HmKVQD/7Ro4yP83N2Xy JsCw== |
| X-Gm-Message-State: | AOPr4FXdpZ0707g8t28LpyZSyyPSjGBYAjnu1LuZ9m273kAsJxlDdNv+YgnWlFaFr/u6Owx/eyu2qbjR/qSOKA== |
| MIME-Version: | 1.0 |
| X-Received: | by 10.112.134.229 with SMTP id pn5mr4335937lbb.36.1463059844793; Thu, 12 May 2016 06:30:44 -0700 (PDT) |
| Date: | Thu, 12 May 2016 15:30:44 +0200 |
| Message-ID: | <CAOTD34Z8sbu3BFDbSjzRhy_ZX5swnvNErVk1EzMfQZj0MEE=DA@mail.gmail.com> |
| Subject: | Segfault in MAP_NORESERVE mmap above ~4GB |
| From: | Erik Bray <erik DOT m DOT bray AT gmail DOT com> |
| To: | cygwin AT cygwin DOT com |
Hi all,
This issue pertains to Cygwin 64-bit. The following example program
demonstrates the issue:
$ cat mmap_test.c
#include <sys/mman.h>
#include <stdio.h>
#include <windows.h>
#define VSIZE 0x100001000
#define SIZE 0x1000
void foo() {
void *top, *bot, *c;
c = mmap(NULL, VSIZE, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0);
top = c + VSIZE;
bot = top - SIZE;
printf(" c = 0x%016lx\n", c);
printf(" top = 0x%016lx\n", top);
printf(" bot = 0x%016lx\n", bot);
printf(" c[0] = %ul\n", *((unsigned long *)c));
printf("bot[0] = %ul\n", *((unsigned long *)bot));
}
int main(void) {
foo();
return 0;
}
$ gcc mmap_test.c -o mmap_test
$ ./mmap_test.exe
c = 0x000006feffff0000
top = 0x000006ffffff1000
bot = 0x000006ffffff0000
c[0] = 0l
Segmentation fault (core dumped)
--------------------------------------------------
As you can see, the address stored in `bot` is within the mmap'd
region, but trying to access it results in an access violation, while
addresses low in the region can be accessed. This is only an issue
because of MAP_NORESERVE, so when the mmap is created it only reserves
an address range for it but does not commit any resources.
Instead, when Cygwin's exception handler receives a
STATUS_ACCESS_VIOLATION [1] it calls into
mmap_is_attached_or_noreserve [2] with the address associated with
access violation. This searches the records of existing mmap'd
regions until it finds a matching region, and commits enough of that
region to be able to service the memory access.
This search works for lower addresses in the region, but fails for
higher addresses. From a bit of debugging it seems this is occurring
because the constructor for mmap_record is squeezing the mmap length
into a DWORD [3], and the rest of the problems stem from there. There
are a few other places related to mmap_record that seem to be treating
the mmap length as a DWORD instead of a size_t. I would offer a patch
but I've never built Cygwin before so I haven't tested this yet.
Thanks,
Erik
[1] https://github.com/openunix/cygwin/blob/99590589326b5537d549cdd41ca4177ce7051d4a/winsup/cygwin/exceptions.cc#L722
[2] https://github.com/openunix/cygwin/blob/99590589326b5537d549cdd41ca4177ce7051d4a/winsup/cygwin/mmap.cc#L704
[3] https://github.com/openunix/cygwin/blob/99590589326b5537d549cdd41ca4177ce7051d4a/winsup/cygwin/mmap.cc#L275
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |