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

Issue 1113063004: Add HANDLE_FLAG_PROTECT_FROM_CLOSE flag to Tracked/ScopedHandle. (Closed)

Created:
5 years, 7 months ago by Shrikant Kelkar
Modified:
5 years, 5 months ago
CC:
chromium-reviews, grt+watch_chromium.org, erikwright+watch_chromium.org, wfh+watch_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Add HANDLE_FLAG_PROTECT_FROM_CLOSE flag to Tracked/ScopedHandle. Idea here is to try and protect our scoped handles so that any third party close/accidental close could be some what restricted. Besides adding flag following changes are in this CL. 1. While launching test process (Python executable), we pass it a pipe handle which we add it to ScopedHandle before passing, this marked handle as protected, now when we let python process inherit that handle, python process cannot close it and throws exception. We now duplicate handle without protection and then pass it onto python process and let host process continue with protected scoped handle. 2. Other change is related to disabling of active verifier dynamically. If ActiveVerifier gets invoked before disabling it (because someone used scoped handle before instruction pointer reached to UseHooks/InstallCloseHandleHooks) then it protects handle from closing. If now we disable ActiveVerifier when scoped handle goes out of scope, it tries to stop tracking handle, but in this case as active verifier got disabled later, that particular handle remains protected. Now we don't disable active verifier dynamically, but just decide on setting up of CloseHandleHook based on certain parameters. BUG=475872 R=cpu@chromium.org,rvargas@chromium.org Committed: https://crrev.com/c928d34ee861fd4102c352d9e79e1a4959a47209 Cr-Commit-Position: refs/heads/master@{#329516}

Patch Set 1 #

Total comments: 13

Patch Set 2 : Code review #

Patch Set 3 : Removed empty line #

Total comments: 2

Patch Set 4 : Code review comments. #

Patch Set 5 : Removed GetHandle checking before CHECK and separated out Verifier->Disable #

Patch Set 6 : Added check if SetHandleInfo fails. #

Patch Set 7 : Reduced scope of changes to only deal with valid handles. #

Total comments: 1

Patch Set 8 : Removed error checking for SetHandleInfo. #

Patch Set 9 : Duplicating handle before spawning process with INHERIT. #

Patch Set 10 : Added unknown chrome channel when setting up CloseHandle hooks for trybots. #

Patch Set 11 : Removed dynamic disabling of ActiveVerifier. #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+22 lines, -5 lines) Patch
M base/win/scoped_handle.cc View 1 2 3 4 5 6 7 2 chunks +15 lines, -0 lines 2 comments Download
M chrome/app/close_handle_hook_win.cc View 1 2 3 4 5 6 7 8 9 10 2 chunks +2 lines, -3 lines 0 comments Download
M net/test/spawned_test_server/local_test_server_win.cc View 1 2 3 4 5 6 7 8 2 chunks +5 lines, -2 lines 0 comments Download

Messages

