Attachment #9131513: Bug 1557282 Part 1: Take chromium commit c1ce57ea5d31208af589b4839390a44ab20b0c8f. r=handyman! for bug #1618911

View | Details | Raw Unified | Return to bug 1618911
Collapse All | Expand All

(-)a/security/sandbox/chromium/sandbox/win/src/restricted_token.cc (+19 lines)
Line     Link Here 
 Lines 158-173   DWORD RestrictedToken::GetRestrictedToke Link Here 
158
  } else {
158
  } else {
159
    // Modify the default dacl on the token to contain Restricted.
159
    // Modify the default dacl on the token to contain Restricted.
160
    if (!AddSidToDefaultDacl(new_token.Get(), WinRestrictedCodeSid,
160
    if (!AddSidToDefaultDacl(new_token.Get(), WinRestrictedCodeSid,
161
                             GRANT_ACCESS, GENERIC_ALL)) {
161
                             GRANT_ACCESS, GENERIC_ALL)) {
162
      return ::GetLastError();
162
      return ::GetLastError();
163
    }
163
    }
164
  }
164
  }
165
165
166
  for (const auto& default_dacl_sid : sids_for_default_dacl_) {
167
    if (!AddSidToDefaultDacl(new_token.Get(), std::get<0>(default_dacl_sid),
168
                             std::get<1>(default_dacl_sid),
169
                             std::get<2>(default_dacl_sid))) {
170
      return ::GetLastError();
171
    }
172
  }
173
166
  // Add user to default dacl.
174
  // Add user to default dacl.
167
  if (!AddUserSidToDefaultDacl(new_token.Get(), GENERIC_ALL))
175
  if (!AddUserSidToDefaultDacl(new_token.Get(), GENERIC_ALL))
168
    return ::GetLastError();
176
    return ::GetLastError();
169
177
170
  DWORD error = SetTokenIntegrityLevel(new_token.Get(), integrity_level_);
178
  DWORD error = SetTokenIntegrityLevel(new_token.Get(), integrity_level_);
171
  if (ERROR_SUCCESS != error)
179
  if (ERROR_SUCCESS != error)
172
    return error;
180
    return error;
173
181
 Lines 422-430   DWORD RestrictedToken::SetIntegrityLevel Link Here 
422
  integrity_level_ = integrity_level;
430
  integrity_level_ = integrity_level;
423
  return ERROR_SUCCESS;
431
  return ERROR_SUCCESS;
424
}
432
}
425
433
426
void RestrictedToken::SetLockdownDefaultDacl() {
434
void RestrictedToken::SetLockdownDefaultDacl() {
427
  lockdown_default_dacl_ = true;
435
  lockdown_default_dacl_ = true;
428
}
436
}
429
437
438
DWORD RestrictedToken::AddDefaultDaclSid(const Sid& sid,
439
                                         ACCESS_MODE access_mode,
440
                                         ACCESS_MASK access) {
441
  DCHECK(init_);
442
  if (!init_)
443
    return ERROR_NO_TOKEN;
444
445
  sids_for_default_dacl_.push_back(std::make_tuple(sid, access_mode, access));
446
  return ERROR_SUCCESS;
447
}
448
430
}  // namespace sandbox
449
}  // namespace sandbox
(-)a/security/sandbox/chromium/sandbox/win/src/restricted_token.h (+9 lines)
Line     Link Here 
 Lines 2-17    Link Here 
