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

Issue 1117883002: Reduce resource leak code for StartNaClExecution.

Created:
5 years, 7 months ago by hidehiko
Modified:
5 years, 6 months ago
Reviewers:
Mark Seaborn
CC:
chromium-reviews, hamaji, mazda, Yusuke Sato
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Reduce resource leak code for StartNaClExecution. Specifically on error handling code, there are some resource leak code path or potential crash code path. The root cause is; currently the code to open resources used by a plugin is distributed. So, if an error is found after some resources in the plugin is created, it would be leaked. With this CL, those resource opening is delayed until we decide to send an IPC to plugin (in StartNaClExecution), and whenever we decide to send (i.e. once we start opening resources for the plugin), always the IPC is sent even some error (like resource opening failure) is found by deferring the error handling to the plugin. Note that the biggest code change of this CL is moving BatchOpenResourceFiles from nacl_host_message_filter to nacl_process_host. TEST=Ran bots. BUG=https://code.google.com/p/nativeclient/issues/detail?id=3802

Patch Set 1 #

Total comments: 4

Patch Set 2 : Rebase #

Patch Set 3 : Rebase #

Patch Set 4 : #

Unified diffs Side-by-side diffs Delta from patch set Stats (+229 lines, -174 lines) Patch
M components/nacl/browser/nacl_host_message_filter.h View 2 chunks +1 line, -6 lines 0 comments Download
M components/nacl/browser/nacl_host_message_filter.cc View 1 5 chunks +4 lines, -58 lines 0 comments Download
M components/nacl/browser/nacl_process_host.h View 1 2 3 chunks +7 lines, -5 lines 0 comments Download
M components/nacl/browser/nacl_process_host.cc View 1 2 9 chunks +203 lines, -101 lines 0 comments Download
M components/nacl/loader/nacl_listener.cc View 1 2 3 3 chunks +14 lines, -4 lines 0 comments Download

Messages

Total messages: 19 (3 generated)
hidehiko
This is the remaining part of https://codereview.chromium.org/1085583005/#ps20001. PTAL. - hidehiko
5 years, 7 months ago (2015-04-30 13:39:04 UTC) #2
hidehiko
Friendly ping? On 2015/04/30 13:39:04, hidehiko wrote: > This is the remaining part of > ...
5 years, 7 months ago (2015-05-01 16:27:48 UTC) #3
hidehiko
Friendly ping? On 2015/05/01 16:27:48, hidehiko wrote: > Friendly ping? > > On 2015/04/30 13:39:04, ...
5 years, 7 months ago (2015-05-04 16:23:10 UTC) #4
hidehiko
Friendly ping? On 2015/05/04 16:23:10, hidehiko wrote: > Friendly ping? > > On 2015/05/01 16:27:48, ...
5 years, 7 months ago (2015-05-06 13:16:58 UTC) #5
Mark Seaborn
https://codereview.chromium.org/1117883002/diff/1/components/nacl/browser/nacl_process_host.cc File components/nacl/browser/nacl_process_host.cc (right): https://codereview.chromium.org/1117883002/diff/1/components/nacl/browser/nacl_process_host.cc#newcode947 components/nacl/browser/nacl_process_host.cc:947: params.irt_handle = IPC::GetFileHandleForProcess( So you're changing the browser process ...
5 years, 7 months ago (2015-05-08 00:02:02 UTC) #6
hidehiko
Rebased, as some more changes around the code are landed. PTAL. https://codereview.chromium.org/1117883002/diff/1/components/nacl/browser/nacl_process_host.cc File components/nacl/browser/nacl_process_host.cc (right): ...
5 years, 7 months ago (2015-05-11 16:52:49 UTC) #9
hidehiko
Ping. On 2015/05/11 16:52:49, hidehiko wrote: > Rebased, as some more changes around the code ...
5 years, 7 months ago (2015-05-12 18:48:21 UTC) #10
hidehiko
CC+=yusukes@. Mark, according to offline discussion with Julien and Justin, as for resource (FDs/HANDLEs management), ...
5 years, 7 months ago (2015-05-19 12:35:47 UTC) #11
Mark Seaborn
https://codereview.chromium.org/1117883002/diff/1/components/nacl/browser/nacl_process_host.cc File components/nacl/browser/nacl_process_host.cc (right): https://codereview.chromium.org/1117883002/diff/1/components/nacl/browser/nacl_process_host.cc#newcode947 components/nacl/browser/nacl_process_host.cc:947: params.irt_handle = IPC::GetFileHandleForProcess( On 2015/05/11 16:52:49, hidehiko wrote: > ...
5 years, 6 months ago (2015-05-25 19:48:55 UTC) #12
hidehiko
PTAL. https://codereview.chromium.org/1117883002/diff/1/components/nacl/browser/nacl_process_host.cc File components/nacl/browser/nacl_process_host.cc (right): https://codereview.chromium.org/1117883002/diff/1/components/nacl/browser/nacl_process_host.cc#newcode947 components/nacl/browser/nacl_process_host.cc:947: params.irt_handle = IPC::GetFileHandleForProcess( On 2015/05/25 19:48:55, Mark Seaborn ...
5 years, 6 months ago (2015-05-26 14:32:59 UTC) #13
jschuh
On 2015/05/26 14:32:59, hidehiko wrote: > PTAL. > > https://codereview.chromium.org/1117883002/diff/1/components/nacl/browser/nacl_process_host.cc > File components/nacl/browser/nacl_process_host.cc (right): > ...
5 years, 6 months ago (2015-05-27 04:28:24 UTC) #14
Mark Seaborn
On 27 May 2015 at 05:28, <jschuh@chromium.org> wrote: > On 2015/05/26 14:32:59, hidehiko wrote: > ...
5 years, 6 months ago (2015-05-27 13:17:26 UTC) #15
hidehiko
On 2015/05/27 13:17:26, Mark Seaborn wrote: > On 27 May 2015 at 05:28, <mailto:jschuh@chromium.org> wrote: ...
5 years, 6 months ago (2015-05-27 17:42:25 UTC) #16
hidehiko
ping. On 2015/05/27 17:42:25, hidehiko wrote: > On 2015/05/27 13:17:26, Mark Seaborn wrote: > > ...
5 years, 6 months ago (2015-05-29 06:01:13 UTC) #17
hidehiko
ping. On 2015/05/29 06:01:13, hidehiko wrote: > ping. > > > On 2015/05/27 17:42:25, hidehiko ...
5 years, 6 months ago (2015-06-03 05:09:24 UTC) #18
hidehiko
5 years, 6 months ago (2015-06-04 14:47:09 UTC) #19
ping.

