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

Unified Diff: sandbox/win/src/handle_closer_agent.cc

Issue 919893002: Replace handles that the handle closer closes with dummy Events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: only stuff events and file handles Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/win/src/handle_closer_agent.cc
diff --git a/sandbox/win/src/handle_closer_agent.cc b/sandbox/win/src/handle_closer_agent.cc
index 07c6a09854d2d5355a84f30f782ec57f1a04f3ab..26f0a73e03c87b6f005d62e655861837fa3df9ae 100644
--- a/sandbox/win/src/handle_closer_agent.cc
+++ b/sandbox/win/src/handle_closer_agent.cc
@@ -30,6 +30,44 @@ NTSTATUS QueryObjectTypeInformation(HANDLE handle,
return status;
}
+bool AttemptToStuffHandleSlot(HANDLE to_stuff, const base::string16& type) {
cpu_(ooo_6.6-7.5) 2015/02/18 18:00:00 to_stuff -> closed_handle ?
Will Harris 2015/02/18 22:11:28 Done.
+ // Only attempt to stuff Files and Events at the moment.
+ if (type != L"Event" &&
+ type != L"File") {
+ return true;
+ }
+
+ HANDLE dummy = ::CreateEvent(NULL, FALSE, FALSE, NULL);
forshaw 2015/02/18 10:50:10 Can we just use one event object for all stuffed h
cpu_(ooo_6.6-7.5) 2015/02/18 18:00:00 given that is single threaded we can indeed use a
Will Harris 2015/02/18 22:11:29 we can't create the template handle static in this
+
+ if (dummy == INVALID_HANDLE_VALUE)
forshaw 2015/02/18 10:50:10 While unlikely to fail CreateEvent actually return
Will Harris 2015/02/18 22:11:29 Done.
+ return false;
+
+ std::vector<HANDLE> to_close;
+ DWORD options = DUPLICATE_SAME_ACCESS;
Sigurður Ásgeirsson 2015/02/18 13:56:00 looks pretty reasonable - you may want to document
Will Harris 2015/02/18 22:11:29 changed this to 0 access as per other comments.
+
+ while (reinterpret_cast<uintptr_t>(dummy) <
+ reinterpret_cast<uintptr_t>(to_stuff)) {
+ HANDLE dup_dummy;
cpu_(ooo_6.6-7.5) 2015/02/18 18:00:00 move dup_dummy below 51
Will Harris 2015/02/18 22:11:29 Acknowledged.
+ to_close.push_back(dummy);
+
+ if (!::DuplicateHandle(::GetCurrentProcess(), dummy, ::GetCurrentProcess(),
+ &dup_dummy, 0, false, options))
+ break;
Sigurður Ásgeirsson 2015/02/18 19:02:47 come to think of it, another check you may want to
Will Harris 2015/02/18 22:11:28 We can't do this because we don't know if the hand
+ dummy = dup_dummy;
+ }
+
+ if (dummy != to_stuff)
+ to_close.push_back(dummy);
+
+ for (auto h : to_close)
+ ::CloseHandle(h);
+
+ // We want to know when we're not able to stuff handles.
+ DCHECK(dummy == to_stuff);
+
+ return dummy == to_stuff;
+}
+
} // namespace
namespace sandbox {
@@ -136,6 +174,8 @@ bool HandleCloserAgent::CloseHandles() {
return false;
if (!::CloseHandle(handle))
return false;
+ // Attempt to stuff this handle with a new empty Event.
cpu_(ooo_6.6-7.5) 2015/02/18 18:00:00 "new dummy event"
Will Harris 2015/02/18 22:11:29 Done.
+ AttemptToStuffHandleSlot(handle, result->first);
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698