Skip to content

Commit c075f6c

Browse files
committed
cve-2017-17052: tolerate ENOMEM during test
As each iteration of mmap_thread() grabs a fresh 16 MiB MAP_POPULATE region and never releases it. With the loop runs, those regions accumulate consuming both virtual address space and committed physical memory right away instead of lazily. Easily mmap() fails with ENOMEM on smaller/limit RAM resource system. Error Log: cve-2017-17052.c:48: TBROK: mmap((nil),16777216,PROT_READ(1),32802,-1,0) failed: ENOMEM (12) tst_test.c:479: TINFO: Child process reported TBROK killing the test tst_test.c:1909: TINFO: Killed the leftover descendant processes Consider there is no practical upper bound on this allocation pattern, so setting .min_mem_avail may not helps. Here we just tolerate ENOMEM during the mmap_thread() looping. Signed-off-by: Li Wang <liwang@redhat.com> Reviewed-by: Petr Vorel <pvorel@suse.cz> Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
1 parent 7e62f90 commit c075f6c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

testcases/cve/cve-2017-17052.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,18 @@ static void cleanup(void)
4444

4545
static void *mmap_thread(void *arg)
4646
{
47+
void *ptr;
48+
4749
for (;;) {
48-
SAFE_MMAP(NULL, 0x1000000, PROT_READ,
50+
ptr = mmap(NULL, 0x1000000, PROT_READ,
4951
MAP_POPULATE|MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
52+
53+
if (ptr == MAP_FAILED) {
54+
if (errno == ENOMEM)
55+
usleep(1000);
56+
else
57+
tst_brk(TBROK | TTERRNO, "mmap() failed");
58+
}
5059
}
5160

5261
return arg;

0 commit comments

Comments
 (0)