On 2015/06/03 05:09:24, hidehiko wrote:
> ping.
> 
> On 2015/05/29 06:01:13, hidehiko wrote:
> > ping.
> > 
> > 
> > On 2015/05/27 17:42:25, hidehiko wrote:
> > > On 2015/05/27 13:17:26, Mark Seaborn wrote:
> > > > On 27 May 2015 at 05:28, <mailto:jschuh@chromium.org> wrote:
> > > > 
> > > > > On 2015/05/26 14:32:59, hidehiko wrote:
> > > > >
> > > > >> > However, I've been thinking about this, and I think that cleaning
up
> > > > >> the IPC
> > > > >>
> > > > > > layer to transfer Windows handles more cleanly might not be too
hard.
> > > > >> >
> > > > >> > Could we get the IPC layer to do the DuplicateHandle() calls
*after*
> we
> > > > >> do
> > > > >> > channel->Send(message)?  This would involve changing:
> > > > >> >
> > > > >> >  * ipc_message_attachment.h: Unconditionalise TakePlatformFile().
> > > > >> >
> > > > >> >  * ipc/ipc_platform_file_attachment_posix.cc: Add a version for
> > > > >> Windows handles.
> > > > >> >
> > > > >> >  * ipc_message_attachment_set.h: Add Windows equivalent of
> > > > >> > AddDescriptorsToOwn().
> > > > >> >
> > > > >> >  * ipc_message_utils.cc: Add Windows equivalent of
> > > > >> > ParamTraits<base::FileDescriptor>::Write() -- perhaps
> > > > >> > ParamTraits<base::File>::Write().  We would allow putting
base::Files
> > > > >> in IPC
> > > > >> > messages and have these transferred automatically without the user
of
> > > > >> the IPC
> > > > >
> > > > >  > layer having to call IPC::Get/TakeFileHandleForProcess() or see
> > > > >> > IPC::PlatformFileForTransits.
> > > > >> >
> > > > >> >  * ipc_channel_win.cc: Add logic to tack duplicated handles onto a
> > > > >> message,
> > > > >> > similar to the code that uses
> msg->attachment_set()->PeekDescriptors()
> > > > >> in
> > > > >> > ipc_channel_posix.cc.  To start with, we'd just handle the case of
> > > > >> sending
> > > > >> > messages from the browser process to sandboxed processes.
> > > > >> >
> > > > >> >
> > > > >> > This would make the error handling easier because all the
> > > > >> DuplicateHandle()
> > > > >> > calls would be done in one loop.  If one call fails, we can easily
> free
> > > > >> the
> > > > >> > remaining handles.
> > > > >> >
> > > > >> > That would be easier to reason about than putting workarounds into
> > > > >> users of the
> > > > >> > IPC layer (such as nacl_process_host.cc), which is rather fragile
> > > > >> because the
> > > > >
> > > > >  > error paths don't get tested.
> > > > >> >
> > > > >> > What do you think about that idea?
> > > > >>
> > > > >
> > > > >  IIUC, this has same problem; if DuplicateHandle() fails, after some
> > > > >> DuplicateHandle() succeeds, in ipc_channel_win, it means some HANDLE
is
> > > > >> already
> > > > >
> > > > >  opened in the callee process.
> > > > >>
> > > > >
> > > > > FWIW, DuplicateHandle with DUPLICATE_CLOSE_SOURCE will work to close
the
> > > > > handle
> > > > > in the target process from the browser process. And I can use that to
> add
> > a
> > > > > batch version of BrokerDuplicateHandle that cleans up after itself on
a
> > > > > failure.
> > > > 
> > > > 
> > > > Indeed, as Justin says, it's possible to close the handles that got sent
> to
> > > > the renderer if DuplicateHandle() fails.
> > > > 
> > > > Also, I would argue that closing those duplicated handles on Windows
isn't
> > > > actually the important part.  The important part is how errors are
handled
> > > > on Unix.
> > > > 
> > > > Firstly, if some handles got leaked in the renderer process, that's not
> too
> > > > bad, because it's not too disruptive if a renderer process crashes due
to
> > > > filling up the handle table.  It's more important to make sure that no
> > > > FDs/handles are leaked in the browser process, because it's more
> disruptive
> > > > if the browser process crashes.
> > > > 
> > > > Secondly, there aren't many ways the DuplicateHandle() call could fail:
> > > >  * It could fail if the destination process died, in which case we don't
> > > > need to close the duplicated handles.
> > > >  * It could fail if the destination process's handle table is full, in
> > > > which case the destination process probably won't last long anyway.
> > > >  * It could fail if the handle we're duplicating is invalid, which is
> > > > grounds for aborting the current process anyway.
> > > > 
> > > > Oddly enough, the benefit of cleaning up Chrome's use of handle-passing
on
> > > > Windows would be that it stops Chrome leaking FDs in the browser process
> > > > *on Unix*.  That's because if there's an error after calling
> > > > IPC::Get/TakeFileHandleForProcess(), there's currently no portable
> > > > interface for closing the Unix FDs that those functions return.  The
idea
> > > > of the clean up would be that we don't need to use
> > > > IPC::Get/TakeFileHandleForProcess().
> > > > 
> > > 
> > > Thank you for comment.
> > > 
> > > But, I wouldn't like to discuss the IPC's ideal FDs/HANDLEs handling
*here*,
> > > because it is not the goal.
> > > This CL is based on the current IPC framework, and, again, the goal is
> > > completing yusukes@'s
> > > remaining task, rather than implementing ideal IPC's RAII.
> > > 
> > > Mark, what's your concrete concern on this CL? Even on Unix, the code
should
> > > release FDs properly, IIUC.
> > > If FD RAII is supported on IPC in future, that's great. I'm happy to join
> the
> > > discussion.
> > > Though, it's better to be discussed separately. Actually, supporting RAII
on
> > IPC
> > > is not the focus of this CL.
> > > 
> > > Thanks,
> > > - hidehiko
> > > 
> > > 
> > > > Cheers,
> > > > Mark
> > > > 
> > > > To unsubscribe from this group and stop receiving emails from it, send
an
> > > email
> > > > to mailto:chromium-reviews+unsubscribe@chromium.org.

Powered by Google App Engine
This is Rietveld 408576698