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

Side by Side Diff: content/public/android/java/src/org/chromium/content/app/ChildProcessServiceImpl.java

Issue 2796453003: android: Limit bindToCaller check to webview (Closed)
Patch Set: rebase, removed final from chrome Created 3 years, 8 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 package org.chromium.content.app; 5 package org.chromium.content.app;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.Intent; 8 import android.content.Intent;
9 import android.graphics.SurfaceTexture; 9 import android.graphics.SurfaceTexture;
10 import android.os.Binder; 10 import android.os.Binder;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 @SuppressWarnings("SynchronizeOnNonFinalField") 52 @SuppressWarnings("SynchronizeOnNonFinalField")
53 @MainDex 53 @MainDex
54 @UsedByReflection("WebApkSandboxedProcessService") 54 @UsedByReflection("WebApkSandboxedProcessService")
55 public class ChildProcessServiceImpl { 55 public class ChildProcessServiceImpl {
56 private static final String MAIN_THREAD_NAME = "ChildProcessMain"; 56 private static final String MAIN_THREAD_NAME = "ChildProcessMain";
57 private static final String TAG = "ChildProcessService"; 57 private static final String TAG = "ChildProcessService";
58 58
59 // Lock that protects the following members. 59 // Lock that protects the following members.
60 private final Object mBinderLock = new Object(); 60 private final Object mBinderLock = new Object();
61 private IGpuProcessCallback mGpuCallback; 61 private IGpuProcessCallback mGpuCallback;
62 // PID of the client of this service, set in bindToCaller(). 62 private boolean mBindToCallerCheck;
63 // PID of the client of this service, set in bindToCaller(), if mBindToCalle rCheck is true.
63 private int mBoundCallingPid; 64 private int mBoundCallingPid;
64 65
65 // This is the native "Main" thread for the renderer / utility process. 66 // This is the native "Main" thread for the renderer / utility process.
66 private Thread mMainThread; 67 private Thread mMainThread;
67 // Parameters received via IPC, only accessed while holding the mMainThread monitor. 68 // Parameters received via IPC, only accessed while holding the mMainThread monitor.
68 private String[] mCommandLineParams; 69 private String[] mCommandLineParams;
69 private int mCpuCount; 70 private int mCpuCount;
70 private long mCpuFeatures; 71 private long mCpuFeatures;
71 // File descriptors that should be registered natively. 72 // File descriptors that should be registered natively.
72 private FileDescriptorInfo[] mFdInfos; 73 private FileDescriptorInfo[] mFdInfos;
(...skipping 30 matching lines...) Expand all
103 mLinkerParams.mTestRunnerClassNameForTesting); 104 mLinkerParams.mTestRunnerClassNameForTesting);
104 } 105 }
105 return Linker.getInstance(); 106 return Linker.getInstance();
106 } 107 }
107 108
108 // Binder object used by clients for this service. 109 // Binder object used by clients for this service.
109 private final IChildProcessService.Stub mBinder = new IChildProcessService.S tub() { 110 private final IChildProcessService.Stub mBinder = new IChildProcessService.S tub() {
110 // NOTE: Implement any IChildProcessService methods here. 111 // NOTE: Implement any IChildProcessService methods here.
111 @Override 112 @Override
112 public boolean bindToCaller() { 113 public boolean bindToCaller() {
114 assert mBindToCallerCheck;
113 synchronized (mBinderLock) { 115 synchronized (mBinderLock) {
114 int callingPid = Binder.getCallingPid(); 116 int callingPid = Binder.getCallingPid();
115 if (mBoundCallingPid == 0) { 117 if (mBoundCallingPid == 0) {
116 mBoundCallingPid = callingPid; 118 mBoundCallingPid = callingPid;
117 } else if (mBoundCallingPid != callingPid) { 119 } else if (mBoundCallingPid != callingPid) {
118 Log.e(TAG, "Service is already bound by pid %d, cannot bind for pid %d", 120 Log.e(TAG, "Service is already bound by pid %d, cannot bind for pid %d",
119 mBoundCallingPid, callingPid); 121 mBoundCallingPid, callingPid);
120 return false; 122 return false;
121 } 123 }
122 } 124 }
123 return true; 125 return true;
124 } 126 }
125 127
126 @Override 128 @Override
127 public int setupConnection(Bundle args, IBinder callback) { 129 public int setupConnection(Bundle args, IBinder callback) {
128 int callingPid = Binder.getCallingPid(); 130 int callingPid = Binder.getCallingPid();
129 synchronized (mBinderLock) { 131 synchronized (mBinderLock) {
130 if (mBoundCallingPid != callingPid) { 132 if (mBindToCallerCheck && mBoundCallingPid != callingPid) {
131 if (mBoundCallingPid == 0) { 133 if (mBoundCallingPid == 0) {
132 Log.e(TAG, "Service has not been bound with bindToCaller ()"); 134 Log.e(TAG, "Service has not been bound with bindToCaller ()");
133 } else { 135 } else {
134 Log.e(TAG, "Client pid %d does not match the bound pid % d", callingPid, 136 Log.e(TAG, "Client pid %d does not match the bound pid % d", callingPid,
135 mBoundCallingPid); 137 mBoundCallingPid);
136 } 138 }
137 return -1; 139 return -1;
138 } 140 }
141 }
139 142
140 mGpuCallback = 143 mGpuCallback = callback != null ? IGpuProcessCallback.Stub.asInterfa ce(callback) : null;
141 callback != null ? IGpuProcessCallback.Stub.asInterface( callback) : null; 144 getServiceInfo(args);
142 getServiceInfo(args); 145 return Process.myPid();
143 return Process.myPid();
144 }
145 } 146 }
146 147
147 @Override 148 @Override
148 public void crashIntentionallyForTesting() { 149 public void crashIntentionallyForTesting() {
149 Process.killProcess(Process.myPid()); 150 Process.killProcess(Process.myPid());
150 } 151 }
151 152
152 @Override 153 @Override
153 public boolean onTransact(int arg0, Parcel arg1, Parcel arg2, int arg3) 154 public boolean onTransact(int arg0, Parcel arg1, Parcel arg2, int arg3)
154 throws RemoteException { 155 throws RemoteException {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 335
335 private void initializeParams(Intent intent) { 336 private void initializeParams(Intent intent) {
336 synchronized (mMainThread) { 337 synchronized (mMainThread) {
337 // mLinkerParams is never used if Linker.isUsed() returns false. 338 // mLinkerParams is never used if Linker.isUsed() returns false.
338 // See onCreate(). 339 // See onCreate().
339 mLinkerParams = (ChromiumLinkerParams) intent.getParcelableExtra( 340 mLinkerParams = (ChromiumLinkerParams) intent.getParcelableExtra(
340 ChildProcessConstants.EXTRA_LINKER_PARAMS); 341 ChildProcessConstants.EXTRA_LINKER_PARAMS);
341 mLibraryProcessType = ChildProcessCreationParams.getLibraryProcessTy pe(intent); 342 mLibraryProcessType = ChildProcessCreationParams.getLibraryProcessTy pe(intent);
342 mMainThread.notifyAll(); 343 mMainThread.notifyAll();
343 } 344 }
345 synchronized (mBinderLock) {
346 mBindToCallerCheck =
347 intent.getBooleanExtra(ChildProcessConstants.EXTRA_BIND_TO_C ALLER, false);
348 }
344 } 349 }
345 350
346 private void getServiceInfo(Bundle bundle) { 351 private void getServiceInfo(Bundle bundle) {
347 // Required to unparcel FileDescriptorInfo. 352 // Required to unparcel FileDescriptorInfo.
348 bundle.setClassLoader(mHostClassLoader); 353 bundle.setClassLoader(mHostClassLoader);
349 synchronized (mMainThread) { 354 synchronized (mMainThread) {
350 if (mCommandLineParams == null) { 355 if (mCommandLineParams == null) {
351 mCommandLineParams = 356 mCommandLineParams =
352 bundle.getStringArray(ChildProcessConstants.EXTRA_COMMAN D_LINE); 357 bundle.getStringArray(ChildProcessConstants.EXTRA_COMMAN D_LINE);
353 mMainThread.notifyAll(); 358 mMainThread.notifyAll();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 private static native void nativeInitChildProcessImpl( 436 private static native void nativeInitChildProcessImpl(
432 ChildProcessServiceImpl serviceImpl, int cpuCount, long cpuFeatures) ; 437 ChildProcessServiceImpl serviceImpl, int cpuCount, long cpuFeatures) ;
433 438
434 /** 439 /**
435 * Force the child process to exit. 440 * Force the child process to exit.
436 */ 441 */
437 private static native void nativeExitChildProcess(); 442 private static native void nativeExitChildProcess();
438 443
439 private native void nativeShutdownMainThread(); 444 private native void nativeShutdownMainThread();
440 } 445 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698