diff options
author | Christopher Ferris <cferris1000@users.noreply.github.com> | 2024-03-29 14:19:10 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-03-29 14:22:00 -0700 |
commit | 34ad29845209be6d7ec9658fbfcf4e574447b08d (patch) | |
tree | 5f9331fbade407eaff32b9c5a51c69361ef02fdd | |
parent | 6d3a4adc47d0e44e556c27d1b836cbd27e140cf2 (diff) | |
download | scudo-34ad29845209be6d7ec9658fbfcf4e574447b08d.tar.gz |
[scudo] Change tests that use setrlimit to cause mmap to fail. (#87004)
It appears that qemu does not actually cause mmap to fail when calling
setrlimit to limit the address space size. In the two tests that use
setrlimit, detect if mmap still works and skip the tests in that case.
Since all Android targets should support setrlimit, compile out the mmap
check code for them.
GitOrigin-RevId: c0a3c5c81ff7ff9e2a90b1664d6e419bf99c1aa9
Change-Id: If0779cb50a77f3fea8e6704d4a3d21c3eaa47e3b
-rw-r--r-- | standalone/tests/strings_test.cpp | 11 | ||||
-rw-r--r-- | standalone/tests/vector_test.cpp | 9 |
2 files changed, 20 insertions, 0 deletions
diff --git a/standalone/tests/strings_test.cpp b/standalone/tests/strings_test.cpp index 17a596d712d..abb81803f65 100644 --- a/standalone/tests/strings_test.cpp +++ b/standalone/tests/strings_test.cpp @@ -129,6 +129,7 @@ TEST(ScudoStringsTest, Padding) { } #if defined(__linux__) + #include <sys/resource.h> TEST(ScudoStringsTest, CapacityIncreaseFails) { @@ -136,9 +137,19 @@ TEST(ScudoStringsTest, CapacityIncreaseFails) { rlimit Limit = {}; EXPECT_EQ(0, getrlimit(RLIMIT_AS, &Limit)); + rlimit EmptyLimit = {.rlim_cur = 0, .rlim_max = Limit.rlim_max}; EXPECT_EQ(0, setrlimit(RLIMIT_AS, &EmptyLimit)); + // qemu does not honor the setrlimit, so verify before proceeding. + scudo::MemMapT MemMap; + if (MemMap.map(/*Addr=*/0U, scudo::getPageSizeCached(), "scudo:test", + MAP_ALLOWNOMEM)) { + MemMap.unmap(MemMap.getBase(), MemMap.getCapacity()); + setrlimit(RLIMIT_AS, &Limit); + GTEST_SKIP() << "Limiting address space does not prevent mmap."; + } + // Test requires that the default length is at least 6 characters. scudo::uptr MaxSize = Str.capacity(); EXPECT_LE(6u, MaxSize); diff --git a/standalone/tests/vector_test.cpp b/standalone/tests/vector_test.cpp index add62c5a42a..b612676b7bd 100644 --- a/standalone/tests/vector_test.cpp +++ b/standalone/tests/vector_test.cpp @@ -58,6 +58,15 @@ TEST(ScudoVectorTest, ReallocateFails) { rlimit EmptyLimit = {.rlim_cur = 0, .rlim_max = Limit.rlim_max}; EXPECT_EQ(0, setrlimit(RLIMIT_AS, &EmptyLimit)); + // qemu does not honor the setrlimit, so verify before proceeding. + scudo::MemMapT MemMap; + if (MemMap.map(/*Addr=*/0U, scudo::getPageSizeCached(), "scudo:test", + MAP_ALLOWNOMEM)) { + MemMap.unmap(MemMap.getBase(), MemMap.getCapacity()); + setrlimit(RLIMIT_AS, &Limit); + GTEST_SKIP() << "Limiting address space does not prevent mmap."; + } + V.resize(capacity); // Set the last element so we can check it later. V.back() = '\0'; |