Skip to content

Commit 4f49c8b

Browse files
committed
Bug 1997854 - Change the number of policy memory pages back to previous value. r=yjuglaret
This also surfaces that value as a constant, so that we can rely on it. Differential Revision: https://phabricator.services.mozilla.com/D271086
1 parent 384b70c commit 4f49c8b

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
This surfaces the memory page count for the maximum policy size as a constant,
2+
so that we can rely on it in our code. It also reverts it to 14, the value
3+
it was set to before the latest chromium sandbox update.
4+
5+
diff --git a/security/sandbox/chromium/sandbox/win/src/sandbox_policy.h b/security/sandbox/chromium/sandbox/win/src/sandbox_policy.h
6+
index 4d9d8f270890..bffab2fae890 100644
7+
--- a/security/sandbox/chromium/sandbox/win/src/sandbox_policy.h
8+
+++ b/security/sandbox/chromium/sandbox/win/src/sandbox_policy.h
9+
@@ -10,16 +10,19 @@
10+
11+
#include "base/containers/span.h"
12+
#include "base/memory/scoped_refptr.h"
13+
#include "sandbox/win/src/sandbox_types.h"
14+
#include "sandbox/win/src/security_level.h"
15+
16+
namespace sandbox {
17+
18+
+// Number of memory pages to allow for the policy storage.
19+
+constexpr size_t kPolMemPageCount = 14;
20+
+
21+
class AppContainer;
22+
23+
// Desktop used to launch child, controls GetDesktop().
24+
enum class Desktop {
25+
// Child is launched without changing the desktop.
26+
kDefault,
27+
// Child is launched using the alternate desktop.
28+
kAlternateDesktop,
29+
diff --git a/security/sandbox/chromium/sandbox/win/src/sandbox_policy_base.cc b/security/sandbox/chromium/sandbox/win/src/sandbox_policy_base.cc
30+
index 2559133d772b..3395e9cadc07 100644
31+
--- a/security/sandbox/chromium/sandbox/win/src/sandbox_policy_base.cc
32+
+++ b/security/sandbox/chromium/sandbox/win/src/sandbox_policy_base.cc
33+
@@ -44,17 +44,17 @@
34+
35+
namespace sandbox {
36+
namespace {
37+
38+
// The standard windows size for one memory page.
39+
constexpr size_t kOneMemPage = 4096;
40+
// The IPC and Policy shared memory sizes.
41+
constexpr size_t kIPCMemSize = kOneMemPage * 2;
42+
-constexpr size_t kPolMemSize = kOneMemPage * 6;
43+
+constexpr size_t kPolMemSize = kOneMemPage * kPolMemPageCount;
44+
45+
// Offset of pShimData in ntdll!_PEB.
46+
#if defined(_WIN64)
47+
// This is the same on x64 and arm64.
48+
constexpr ptrdiff_t kShimDataOffset = 0x2d8;
49+
#else
50+
constexpr ptrdiff_t kShimDataOffset = 0x1e8;
51+
#endif

security/sandbox/chromium/sandbox/win/src/sandbox_policy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
namespace sandbox {
1717

18+
// Number of memory pages to allow for the policy storage.
19+
constexpr size_t kPolMemPageCount = 14;
20+
1821
class AppContainer;
1922

2023
// Desktop used to launch child, controls GetDesktop().

security/sandbox/chromium/sandbox/win/src/sandbox_policy_base.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace {
4949
constexpr size_t kOneMemPage = 4096;
5050
// The IPC and Policy shared memory sizes.
5151
constexpr size_t kIPCMemSize = kOneMemPage * 2;
52-
constexpr size_t kPolMemSize = kOneMemPage * 6;
52+
constexpr size_t kPolMemSize = kOneMemPage * kPolMemPageCount;
5353

5454
// Offset of pShimData in ntdll!_PEB.
5555
#if defined(_WIN64)

security/sandbox/win/src/sandboxbroker/ConfigHelpers.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ SizeTrackingConfig::SizeTrackingConfig(sandbox::TargetConfig* aConfig,
3030
: mConfig(aConfig) {
3131
MOZ_ASSERT(mConfig);
3232

33-
// The calculation at the start of sandbox_policy_base.cc allows for 14 pages.
34-
MOZ_ASSERT(aStoragePages <= 14);
33+
// The calculation uses the kPolMemPageCount constant in sandbox_policy.h.
34+
// We reduce the allowable size by 1 to account for the PolicyGlobal.
35+
MOZ_ASSERT(aStoragePages > 0);
36+
MOZ_ASSERT(static_cast<size_t>(aStoragePages) < sandbox::kPolMemPageCount);
3537

3638
constexpr int32_t kOneMemPage = 4096;
3739
mRemainingSize = kOneMemPage * aStoragePages;

0 commit comments

Comments
 (0)