|
@@ -0,0 +1,162 @@
|
|
|
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
+From: John Kleinschmidt <[email protected]>
|
|
|
+Date: Wed, 26 Oct 2022 10:59:53 -0400
|
|
|
+Subject: Revert "Use accessibility.pkey when setting page access."
|
|
|
+
|
|
|
+This reverts commit 1c803026432e70740a319a51b41415694ebe36c9.
|
|
|
+
|
|
|
+https://chromium-review.googlesource.com/c/chromium/src/+/3949281
|
|
|
+breaks builds running in Docker.
|
|
|
+
|
|
|
+This patch should be removed once
|
|
|
+https://chromium-review.googlesource.com/c/chromium/src/+/3949284
|
|
|
+is merged.
|
|
|
+
|
|
|
+diff --git a/base/allocator/partition_allocator/BUILD.gn b/base/allocator/partition_allocator/BUILD.gn
|
|
|
+index 7f55dfd28b41c19a61590a71fa72c7bc73edc4a0..d8688eca677aac51c3e6e16104c3fe3b765167f0 100644
|
|
|
+--- a/base/allocator/partition_allocator/BUILD.gn
|
|
|
++++ b/base/allocator/partition_allocator/BUILD.gn
|
|
|
+@@ -110,8 +110,6 @@ component("partition_alloc") {
|
|
|
+ "partition_alloc_base/numerics/safe_math_arm_impl.h",
|
|
|
+ "partition_alloc_base/numerics/safe_math_clang_gcc_impl.h",
|
|
|
+ "partition_alloc_base/numerics/safe_math_shared_impl.h",
|
|
|
+- "partition_alloc_base/pkey.cc",
|
|
|
+- "partition_alloc_base/pkey.h",
|
|
|
+ "partition_alloc_base/posix/eintr_wrapper.h",
|
|
|
+ "partition_alloc_base/rand_util.cc",
|
|
|
+ "partition_alloc_base/rand_util.h",
|
|
|
+diff --git a/base/allocator/partition_allocator/page_allocator_internals_posix.h b/base/allocator/partition_allocator/page_allocator_internals_posix.h
|
|
|
+index 6ec54137fc0287375e267ba04f62201b7aac5cbd..fde49fd5b169507c9b8d26908bb306b4f0226c11 100644
|
|
|
+--- a/base/allocator/partition_allocator/page_allocator_internals_posix.h
|
|
|
++++ b/base/allocator/partition_allocator/page_allocator_internals_posix.h
|
|
|
+@@ -15,7 +15,6 @@
|
|
|
+ #include "base/allocator/partition_allocator/oom.h"
|
|
|
+ #include "base/allocator/partition_allocator/page_allocator.h"
|
|
|
+ #include "base/allocator/partition_allocator/partition_alloc_base/debug/debugging_buildflags.h"
|
|
|
+-#include "base/allocator/partition_allocator/partition_alloc_base/pkey.h"
|
|
|
+ #include "base/allocator/partition_allocator/partition_alloc_base/posix/eintr_wrapper.h"
|
|
|
+ #include "base/allocator/partition_allocator/partition_alloc_check.h"
|
|
|
+ #include "build/build_config.h"
|
|
|
+@@ -201,14 +200,8 @@ bool TrySetSystemPagesAccessInternal(
|
|
|
+ uintptr_t address,
|
|
|
+ size_t length,
|
|
|
+ PageAccessibilityConfiguration accessibility) {
|
|
|
+-#if BUILDFLAG(ENABLE_PKEYS)
|
|
|
+- return 0 == base::PkeyMprotect(reinterpret_cast<void*>(address), length,
|
|
|
+- GetAccessFlags(accessibility),
|
|
|
+- accessibility.pkey);
|
|
|
+-#else
|
|
|
+ return 0 == PA_HANDLE_EINTR(mprotect(reinterpret_cast<void*>(address), length,
|
|
|
+ GetAccessFlags(accessibility)));
|
|
|
+-#endif
|
|
|
+ }
|
|
|
+
|
|
|
+ void SetSystemPagesAccessInternal(
|
|
|
+@@ -216,14 +209,8 @@ void SetSystemPagesAccessInternal(
|
|
|
+ size_t length,
|
|
|
+ PageAccessibilityConfiguration accessibility) {
|
|
|
+ int access_flags = GetAccessFlags(accessibility);
|
|
|
+-#if BUILDFLAG(ENABLE_PKEYS)
|
|
|
+- int ret =
|
|
|
+- base::PkeyMprotect(reinterpret_cast<void*>(address), length,
|
|
|
+- GetAccessFlags(accessibility), accessibility.pkey);
|
|
|
+-#else
|
|
|
+- int ret = PA_HANDLE_EINTR(mprotect(reinterpret_cast<void*>(address), length,
|
|
|
+- GetAccessFlags(accessibility)));
|
|
|
+-#endif
|
|
|
++ const int ret = PA_HANDLE_EINTR(
|
|
|
++ mprotect(reinterpret_cast<void*>(address), length, access_flags));
|
|
|
+
|
|
|
+ // On Linux, man mprotect(2) states that ENOMEM is returned when (1) internal
|
|
|
+ // kernel data structures cannot be allocated, (2) the address range is
|
|
|
+diff --git a/base/allocator/partition_allocator/partition_alloc_base/pkey.cc b/base/allocator/partition_allocator/partition_alloc_base/pkey.cc
|
|
|
+deleted file mode 100644
|
|
|
+index b9f3e25cb037c18a146ad6843450e7b12b13100a..0000000000000000000000000000000000000000
|
|
|
+--- a/base/allocator/partition_allocator/partition_alloc_base/pkey.cc
|
|
|
++++ /dev/null
|
|
|
+@@ -1,49 +0,0 @@
|
|
|
+-// Copyright 2022 The Chromium Authors
|
|
|
+-// Use of this source code is governed by a BSD-style license that can be
|
|
|
+-// found in the LICENSE file.
|
|
|
+-
|
|
|
+-#include "base/allocator/partition_allocator/partition_alloc_base/pkey.h"
|
|
|
+-
|
|
|
+-#if BUILDFLAG(ENABLE_PKEYS)
|
|
|
+-
|
|
|
+-#include <errno.h>
|
|
|
+-#include <sys/mman.h>
|
|
|
+-#include <sys/syscall.h>
|
|
|
+-#include <unistd.h>
|
|
|
+-
|
|
|
+-#include "base/allocator/partition_allocator/partition_alloc_base/cpu.h"
|
|
|
+-#include "base/allocator/partition_allocator/partition_alloc_check.h"
|
|
|
+-
|
|
|
+-#if !BUILDFLAG(IS_LINUX)
|
|
|
+-#error "This pkey code is currently only supported on Linux"
|
|
|
+-#endif
|
|
|
+-
|
|
|
+-namespace partition_alloc::internal::base {
|
|
|
+-
|
|
|
+-bool CPUHasPkeySupport() {
|
|
|
+- return base::CPU::GetInstanceNoAllocation().has_pku();
|
|
|
+-}
|
|
|
+-
|
|
|
+-int PkeyMprotect(void* addr, size_t len, int prot, int pkey) {
|
|
|
+- if (PA_UNLIKELY(CPUHasPkeySupport())) {
|
|
|
+- // The pkey_mprotect syscall is supported from Linux 4.9. If the CPU is
|
|
|
+- // recent enough to have PKU support, then it's likely that we also run on a
|
|
|
+- // more recent kernel. But fall back to mprotect if the syscall is not
|
|
|
+- // available and pkey is 0.
|
|
|
+- // Note that we can't use mprotect as the default for the pkey == 0 case,
|
|
|
+- // since we can temporarily change the pkey back to 0 on some globals.
|
|
|
+- int ret = syscall(SYS_pkey_mprotect, addr, len, prot, pkey);
|
|
|
+- if (PA_LIKELY(ret == 0))
|
|
|
+- return ret;
|
|
|
+- if (errno != ENOSYS)
|
|
|
+- return ret;
|
|
|
+- // fall through if syscall doesn't exist
|
|
|
+- }
|
|
|
+- PA_CHECK(pkey == 0);
|
|
|
+-
|
|
|
+- return mprotect(addr, len, prot);
|
|
|
+-}
|
|
|
+-
|
|
|
+-} // namespace partition_alloc::internal::base
|
|
|
+-
|
|
|
+-#endif // BUILDFLAG(ENABLE_PKEYS)
|
|
|
+diff --git a/base/allocator/partition_allocator/partition_alloc_base/pkey.h b/base/allocator/partition_allocator/partition_alloc_base/pkey.h
|
|
|
+deleted file mode 100644
|
|
|
+index 4830b50aa628cde64ceead76ddc60aaf13c8bab4..0000000000000000000000000000000000000000
|
|
|
+--- a/base/allocator/partition_allocator/partition_alloc_base/pkey.h
|
|
|
++++ /dev/null
|
|
|
+@@ -1,30 +0,0 @@
|
|
|
+-// Copyright 2022 The Chromium Authors
|
|
|
+-// Use of this source code is governed by a BSD-style license that can be
|
|
|
+-// found in the LICENSE file.
|
|
|
+-
|
|
|
+-#ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_BASE_PKEY_H_
|
|
|
+-#define BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_BASE_PKEY_H_
|
|
|
+-
|
|
|
+-#include "base/allocator/partition_allocator/partition_alloc_buildflags.h"
|
|
|
+-
|
|
|
+-#if BUILDFLAG(ENABLE_PKEYS)
|
|
|
+-
|
|
|
+-#include "base/allocator/partition_allocator/partition_alloc_base/compiler_specific.h"
|
|
|
+-
|
|
|
+-#include <cstddef>
|
|
|
+-#include <cstdint>
|
|
|
+-
|
|
|
+-namespace partition_alloc::internal::base {
|
|
|
+-
|
|
|
+-// Check if the CPU supports pkeys.
|
|
|
+-bool CPUHasPkeySupport();
|
|
|
+-
|
|
|
+-// A wrapper around pkey_mprotect that falls back to regular mprotect if the
|
|
|
+-// CPU/kernel doesn't support it (and pkey is 0).
|
|
|
+-[[nodiscard]] int PkeyMprotect(void* addr, size_t len, int prot, int pkey);
|
|
|
+-
|
|
|
+-} // namespace partition_alloc::internal::base
|
|
|
+-
|
|
|
+-#endif // BUILDFLAG(ENABLE_PKEYS)
|
|
|
+-
|
|
|
+-#endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_BASE_PKEY_H_
|