Skip to content

Commit

Permalink
Add HANDLE_EINTR() to mprotect() calls.
Browse files Browse the repository at this point in the history
On Linux, EINTR can be returned from mprotect(), but we don't handle
it. Add HANDLE_EINTR() in relevant places in the codebase. For context,
see https://bugs.chromium.org/p/chromium/issues/detail?id=1124675#c6.

Bug: 1124675
Change-Id: I1cb35e637297593ae7e922cd90cef2163f397584
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2478946
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: George Burgess <gbiv@chromium.org>
Commit-Queue: Benoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820203}
  • Loading branch information
Benoit Lize authored and Commit Bot committed Oct 23, 2020
1 parent bd67d08 commit 4169c9f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion base/android/linker/modern_linker_jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ bool CopyAndRemapRelocations(const LoadedLibraryMetadata& metadata, int* fd) {
}

memcpy(relro_copy_addr, relro_addr, metadata.relro_size);
int retval = mprotect(relro_copy_addr, metadata.relro_size, PROT_READ);
int retval =
HANDLE_EINTR(mprotect(relro_copy_addr, metadata.relro_size, PROT_READ));
if (retval) {
LOG_ERROR("Cannot call mprotect()");
close(shared_mem_fd);
Expand Down
2 changes: 1 addition & 1 deletion base/files/file_util_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ BASE_EXPORT bool IsPathExecutable(const FilePath& path) {
CHECK_GE(sizeof(pagesize), sizeof(sysconf_result));
void* mapping = mmap(nullptr, pagesize, PROT_READ, MAP_SHARED, fd.get(), 0);
if (mapping != MAP_FAILED) {
if (mprotect(mapping, pagesize, PROT_READ | PROT_EXEC) == 0)
if (HANDLE_EINTR(mprotect(mapping, pagesize, PROT_READ | PROT_EXEC)) == 0)
result = true;
munmap(mapping, pagesize);
}
Expand Down
2 changes: 1 addition & 1 deletion base/process/launch_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ Process LaunchProcess(const std::vector<std::string>& argv,
// any hidden calls to malloc.
void *malloc_thunk =
reinterpret_cast<void*>(reinterpret_cast<intptr_t>(malloc) & ~4095);
mprotect(malloc_thunk, 4096, PROT_READ | PROT_WRITE | PROT_EXEC);
HANDLE_EINTR(mprotect(malloc_thunk, 4096, PROT_READ | PROT_WRITE | PROT_EXEC));
memset(reinterpret_cast<void*>(malloc), 0xff, 8);
#endif // 0

Expand Down
3 changes: 2 additions & 1 deletion chromeos/hugepage_text/hugepage_text.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "base/bit_cast.h"
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"

// CHROMEOS_ORDERFILE_USE is a flag intended to use orderfile
// to link Chrome. Only when orderfile is used, we will use hugepages.
Expand Down Expand Up @@ -134,7 +135,7 @@ static void MremapHugetlbText(void* vaddr, const size_t hsize) {
NoAsanAlignedMemcpy(haddr, vaddr, hsize);

// change mapping protection to read only now that it has done the copy
if (mprotect(haddr, hsize, PROT_READ | PROT_EXEC)) {
if (HANDLE_EINTR(mprotect(haddr, hsize, PROT_READ | PROT_EXEC))) {
PLOG(INFO) << "can not change protection to r-x, fall back to small page";
munmap(haddr, hsize);
return;
Expand Down
4 changes: 3 additions & 1 deletion components/gwp_asan/client/guarded_page_allocator_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <sys/mman.h>

#include "base/check.h"
#include "base/posix/eintr_wrapper.h"

namespace gwp_asan {
namespace internal {
Expand All @@ -25,7 +26,8 @@ void GuardedPageAllocator::UnmapRegion() {
}

void GuardedPageAllocator::MarkPageReadWrite(void* ptr) {
int err = mprotect(ptr, state_.page_size, PROT_READ | PROT_WRITE);
int err =
HANDLE_EINTR(mprotect(ptr, state_.page_size, PROT_READ | PROT_WRITE));
PCHECK(err == 0) << "mprotect";
}

Expand Down

0 comments on commit 4169c9f

Please sign in to comment.