Total messages: 44 (8 generated)
Shrikant Kelkar
5 years, 7 months ago (2015-04-30 23:25:25 UTC) #2
rvargas (doing something else)
drive-by (no comments on the actual meat of the change) https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc File base/win/scoped_handle.cc (left): https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc#oldcode138 ...
5 years, 7 months ago (2015-04-30 23:57:17 UTC) #3
Will Harris
https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc File base/win/scoped_handle.cc (right): https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc#newcode165 base/win/scoped_handle.cc:165: I don't think you can call SetHandleInformation on all ...
5 years, 7 months ago (2015-05-01 00:03:46 UTC) #5
Shrikant Kelkar
https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc File base/win/scoped_handle.cc (right): https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc#newcode223 base/win/scoped_handle.cc:223: return; On 2015/04/30 23:57:16, rvargas (out of office) wrote: ...
5 years, 7 months ago (2015-05-01 00:06:48 UTC) #6
Shrikant Kelkar
On 2015/05/01 00:03:46, Will Harris wrote: > https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc > File base/win/scoped_handle.cc (right): > > https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc#newcode165 ...
5 years, 7 months ago (2015-05-01 00:11:34 UTC) #7
cpu_(ooo_6.6-7.5)
https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc File base/win/scoped_handle.cc (right): https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc#newcode164 base/win/scoped_handle.cc:164: HANDLE_FLAG_PROTECT_FROM_CLOSE); this can be done outside the lock. https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc#newcode165 ...
5 years, 7 months ago (2015-05-01 00:42:52 UTC) #8
Shrikant Kelkar
https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc File base/win/scoped_handle.cc (left): https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc#oldcode138 base/win/scoped_handle.cc:138: g_active_verifier->Disable(); On 2015/04/30 23:57:17, rvargas (out of office) wrote: ...
5 years, 7 months ago (2015-05-01 00:57:31 UTC) #9
grt (UTC plus 2)
drive-by style comment https://codereview.chromium.org/1113063004/diff/40001/base/win/scoped_handle.cc File base/win/scoped_handle.cc (right): https://codereview.chromium.org/1113063004/diff/40001/base/win/scoped_handle.cc#newcode182 base/win/scoped_handle.cc:182: if (!(flags & HANDLE_FLAG_PROTECT_FROM_CLOSE)) minor style ...
5 years, 7 months ago (2015-05-01 13:26:14 UTC) #10
Shrikant Kelkar
https://codereview.chromium.org/1113063004/diff/40001/base/win/scoped_handle.cc File base/win/scoped_handle.cc (right): https://codereview.chromium.org/1113063004/diff/40001/base/win/scoped_handle.cc#newcode182 base/win/scoped_handle.cc:182: if (!(flags & HANDLE_FLAG_PROTECT_FROM_CLOSE)) On 2015/05/01 13:26:14, grt wrote: ...
5 years, 7 months ago (2015-05-01 17:48:42 UTC) #11
Will Harris
https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc File base/win/scoped_handle.cc (right): https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc#newcode165 base/win/scoped_handle.cc:165: On 2015/05/01 00:42:51, cpu wrote: > On 2015/05/01 00:03:45, ...
5 years, 7 months ago (2015-05-03 21:55:19 UTC) #12
Shrikant Kelkar
On 2015/05/03 21:55:19, Will Harris wrote: > https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc > File base/win/scoped_handle.cc (right): > > https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc#newcode165 ...
5 years, 7 months ago (2015-05-03 23:59:56 UTC) #13
Shrikant Kelkar
Removed GetHandleInfo before CHECK and separated out (already checked-in) Verifier->Disable in different CL. ptal.
5 years, 7 months ago (2015-05-05 22:55:40 UTC) #14
rvargas (doing something else)
https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc File base/win/scoped_handle.cc (right): https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc#newcode165 base/win/scoped_handle.cc:165: On 2015/05/03 21:55:19, Will Harris wrote: > On 2015/05/01 ...
5 years, 7 months ago (2015-05-06 01:47:23 UTC) #15
Will Harris
On 2015/05/06 01:47:23, rvargas (out of office) wrote: > https://codereview.chromium.org/1113063004/diff/1/base/win/scoped_handle.cc > File base/win/scoped_handle.cc (right): > ...
5 years, 7 months ago (2015-05-06 02:18:24 UTC) #16
Shrikant Kelkar
Added CHECK() if SetHandleInfo fails.
5 years, 7 months ago (2015-05-06 18:40:42 UTC) #17
cpu_(ooo_6.6-7.5)
lgtm
5 years, 7 months ago (2015-05-06 20:37:19 UTC) #18
cpu_(ooo_6.6-7.5)
lgtm
5 years, 7 months ago (2015-05-06 20:37:20 UTC) #19
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1113063004/100001
5 years, 7 months ago (2015-05-06 20:37:58 UTC) #21
commit-bot: I haz the power
Try jobs failed on following builders: win8_chromium_rel on tryserver.chromium.win (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.win/builders/win8_chromium_rel/builds/81009)
5 years, 7 months ago (2015-05-07 00:31:12 UTC) #23
Shrikant Kelkar
Reduced scope of CL to deal with only valid handles. Unit tests failed (Especially ScopedProcessInformation) ...
5 years, 7 months ago (2015-05-07 21:13:46 UTC) #24
cpu_(ooo_6.6-7.5)
https://codereview.chromium.org/1113063004/diff/120001/base/win/scoped_handle.cc File base/win/scoped_handle.cc (right): https://codereview.chromium.org/1113063004/diff/120001/base/win/scoped_handle.cc#newcode163 base/win/scoped_handle.cc:163: if (error != ERROR_INVALID_HANDLE) { what other error would ...
5 years, 7 months ago (2015-05-08 02:45:19 UTC) #25
Shrikant Kelkar
On 2015/05/08 02:45:19, cpu wrote: > https://codereview.chromium.org/1113063004/diff/120001/base/win/scoped_handle.cc > File base/win/scoped_handle.cc (right): > > https://codereview.chromium.org/1113063004/diff/120001/base/win/scoped_handle.cc#newcode163 > ...
5 years, 7 months ago (2015-05-08 19:43:03 UTC) #26
cpu_(ooo_6.6-7.5)
ok, lgtm as is. let me know if you are changing it again.
5 years, 7 months ago (2015-05-08 19:53:00 UTC) #27
Shrikant Kelkar
On 2015/05/08 19:53:00, cpu wrote: > ok, lgtm as is. let me know if you ...
5 years, 7 months ago (2015-05-08 22:07:43 UTC) #28
Shrikant Kelkar
5 years, 7 months ago (2015-05-10 05:35:13 UTC) #29
Shrikant Kelkar
Finally bots are green. Newly added both changes are related, would like to keep them ...
5 years, 7 months ago (2015-05-10 17:44:13 UTC) #30
cpu_(ooo_6.6-7.5)
lgtm
5 years, 7 months ago (2015-05-11 20:31:59 UTC) #31
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1113063004/180001
5 years, 7 months ago (2015-05-11 20:32:39 UTC) #33
commit-bot: I haz the power
Try jobs failed on following builders: win_chromium_x64_rel_ng on tryserver.chromium.win (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.win/builders/win_chromium_x64_rel_ng/builds/56103)
5 years, 7 months ago (2015-05-12 00:15:00 UTC) #35
Shrikant Kelkar
Now both x86 and x64 bots seem to be happy. Please let me know if ...
5 years, 7 months ago (2015-05-12 19:36:48 UTC) #36
cpu_(ooo_6.6-7.5)
can you add a paragraph in the CL description about the change including the last ...
5 years, 7 months ago (2015-05-12 21:23:09 UTC) #37
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1113063004/200001
5 years, 7 months ago (2015-05-12 21:40:11 UTC) #39
commit-bot: I haz the power
Committed patchset #11 (id:200001)
5 years, 7 months ago (2015-05-12 22:29:05 UTC) #40
commit-bot: I haz the power
Patchset 11 (id:??) landed as https://crrev.com/c928d34ee861fd4102c352d9e79e1a4959a47209 Cr-Commit-Position: refs/heads/master@{#329516}
5 years, 7 months ago (2015-05-12 22:29:57 UTC) #41
Sébastien Marchand
One comment / potential bug (I don't know enough about Windows handles to say). https://codereview.chromium.org/1113063004/diff/200001/base/win/scoped_handle.cc ...
5 years, 5 months ago (2015-07-22 15:01:08 UTC) #43
Sébastien Marchand
5 years, 5 months ago (2015-07-22 17:37:04 UTC) #44
Message was sent while issue was closed.
https://codereview.chromium.org/1113063004/diff/200001/base/win/scoped_handle.cc
File base/win/scoped_handle.cc (right):

https://codereview.chromium.org/1113063004/diff/200001/base/win/scoped_handle...
base/win/scoped_handle.cc:159: HANDLE_FLAG_PROTECT_FROM_CLOSE);
On 2015/07/22 15:01:08, Sébastien Marchand wrote:
> This doesn't work if |handle| is as been created like this:
> ::DuplicateHandle(::GetCurrentProcess(), STD_OUTPUT_HANDLE,
>                   ::GetCurrentProcess(), &handle,
>                   0, TRUE, DUPLICATE_SAME_ACCESS);
> 
> I don't know if it's a bug or not, as we don't really manipulate the std
handles
> in Chrome afaik (we close them at startup), but it might be an issue in some
> unittests maybe ?
> 
> Here's a small repro for this:
> 
>   HANDLE original = ::GetStdHandle(STD_OUTPUT_HANDLE);
>   HANDLE duplicate = nullptr;
>   BOOL result = ::DuplicateHandle(::GetCurrentProcess(), original,
>                                   ::GetCurrentProcess(), &duplicate,
>                                   0, TRUE, DUPLICATE_SAME_ACCESS);
>   assert(result);
> 
>   ::SetHandleInformation(duplicate, HANDLE_FLAG_PROTECT_FROM_CLOSE,
>                          HANDLE_FLAG_PROTECT_FROM_CLOSE);
>   
>   DWORD flags = 0;
>   result = ::GetHandleInformation(duplicate, &flags);
>   assert(result);
>   // This assert fail, in this case |flags| == 1 (HANDLE_FLAG_INHERIT).
>   assert((flags & HANDLE_FLAG_PROTECT_FROM_CLOSE) != 0);
> 
> Is it an misuse of the Handle API or is it a real bug (I don't know so much
> about handles...)
> 
> We're hitting this in the Syzygy codebase (on this line:
>
https://github.com/google/syzygy/blob/master/syzygy/kasko/testing/launch_pyth...)
> 
> 
> 
> 

Apparently this is an accepted side effect of your change (you don't support
inherited handles), we'll just avoid using the ScopedHandle class for this then.

Powered by Google App Engine
This is Rietveld 408576698