Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: content/common/sandbox_win.cc

Issue 2672003002: Remove the --allow-no-sandbox-job flag in favor of automatic recognition. (Closed)
Patch Set: add todo. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
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 "content/common/sandbox_win.h" 5 #include "content/common/sandbox_win.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 sizeof(session_id), &session_id_length)); 243 sizeof(session_id), &session_id_length));
244 CloseHandle(token); 244 CloseHandle(token);
245 if (session_id) 245 if (session_id)
246 s_session_id = session_id; 246 s_session_id = session_id;
247 } 247 }
248 248
249 return base::StringPrintf(L"\\Sessions\\%lu%ls", s_session_id, object); 249 return base::StringPrintf(L"\\Sessions\\%lu%ls", s_session_id, object);
250 } 250 }
251 251
252 // Checks if the sandbox should be let to run without a job object assigned. 252 // Checks if the sandbox should be let to run without a job object assigned.
253 bool ShouldSetJobLevel(const base::CommandLine& cmd_line) { 253 bool ShouldSetJobLevel(const base::CommandLine& cmd_line) {
Will Harris 2017/02/13 18:28:55 so behavior before was that if --allow-no-sandbox-
254 if (!cmd_line.HasSwitch(switches::kAllowNoSandboxJob))
255 return true;
256
257 // Windows 8 allows nested jobs so we don't need to check if we are in other 254 // Windows 8 allows nested jobs so we don't need to check if we are in other
258 // job. 255 // job.
259 if (base::win::GetVersion() >= base::win::VERSION_WIN8) 256 if (base::win::GetVersion() >= base::win::VERSION_WIN8)
260 return true; 257 return true;
261 258
262 BOOL in_job = true; 259 BOOL in_job = true;
263 // Either there is no job yet associated so we must add our job, 260 // Either there is no job yet associated so we must add our job,
264 if (!::IsProcessInJob(::GetCurrentProcess(), NULL, &in_job)) 261 if (!::IsProcessInJob(::GetCurrentProcess(), NULL, &in_job))
265 NOTREACHED() << "IsProcessInJob failed. " << GetLastError(); 262 NOTREACHED() << "IsProcessInJob failed. " << GetLastError();
266 if (!in_job) 263 if (!in_job)
267 return true; 264 return true;
268 265
269 // ...or there is a job but the JOB_OBJECT_LIMIT_BREAKAWAY_OK limit is set. 266 // ...or there is a job but the JOB_OBJECT_LIMIT_BREAKAWAY_OK limit is set.
270 JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info = {}; 267 JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info = {};
271 if (!::QueryInformationJobObject(NULL, 268 if (!::QueryInformationJobObject(NULL,
272 JobObjectExtendedLimitInformation, &job_info, 269 JobObjectExtendedLimitInformation, &job_info,
273 sizeof(job_info), NULL)) { 270 sizeof(job_info), NULL)) {
274 NOTREACHED() << "QueryInformationJobObject failed. " << GetLastError(); 271 NOTREACHED() << "QueryInformationJobObject failed. " << GetLastError();
275 return true; 272 return true;
Will Harris 2017/02/10 18:45:35 are you sure that one of these earlier tests won't
pastarmovj 2017/02/13 12:26:41 It is not setting the breakaway flag unfortunately
276 } 273 }
277 if (job_info.BasicLimitInformation.LimitFlags & JOB_OBJECT_LIMIT_BREAKAWAY_OK) 274 if (job_info.BasicLimitInformation.LimitFlags & JOB_OBJECT_LIMIT_BREAKAWAY_OK)
278 return true; 275 return true;
279 276
277 // Lastly in place of the flag which was supposed to be used only for running
278 // Chrome in remote sessions we do this check explicitly here.
279 // According to MS this flag can be false for a remote session only on Windows
280 // Server 2012 and newer so if we do the check last we should be on the safe
281 // side. See: https://msdn.microsoft.com/en-us/library/aa380798.aspx.
282 if (!::GetSystemMetrics(SM_REMOTESESSION)) {
283 // Measure how often we would have decided to apply the sandbox but the
284 // user actually wanted to avoid it.
285 // TODO(pastarmovj): Remove this check and the flag altogher once we are
Will Harris 2017/02/10 18:45:35 nit: typo
pastarmovj 2017/02/14 12:10:33 Done.
286 // convinced that the automatic logic is good enough.
287 if (cmd_line.HasSwitch(switches::kAllowNoSandboxJob)) {
288 UMA_HISTOGRAM_BOOLEAN("Process.Sandbox.JobAvoidedCorrectly", false);
Will Harris 2017/02/10 18:45:35 I'd prefer to record this histogram all the time a
pastarmovj 2017/02/13 12:26:41 As the histogram is worded now it is collected eve
Will Harris 2017/02/13 18:28:55 normally best practice for histograms is to always
pastarmovj 2017/02/14 12:10:33 Agree. Moved that to the calling function.
289 return false;
290 }
291 return true;
292 }
293
294 // Allow running without the sandbox in this case. This slightly reduces the
295 // ability of the sandbox to protect its children from spawning new processes
296 // or preventing them from shutting down Windows or accessing the clipboard.
297 UMA_HISTOGRAM_BOOLEAN("Process.Sandbox.JobAvoidedCorrectly", true);
280 return false; 298 return false;
281 } 299 }
282 300
283 // Adds the generic policy rules to a sandbox TargetPolicy. 301 // Adds the generic policy rules to a sandbox TargetPolicy.
284 sandbox::ResultCode AddGenericPolicy(sandbox::TargetPolicy* policy) { 302 sandbox::ResultCode AddGenericPolicy(sandbox::TargetPolicy* policy) {
285 sandbox::ResultCode result; 303 sandbox::ResultCode result;
286 304
287 // Add the policy for the client side of a pipe. It is just a file 305 // Add the policy for the client side of a pipe. It is just a file
288 // in the \pipe\ namespace. We restrict it to pipes that start with 306 // in the \pipe\ namespace. We restrict it to pipes that start with
289 // "chrome." so the sandboxed process cannot connect to system services. 307 // "chrome." so the sandboxed process cannot connect to system services.
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 } 851 }
834 852
835 delegate->PostSpawnTarget(target.process_handle()); 853 delegate->PostSpawnTarget(target.process_handle());
836 854
837 CHECK(ResumeThread(target.thread_handle()) != static_cast<DWORD>(-1)); 855 CHECK(ResumeThread(target.thread_handle()) != static_cast<DWORD>(-1));
838 *process = base::Process(target.TakeProcessHandle()); 856 *process = base::Process(target.TakeProcessHandle());
839 return sandbox::SBOX_ALL_OK; 857 return sandbox::SBOX_ALL_OK;
840 } 858 }
841 859
842 } // namespace content 860 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698