github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/test/syscalls/linux/vdso.cc (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include <string.h> 16 #include <sys/mman.h> 17 18 #include <algorithm> 19 20 #include "gtest/gtest.h" 21 #include "test/util/fs_util.h" 22 #include "test/util/posix_error.h" 23 #include "test/util/proc_util.h" 24 #include "test/util/test_util.h" 25 26 namespace gvisor { 27 namespace testing { 28 29 namespace { 30 31 // Ensure that the vvar page cannot be made writable. 32 TEST(VvarTest, WriteVvar) { 33 auto contents = ASSERT_NO_ERRNO_AND_VALUE(GetContents("/proc/self/maps")); 34 auto maps = ASSERT_NO_ERRNO_AND_VALUE(ParseProcMaps(contents)); 35 auto it = std::find_if(maps.begin(), maps.end(), [](const ProcMapsEntry& e) { 36 return e.filename == "[vvar]"; 37 }); 38 39 SKIP_IF(it == maps.end()); 40 EXPECT_THAT(mprotect(reinterpret_cast<void*>(it->start), kPageSize, 41 PROT_READ | PROT_WRITE), 42 SyscallFailsWithErrno(EACCES)); 43 } 44 45 } // namespace 46 47 } // namespace testing 48 } // namespace gvisor