2
// Use of this source code is governed by a BSD-style license that can be
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
3
// found in the LICENSE file.
4
4
5
#ifndef SANDBOX_SRC_RESTRICTED_TOKEN_H_
5
#ifndef SANDBOX_SRC_RESTRICTED_TOKEN_H_
6
#define SANDBOX_SRC_RESTRICTED_TOKEN_H_
6
#define SANDBOX_SRC_RESTRICTED_TOKEN_H_
7
7
8
#include <windows.h>
8
#include <windows.h>
9
9
10
#include <tuple>
10
#include <vector>
11
#include <vector>
11
12
12
#include "base/macros.h"
13
#include "base/macros.h"
13
#include "base/strings/string16.h"
14
#include "base/strings/string16.h"
14
#include "base/win/scoped_handle.h"
15
#include "base/win/scoped_handle.h"
15
#include "sandbox/win/src/restricted_token_utils.h"
16
#include "sandbox/win/src/restricted_token_utils.h"
16
#include "sandbox/win/src/security_level.h"
17
#include "sandbox/win/src/security_level.h"
17
#include "sandbox/win/src/sid.h"
18
#include "sandbox/win/src/sid.h"
 Lines 168-190   class RestrictedToken { Link Here 
168
  // Sets the token integrity level. This is only valid on Vista. The integrity
169
  // Sets the token integrity level. This is only valid on Vista. The integrity
169
  // level cannot be higher than your current integrity level.
170
  // level cannot be higher than your current integrity level.
170
  DWORD SetIntegrityLevel(IntegrityLevel integrity_level);
171
  DWORD SetIntegrityLevel(IntegrityLevel integrity_level);
171
172
172
  // Set a flag which indicates the created token should have a locked down
173
  // Set a flag which indicates the created token should have a locked down
173
  // default DACL when created.
174
  // default DACL when created.
174
  void SetLockdownDefaultDacl();
175
  void SetLockdownDefaultDacl();
175
176
177
  // Add a SID to the default DACL. These SIDs are added regardless of the
178
  // SetLockdownDefaultDacl state.
179
  DWORD AddDefaultDaclSid(const Sid& sid,
180
                          ACCESS_MODE access_mode,
181
                          ACCESS_MASK access);
182
176
 private:
183
 private:
177
  // The list of restricting sids in the restricted token.
184
  // The list of restricting sids in the restricted token.
178
  std::vector<Sid> sids_to_restrict_;
185
  std::vector<Sid> sids_to_restrict_;
179
  // The list of privileges to remove in the restricted token.
186
  // The list of privileges to remove in the restricted token.
180
  std::vector<LUID> privileges_to_disable_;
187
  std::vector<LUID> privileges_to_disable_;
181
  // The list of sids to mark as Deny Only in the restricted token.
188
  // The list of sids to mark as Deny Only in the restricted token.
182
  std::vector<Sid> sids_for_deny_only_;
189
  std::vector<Sid> sids_for_deny_only_;
190
  // The list of sids to add to the default DACL of the restricted token.
191
  std::vector<std::tuple<Sid, ACCESS_MODE, ACCESS_MASK>> sids_for_default_dacl_;
183
  // The token to restrict. Can only be set in a constructor.
192
  // The token to restrict. Can only be set in a constructor.
184
  base::win::ScopedHandle effective_token_;
193
  base::win::ScopedHandle effective_token_;
185
  // The token integrity level. Only valid on Vista.
194
  // The token integrity level. Only valid on Vista.
186
  IntegrityLevel integrity_level_;
195
  IntegrityLevel integrity_level_;
187
  // Tells if the object is initialized or not (if Init() has been called)
196
  // Tells if the object is initialized or not (if Init() has been called)
188
  bool init_;
197
  bool init_;
189
  // Lockdown the default DACL when creating new tokens.
198
  // Lockdown the default DACL when creating new tokens.
190
  bool lockdown_default_dacl_;
199
  bool lockdown_default_dacl_;
(-)a/security/sandbox/chromium/sandbox/win/src/restricted_token_utils.cc (+17 lines)
Line     Link Here 
 Lines 51-72   DWORD GetObjectSecurityDescriptor(HANDLE Link Here 
51
51
52
}  // namespace
52
}  // namespace
53
53
54
DWORD CreateRestrictedToken(HANDLE effective_token,
54
DWORD CreateRestrictedToken(HANDLE effective_token,
55
                            TokenLevel security_level,
55
                            TokenLevel security_level,
56
                            IntegrityLevel integrity_level,
56
                            IntegrityLevel integrity_level,
57
                            TokenType token_type,
57
                            TokenType token_type,
58
                            bool lockdown_default_dacl,
58
                            bool lockdown_default_dacl,
59
                            PSID unique_restricted_sid,
59
                            bool use_restricting_sids,
60
                            bool use_restricting_sids,
60
                            base::win::ScopedHandle* token) {
61
                            base::win::ScopedHandle* token) {
61
  RestrictedToken restricted_token;
62
  RestrictedToken restricted_token;
62
  restricted_token.Init(effective_token);
63
  restricted_token.Init(effective_token);
63
  if (lockdown_default_dacl)
64
  if (lockdown_default_dacl)
64
    restricted_token.SetLockdownDefaultDacl();
65
    restricted_token.SetLockdownDefaultDacl();
66
  if (unique_restricted_sid) {
67
    restricted_token.AddDefaultDaclSid(Sid(unique_restricted_sid), GRANT_ACCESS,
68
                                       GENERIC_ALL);
69
    restricted_token.AddDefaultDaclSid(Sid(WinCreatorOwnerRightsSid),
70
                                       GRANT_ACCESS, READ_CONTROL);
71
  }
65
72
66
  std::vector<base::string16> privilege_exceptions;
73
  std::vector<base::string16> privilege_exceptions;
67
  std::vector<Sid> sid_exceptions;
74
  std::vector<Sid> sid_exceptions;
68
75
69
  bool deny_sids = true;
76
  bool deny_sids = true;
70
  bool remove_privileges = true;
77
  bool remove_privileges = true;
71
78
72
  switch (security_level) {
79
  switch (security_level) {
 Lines 103-152   DWORD CreateRestrictedToken(HANDLE effec Link Here 
103
      sid_exceptions.push_back(WinAuthenticatedUserSid);
110
      sid_exceptions.push_back(WinAuthenticatedUserSid);
104
      privilege_exceptions.push_back(SE_CHANGE_NOTIFY_NAME);
111
      privilege_exceptions.push_back(SE_CHANGE_NOTIFY_NAME);
105
      if (use_restricting_sids) {
112
      if (use_restricting_sids) {
106
        restricted_token.AddRestrictingSid(WinBuiltinUsersSid);
113
        restricted_token.AddRestrictingSid(WinBuiltinUsersSid);
107
        restricted_token.AddRestrictingSid(WinWorldSid);
114
        restricted_token.AddRestrictingSid(WinWorldSid);
108
        restricted_token.AddRestrictingSid(WinRestrictedCodeSid);
115
        restricted_token.AddRestrictingSid(WinRestrictedCodeSid);
109
        restricted_token.AddRestrictingSidCurrentUser();
116
        restricted_token.AddRestrictingSidCurrentUser();
110
        restricted_token.AddRestrictingSidLogonSession();
117
        restricted_token.AddRestrictingSidLogonSession();
118
        if (unique_restricted_sid)
119
          restricted_token.AddRestrictingSid(Sid(unique_restricted_sid));
111
      }
120
      }
112
      break;
121
      break;
113
    }
122
    }
114
    case USER_LIMITED: {
123
    case USER_LIMITED: {
115
      sid_exceptions.push_back(WinBuiltinUsersSid);
124
      sid_exceptions.push_back(WinBuiltinUsersSid);
116
      sid_exceptions.push_back(WinWorldSid);
125
      sid_exceptions.push_back(WinWorldSid);
117
      sid_exceptions.push_back(WinInteractiveSid);
126
      sid_exceptions.push_back(WinInteractiveSid);
118
      privilege_exceptions.push_back(SE_CHANGE_NOTIFY_NAME);
127
      privilege_exceptions.push_back(SE_CHANGE_NOTIFY_NAME);
119
      if (use_restricting_sids) {
128
      if (use_restricting_sids) {
120
        restricted_token.AddRestrictingSid(WinBuiltinUsersSid);
129
        restricted_token.AddRestrictingSid(WinBuiltinUsersSid);
121
        restricted_token.AddRestrictingSid(WinWorldSid);
130
        restricted_token.AddRestrictingSid(WinWorldSid);
122
        restricted_token.AddRestrictingSid(WinRestrictedCodeSid);
131
        restricted_token.AddRestrictingSid(WinRestrictedCodeSid);
132
        if (unique_restricted_sid)
133
          restricted_token.AddRestrictingSid(Sid(unique_restricted_sid));
123
134
124
        // This token has to be able to create objects in BNO.
135
        // This token has to be able to create objects in BNO.
125
        // Unfortunately, on Vista+, it needs the current logon sid
136
        // Unfortunately, on Vista+, it needs the current logon sid
126
        // in the token to achieve this. You should also set the process to be
137
        // in the token to achieve this. You should also set the process to be
127
        // low integrity level so it can't access object created by other
138
        // low integrity level so it can't access object created by other
128
        // processes.
139
        // processes.
129
        restricted_token.AddRestrictingSidLogonSession();
140
        restricted_token.AddRestrictingSidLogonSession();
141
      } else {
142
        restricted_token.AddUserSidForDenyOnly();
130
      }
143
      }
131
      break;
144
      break;
132
    }
145
    }
133
    case USER_RESTRICTED: {
146
    case USER_RESTRICTED: {
134
      privilege_exceptions.push_back(SE_CHANGE_NOTIFY_NAME);
147
      privilege_exceptions.push_back(SE_CHANGE_NOTIFY_NAME);
135
      restricted_token.AddUserSidForDenyOnly();
148
      restricted_token.AddUserSidForDenyOnly();
136
      if (use_restricting_sids) {
149
      if (use_restricting_sids) {
137
        restricted_token.AddRestrictingSid(WinRestrictedCodeSid);
150
        restricted_token.AddRestrictingSid(WinRestrictedCodeSid);
151
        if (unique_restricted_sid)
152
          restricted_token.AddRestrictingSid(Sid(unique_restricted_sid));
138
      }
153
      }
139
      break;
154
      break;
140
    }
155
    }
141
    case USER_LOCKDOWN: {
156
    case USER_LOCKDOWN: {
142
      restricted_token.AddUserSidForDenyOnly();
157
      restricted_token.AddUserSidForDenyOnly();
143
      if (use_restricting_sids) {
158
      if (use_restricting_sids) {
144
        restricted_token.AddRestrictingSid(WinNullSid);
159
        restricted_token.AddRestrictingSid(WinNullSid);
160
        if (unique_restricted_sid)
161
          restricted_token.AddRestrictingSid(Sid(unique_restricted_sid));
145
      }
162
      }
146
      break;
163
      break;
147
    }
164
    }
148
    default: { return ERROR_BAD_ARGUMENTS; }
165
    default: { return ERROR_BAD_ARGUMENTS; }
149
  }
166
  }
150
167
151
  DWORD err_code = ERROR_SUCCESS;
168
  DWORD err_code = ERROR_SUCCESS;
152
  if (deny_sids) {
169
  if (deny_sids) {
(-)a/security/sandbox/chromium/sandbox/win/src/restricted_token_utils.h (+1 lines)
Line     Link Here 
 Lines 33-48   enum TokenType { IMPERSONATION = 0, PRIM Link Here 
33
// If the function succeeds, the return value is ERROR_SUCCESS. If the
33
// If the function succeeds, the return value is ERROR_SUCCESS. If the
34
// function fails, the return value is the win32 error code corresponding to
34
// function fails, the return value is the win32 error code corresponding to
35
// the error.
35
// the error.
36
DWORD CreateRestrictedToken(HANDLE effective_token,
36
DWORD CreateRestrictedToken(HANDLE effective_token,
37
                            TokenLevel security_level,
37
                            TokenLevel security_level,
38
                            IntegrityLevel integrity_level,
38
                            IntegrityLevel integrity_level,
39
                            TokenType token_type,
39
                            TokenType token_type,
40
                            bool lockdown_default_dacl,
40
                            bool lockdown_default_dacl,
41
                            PSID unique_restricted_sid,
41
                            bool use_restricting_sids,
42
                            bool use_restricting_sids,
42
                            base::win::ScopedHandle* token);
43
                            base::win::ScopedHandle* token);
43
44
44
// Sets the integrity label on a object handle.
45
// Sets the integrity label on a object handle.
45
DWORD SetObjectIntegrityLabel(HANDLE handle,
46
DWORD SetObjectIntegrityLabel(HANDLE handle,
46
                              SE_OBJECT_TYPE type,
47
                              SE_OBJECT_TYPE type,
47
                              const wchar_t* ace_access,
48
                              const wchar_t* ace_access,
48
                              const wchar_t* integrity_level_sid);
49
                              const wchar_t* integrity_level_sid);
(-)a/security/sandbox/chromium/sandbox/win/src/sandbox_policy.h (+4 lines)
Line     Link Here 
 Lines 253-268   class TargetPolicy { Link Here 
253
  // ownership of the handle.
253
  // ownership of the handle.
254
  virtual void AddHandleToShare(HANDLE handle) = 0;
254
  virtual void AddHandleToShare(HANDLE handle) = 0;
255
255
256
  // Locks down the default DACL of the created lockdown and initial tokens
256
  // Locks down the default DACL of the created lockdown and initial tokens
257
  // to restrict what other processes are allowed to access a process' kernel
257
  // to restrict what other processes are allowed to access a process' kernel
258
  // resources.
258
  // resources.
259
  virtual void SetLockdownDefaultDacl() = 0;
259
  virtual void SetLockdownDefaultDacl() = 0;
260
260
261
  // Adds a restricting random SID to the restricted SIDs list as well as
262
  // the default DACL.
263
  virtual void AddRestrictingRandomSid() = 0;
264
261
  // Enable OPM API redirection when in Win32k lockdown.
265
  // Enable OPM API redirection when in Win32k lockdown.
262
  virtual void SetEnableOPMRedirection() = 0;
266
  virtual void SetEnableOPMRedirection() = 0;
263
  // Enable OPM API emulation when in Win32k lockdown.
267
  // Enable OPM API emulation when in Win32k lockdown.
264
  virtual bool GetEnableOPMRedirection() = 0;
268
  virtual bool GetEnableOPMRedirection() = 0;
265
269
266
  // Configure policy to use an AppContainer profile. |package_name| is the
270
  // Configure policy to use an AppContainer profile. |package_name| is the
267
  // name of the profile to use. Specifying True for |create_profile| ensures
271
  // name of the profile to use. Specifying True for |create_profile| ensures
268
  // the profile exists, if set to False process creation will fail if the
272
  // the profile exists, if set to False process creation will fail if the
(-)a/security/sandbox/chromium/sandbox/win/src/sandbox_policy_base.cc (-8 / +16 lines)
Line     Link Here 
 Lines 102-117   PolicyBase::PolicyBase() Link Here 
102
      delayed_integrity_level_(INTEGRITY_LEVEL_LAST),
102
      delayed_integrity_level_(INTEGRITY_LEVEL_LAST),
103
      mitigations_(0),
103
      mitigations_(0),
104
      delayed_mitigations_(0),
104
      delayed_mitigations_(0),
105
      is_csrss_connected_(true),
105
      is_csrss_connected_(true),
106
      policy_maker_(nullptr),
106
      policy_maker_(nullptr),
107
      policy_(nullptr),
107
      policy_(nullptr),
108
      lowbox_sid_(nullptr),
108
      lowbox_sid_(nullptr),
109
      lockdown_default_dacl_(false),
109
      lockdown_default_dacl_(false),
110
      add_restricting_random_sid_(false),
110
      enable_opm_redirection_(false),
111
      enable_opm_redirection_(false),
111
      effective_token_(nullptr) {
112
      effective_token_(nullptr) {
112
  ::InitializeCriticalSection(&lock_);
113
  ::InitializeCriticalSection(&lock_);
113
  dispatcher_.reset(new TopLevelDispatcher(this));
114
  dispatcher_.reset(new TopLevelDispatcher(this));
114
}
115
}
115
116
116
PolicyBase::~PolicyBase() {
117
PolicyBase::~PolicyBase() {
117
  TargetSet::iterator it;
118
  TargetSet::iterator it;
 Lines 378-393   void PolicyBase::AddHandleToShare(HANDLE Link Here 
378
379
379
  handles_to_share_.push_back(handle);
380
  handles_to_share_.push_back(handle);
380
}
381
}
381
382
382
void PolicyBase::SetLockdownDefaultDacl() {
383
void PolicyBase::SetLockdownDefaultDacl() {
383
  lockdown_default_dacl_ = true;
384
  lockdown_default_dacl_ = true;
384
}
385
}
385
386
387
void PolicyBase::AddRestrictingRandomSid() {
388
  add_restricting_random_sid_ = true;
389
}
390
386
const base::HandlesToInheritVector& PolicyBase::GetHandlesBeingShared() {
391
const base::HandlesToInheritVector& PolicyBase::GetHandlesBeingShared() {
387
  return handles_to_share_;
392
  return handles_to_share_;
388
}
393
}
389
394
390
ResultCode PolicyBase::MakeJobObject(base::win::ScopedHandle* job) {
395
ResultCode PolicyBase::MakeJobObject(base::win::ScopedHandle* job) {
391
  if (job_level_ == JOB_NONE) {
396
  if (job_level_ == JOB_NONE) {
392
    job->Close();
397
    job->Close();
393
    return SBOX_ALL_OK;
398
    return SBOX_ALL_OK;
 Lines 402-423   ResultCode PolicyBase::MakeJobObject(bas Link Here 
402
407
403
  *job = job_obj.Take();
408
  *job = job_obj.Take();
404
  return SBOX_ALL_OK;
409
  return SBOX_ALL_OK;
405
}
410
}
406
411
407
ResultCode PolicyBase::MakeTokens(base::win::ScopedHandle* initial,
412
ResultCode PolicyBase::MakeTokens(base::win::ScopedHandle* initial,
408
                                  base::win::ScopedHandle* lockdown,
413
                                  base::win::ScopedHandle* lockdown,
409
                                  base::win::ScopedHandle* lowbox) {
414
                                  base::win::ScopedHandle* lowbox) {
415
  Sid random_sid = Sid::GenerateRandomSid();
416
  PSID random_sid_ptr = nullptr;
417
  if (add_restricting_random_sid_)
418
    random_sid_ptr = random_sid.GetPSID();
419
410
  // Create the 'naked' token. This will be the permanent token associated
420
  // Create the 'naked' token. This will be the permanent token associated
411
  // with the process and therefore with any thread that is not impersonating.
421
  // with the process and therefore with any thread that is not impersonating.
412
  DWORD result =
422
  DWORD result = CreateRestrictedToken(
413
      CreateRestrictedToken(effective_token_, lockdown_level_, integrity_level_,
423
      effective_token_, lockdown_level_, integrity_level_, PRIMARY,
414
                            PRIMARY, lockdown_default_dacl_,
424
      lockdown_default_dacl_, random_sid_ptr, use_restricting_sids_, lockdown);
415
                            use_restricting_sids_, lockdown);
416
  if (ERROR_SUCCESS != result)
425
  if (ERROR_SUCCESS != result)
417
    return SBOX_ERROR_GENERIC;
426
    return SBOX_ERROR_GENERIC;
418
427
419
  // If we're launching on the alternate desktop we need to make sure the
428
  // If we're launching on the alternate desktop we need to make sure the
420
  // integrity label on the object is no higher than the sandboxed process's
429
  // integrity label on the object is no higher than the sandboxed process's
421
  // integrity level. So, we lower the label on the desktop process if it's
430
  // integrity level. So, we lower the label on the desktop process if it's
422
  // not already low enough for our process.
431
  // not already low enough for our process.
423
  if (use_alternate_desktop_ && integrity_level_ != INTEGRITY_LEVEL_LAST) {
432
  if (use_alternate_desktop_ && integrity_level_ != INTEGRITY_LEVEL_LAST) {
 Lines 469-488   ResultCode PolicyBase::MakeTokens(base:: Link Here 
469
                          saved_handles_count, lowbox) != ERROR_SUCCESS) {
478
                          saved_handles_count, lowbox) != ERROR_SUCCESS) {
470
      return SBOX_ERROR_GENERIC;
479
      return SBOX_ERROR_GENERIC;
471
    }
480
    }
472
  }
481
  }
473
482
474
  // Create the 'better' token. We use this token as the one that the main
483
  // Create the 'better' token. We use this token as the one that the main
475
  // thread uses when booting up the process. It should contain most of
484
  // thread uses when booting up the process. It should contain most of
476
  // what we need (before reaching main( ))
485
  // what we need (before reaching main( ))
477
  result =
486
  result = CreateRestrictedToken(
478
      CreateRestrictedToken(effective_token_, initial_level_, integrity_level_,
487
      effective_token_, initial_level_, integrity_level_, IMPERSONATION,
479
                            IMPERSONATION, lockdown_default_dacl_,
488
      lockdown_default_dacl_, random_sid_ptr, use_restricting_sids_, initial);
480
                            use_restricting_sids_, initial);
481
  if (ERROR_SUCCESS != result)
489
  if (ERROR_SUCCESS != result)
482
    return SBOX_ERROR_GENERIC;
490
    return SBOX_ERROR_GENERIC;
483
491
484
  return SBOX_ALL_OK;
492
  return SBOX_ALL_OK;
485
}
493
}
486
494
487
PSID PolicyBase::GetLowBoxSid() const {
495
PSID PolicyBase::GetLowBoxSid() const {
488
  return lowbox_sid_;
496
  return lowbox_sid_;
(-)a/security/sandbox/chromium/sandbox/win/src/sandbox_policy_base.h (+2 lines)
Line     Link Here 
 Lines 68-83   class PolicyBase final : public TargetPo Link Here 
68
  ResultCode AddRule(SubSystem subsystem,
68
  ResultCode AddRule(SubSystem subsystem,
69
                     Semantics semantics,
69
                     Semantics semantics,
70
                     const wchar_t* pattern) override;
70
                     const wchar_t* pattern) override;
71
  ResultCode AddDllToUnload(const wchar_t* dll_name) override;
71
  ResultCode AddDllToUnload(const wchar_t* dll_name) override;
72
  ResultCode AddKernelObjectToClose(const base::char16* handle_type,
72
  ResultCode AddKernelObjectToClose(const base::char16* handle_type,
73
                                    const base::char16* handle_name) override;
73
                                    const base::char16* handle_name) override;
74
  void AddHandleToShare(HANDLE handle) override;
74
  void AddHandleToShare(HANDLE handle) override;
75
  void SetLockdownDefaultDacl() override;
75
  void SetLockdownDefaultDacl() override;
76
  void AddRestrictingRandomSid() override;
76
  void SetEnableOPMRedirection() override;
77
  void SetEnableOPMRedirection() override;
77
  bool GetEnableOPMRedirection() override;
78
  bool GetEnableOPMRedirection() override;
78
  ResultCode AddAppContainerProfile(const wchar_t* package_name,
79
  ResultCode AddAppContainerProfile(const wchar_t* package_name,
79
                                    bool create_profile) override;
80
                                    bool create_profile) override;
80
  scoped_refptr<AppContainerProfile> GetAppContainerProfile() override;
81
  scoped_refptr<AppContainerProfile> GetAppContainerProfile() override;
81
  void SetEffectiveToken(HANDLE token) override;
82
  void SetEffectiveToken(HANDLE token) override;
82
83
83
  // Get the AppContainer profile as its internal type.
84
  // Get the AppContainer profile as its internal type.
 Lines 162-177   class PolicyBase final : public TargetPo Link Here 
162
  // This is a map of handle-types to names that we need to close in the
163
  // This is a map of handle-types to names that we need to close in the
163
  // target process. A null set means we need to close all handles of the
164
  // target process. A null set means we need to close all handles of the
164
  // given type.
165
  // given type.
165
  HandleCloser handle_closer_;
166
  HandleCloser handle_closer_;
166
  PSID lowbox_sid_;
167
  PSID lowbox_sid_;
167
  base::win::ScopedHandle lowbox_directory_;
168
  base::win::ScopedHandle lowbox_directory_;
168
  std::unique_ptr<Dispatcher> dispatcher_;
169
  std::unique_ptr<Dispatcher> dispatcher_;
169
  bool lockdown_default_dacl_;
170
  bool lockdown_default_dacl_;
171
  bool add_restricting_random_sid_;
170
172
171
  static HDESK alternate_desktop_handle_;
173
  static HDESK alternate_desktop_handle_;
172
  static HWINSTA alternate_winstation_handle_;
174
  static HWINSTA alternate_winstation_handle_;
173
  static HDESK alternate_desktop_local_winstation_handle_;
175
  static HDESK alternate_desktop_local_winstation_handle_;
174
  static IntegrityLevel alternate_desktop_integrity_level_label_;
176
  static IntegrityLevel alternate_desktop_integrity_level_label_;
175
  static IntegrityLevel
177
  static IntegrityLevel
176
      alternate_desktop_local_winstation_integrity_level_label_;
178
      alternate_desktop_local_winstation_integrity_level_label_;
177
179
(-)a/security/sandbox/chromium/sandbox/win/src/sid.cc (+10 lines)
Line     Link Here 
 Lines 2-19    Link Here 
2
// Use of this source code is governed by a BSD-style license that can be
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
3
// found in the LICENSE file.
4
4
5
#include "sandbox/win/src/sid.h"
5
#include "sandbox/win/src/sid.h"
6
6
7
#include <memory>
7
#include <memory>
8
8
9
#include <sddl.h>
9
#include <sddl.h>
10
#include <stdlib.h>
10
11
11
#include "base/logging.h"
12
#include "base/logging.h"
13
#include "base/rand_util.h"
12
#include "base/win/windows_version.h"
14
#include "base/win/windows_version.h"
13
#include "sandbox/win/src/win_utils.h"
15
#include "sandbox/win/src/win_utils.h"
14
16
15
namespace sandbox {
17
namespace sandbox {
16
18
17
namespace {
19
namespace {
18
20
19
DWORD WellKnownCapabilityToRid(WellKnownCapabilities capability) {
21
DWORD WellKnownCapabilityToRid(WellKnownCapabilities capability) {
 Lines 127-142   Sid Sid::FromSubAuthorities(PSID_IDENTIF Link Here 
127
129
128
Sid Sid::AllRestrictedApplicationPackages() {
130
Sid Sid::AllRestrictedApplicationPackages() {
129
  SID_IDENTIFIER_AUTHORITY package_authority = {SECURITY_APP_PACKAGE_AUTHORITY};
131
  SID_IDENTIFIER_AUTHORITY package_authority = {SECURITY_APP_PACKAGE_AUTHORITY};
130
  DWORD sub_authorities[] = {SECURITY_APP_PACKAGE_BASE_RID,
132
  DWORD sub_authorities[] = {SECURITY_APP_PACKAGE_BASE_RID,
131
                             SECURITY_BUILTIN_PACKAGE_ANY_RESTRICTED_PACKAGE};
133
                             SECURITY_BUILTIN_PACKAGE_ANY_RESTRICTED_PACKAGE};
132
  return FromSubAuthorities(&package_authority, 2, sub_authorities);
134
  return FromSubAuthorities(&package_authority, 2, sub_authorities);
133
}
135
}
134
136
137
Sid Sid::GenerateRandomSid() {
138
  SID_IDENTIFIER_AUTHORITY package_authority = {SECURITY_NULL_SID_AUTHORITY};
139
  DWORD sub_authorities[4] = {};
140
  base::RandBytes(&sub_authorities, sizeof(sub_authorities));
141
  return FromSubAuthorities(&package_authority, _countof(sub_authorities),
142
                            sub_authorities);
143
}
144
135
PSID Sid::GetPSID() const {
145
PSID Sid::GetPSID() const {
136
  return const_cast<BYTE*>(sid_);
146
  return const_cast<BYTE*>(sid_);
137
}
147
}
138
148
139
bool Sid::IsValid() const {
149
bool Sid::IsValid() const {
140
  return !!::IsValidSid(GetPSID());
150
  return !!::IsValidSid(GetPSID());
141
}
151
}
142
152
(-)a/security/sandbox/chromium/sandbox/win/src/sid.h (+2 lines)
Line     Link Here 
 Lines 47-62   class Sid { Link Here 
47
  // Create a Sid from a SDDL format string, such as S-1-1-0.
47
  // Create a Sid from a SDDL format string, such as S-1-1-0.
48
  static Sid FromSddlString(const wchar_t* sddl_sid);
48
  static Sid FromSddlString(const wchar_t* sddl_sid);
49
  // Create a Sid from a set of sub authorities.
49
  // Create a Sid from a set of sub authorities.
50
  static Sid FromSubAuthorities(PSID_IDENTIFIER_AUTHORITY identifier_authority,
50
  static Sid FromSubAuthorities(PSID_IDENTIFIER_AUTHORITY identifier_authority,
51
                                BYTE sub_authority_count,
51
                                BYTE sub_authority_count,
52
                                PDWORD sub_authorities);
52
                                PDWORD sub_authorities);
53
  // Create the restricted all application packages sid.
53
  // Create the restricted all application packages sid.
54
  static Sid AllRestrictedApplicationPackages();
54
  static Sid AllRestrictedApplicationPackages();
55
  // Generate a random SID value.
56
  static Sid GenerateRandomSid();
55
57
56
  // Returns sid_.
58
  // Returns sid_.
57
  PSID GetPSID() const;
59
  PSID GetPSID() const;
58
60
59
  // Gets whether the sid is valid.
61
  // Gets whether the sid is valid.
60
  bool IsValid() const;
62
  bool IsValid() const;
61
63
62
  // Converts the SID to a SDDL format string.
64
  // Converts the SID to a SDDL format string.

Return to bug 1618911