Commit e38f7b7c authored by Egor Pasko's avatar Egor Pasko Committed by Commit Bot

crazylinker: always attempt to share RELRO

rsesek@ wrote:
Anything forked from the system zygote will have many libraries with the
same address space layout, with plenty of gadgets for exploitation.
There’s no benefit to doing extra work to support different layout just
for Chrome’s relocations.

Hence switch the crazylinker to share RELROs across renderer/utility and
browser processes. This should save ~2 MiB RAM (private dirty) on
non-lowend devices.  The low-end devices are sharing RELROs since long
ago, so this change just removes code for not-sharing RELROs.

Bug: 981599
Change-Id: I96225be9c3dad3df0c0e3d90f66fec3db364750d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1694101
Commit-Queue: Egor Pasko <pasko@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarBenoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676394}
parent 1be8ac73
...@@ -11,7 +11,6 @@ import android.support.annotation.Nullable; ...@@ -11,7 +11,6 @@ import android.support.annotation.Nullable;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.SysUtils;
import org.chromium.base.annotations.JniIgnoreNatives; import org.chromium.base.annotations.JniIgnoreNatives;
import java.util.HashMap; import java.util.HashMap;
...@@ -48,10 +47,6 @@ class LegacyLinker extends Linker { ...@@ -48,10 +47,6 @@ class LegacyLinker extends Linker {
// finishLibraryLoad(). // finishLibraryLoad().
private boolean mWaitForSharedRelros; private boolean mWaitForSharedRelros;
// Becomes true when initialization determines that the browser process can use the
// shared RELRO.
private boolean mBrowserUsesSharedRelro;
// The map of all RELRO sections either created or used in this process. // The map of all RELRO sections either created or used in this process.
private Bundle mSharedRelros; private Bundle mSharedRelros;
...@@ -79,49 +74,9 @@ class LegacyLinker extends Linker { ...@@ -79,49 +74,9 @@ class LegacyLinker extends Linker {
// constructor because instantiation occurs on the UI thread. // constructor because instantiation occurs on the UI thread.
loadLinkerJniLibrary(); loadLinkerJniLibrary();
if (mMemoryDeviceConfig == MEMORY_DEVICE_CONFIG_INIT) {
if (SysUtils.isLowEndDevice()) {
mMemoryDeviceConfig = MEMORY_DEVICE_CONFIG_LOW;
} else {
mMemoryDeviceConfig = MEMORY_DEVICE_CONFIG_NORMAL;
}
}
// Cannot run in the constructor because SysUtils.isLowEndDevice() relies
// on CommandLine, which may not be available at instantiation.
switch (BROWSER_SHARED_RELRO_CONFIG) {
case BROWSER_SHARED_RELRO_CONFIG_NEVER:
break;
case BROWSER_SHARED_RELRO_CONFIG_LOW_RAM_ONLY:
if (mMemoryDeviceConfig == MEMORY_DEVICE_CONFIG_LOW) {
mBrowserUsesSharedRelro = true;
Log.w(TAG, "Low-memory device: shared RELROs used in all processes");
}
break;
case BROWSER_SHARED_RELRO_CONFIG_ALWAYS:
Log.w(TAG, "Beware: shared RELROs used in all processes!");
mBrowserUsesSharedRelro = true;
break;
default:
Log.wtf(TAG, "FATAL: illegal shared RELRO config");
throw new AssertionError();
}
mInitialized = true; mInitialized = true;
} }
/**
* Call this method to determine if the linker will try to use shared RELROs
* for the browser process.
*/
@Override
public boolean isUsingBrowserSharedRelros() {
synchronized (sLock) {
ensureInitializedLocked();
return mInBrowserProcess && mBrowserUsesSharedRelro;
}
}
/** /**
* Call this method just before loading any native shared libraries in this process. * Call this method just before loading any native shared libraries in this process.
*/ */
...@@ -154,9 +109,9 @@ class LegacyLinker extends Linker { ...@@ -154,9 +109,9 @@ class LegacyLinker extends Linker {
synchronized (sLock) { synchronized (sLock) {
ensureInitializedLocked(); ensureInitializedLocked();
if (DEBUG) { if (DEBUG) {
String message = String.format(Locale.US, String message =
"mInBrowserProcess=%b mBrowserUsesSharedRelro=%b mWaitForSharedRelros=%b", String.format(Locale.US, "mInBrowserProcess=%b mWaitForSharedRelros=%b",
mInBrowserProcess, mBrowserUsesSharedRelro, mWaitForSharedRelros); mInBrowserProcess, mWaitForSharedRelros);
Log.i(TAG, message); Log.i(TAG, message);
} }
...@@ -172,9 +127,7 @@ class LegacyLinker extends Linker { ...@@ -172,9 +127,7 @@ class LegacyLinker extends Linker {
dumpBundle(mSharedRelros); dumpBundle(mSharedRelros);
} }
if (mBrowserUsesSharedRelro) { useSharedRelrosLocked(mSharedRelros);
useSharedRelrosLocked(mSharedRelros);
}
} }
if (mWaitForSharedRelros) { if (mWaitForSharedRelros) {
...@@ -198,7 +151,7 @@ class LegacyLinker extends Linker { ...@@ -198,7 +151,7 @@ class LegacyLinker extends Linker {
// If testing, run tests now that all libraries are loaded and initialized. // If testing, run tests now that all libraries are loaded and initialized.
if (NativeLibraries.sEnableLinkerTests) { if (NativeLibraries.sEnableLinkerTests) {
runTestRunnerClassForTesting(mMemoryDeviceConfig, mInBrowserProcess); runTestRunnerClassForTesting(mInBrowserProcess);
} }
} }
if (DEBUG) Log.i(TAG, "finishLibraryLoad() exiting"); if (DEBUG) Log.i(TAG, "finishLibraryLoad() exiting");
...@@ -271,7 +224,6 @@ class LegacyLinker extends Linker { ...@@ -271,7 +224,6 @@ class LegacyLinker extends Linker {
ensureInitializedLocked(); ensureInitializedLocked();
mInBrowserProcess = false; mInBrowserProcess = false;
mWaitForSharedRelros = false; mWaitForSharedRelros = false;
mBrowserUsesSharedRelro = false;
} }
} }
...@@ -291,7 +243,6 @@ class LegacyLinker extends Linker { ...@@ -291,7 +243,6 @@ class LegacyLinker extends Linker {
synchronized (sLock) { synchronized (sLock) {
ensureInitializedLocked(); ensureInitializedLocked();
mInBrowserProcess = false; mInBrowserProcess = false;
mBrowserUsesSharedRelro = false;
mWaitForSharedRelros = true; mWaitForSharedRelros = true;
mBaseLoadAddress = baseLoadAddress; mBaseLoadAddress = baseLoadAddress;
mCurrentLoadAddress = baseLoadAddress; mCurrentLoadAddress = baseLoadAddress;
...@@ -335,7 +286,6 @@ class LegacyLinker extends Linker { ...@@ -335,7 +286,6 @@ class LegacyLinker extends Linker {
// If the random address is 0 there are issues with finding enough // If the random address is 0 there are issues with finding enough
// free address space, so disable RELRO shared / fixed load addresses. // free address space, so disable RELRO shared / fixed load addresses.
Log.w(TAG, "Disabling shared RELROs due address space pressure"); Log.w(TAG, "Disabling shared RELROs due address space pressure");
mBrowserUsesSharedRelro = false;
mWaitForSharedRelros = false; mWaitForSharedRelros = false;
} }
} }
...@@ -447,7 +397,7 @@ class LegacyLinker extends Linker { ...@@ -447,7 +397,7 @@ class LegacyLinker extends Linker {
LibInfo libInfo = new LibInfo(); LibInfo libInfo = new LibInfo();
long loadAddress = 0; long loadAddress = 0;
if (isFixedAddressPermitted) { if (isFixedAddressPermitted) {
if ((mInBrowserProcess && mBrowserUsesSharedRelro) || mWaitForSharedRelros) { if (mInBrowserProcess || mWaitForSharedRelros) {
// Load the library at a fixed address. // Load the library at a fixed address.
loadAddress = mCurrentLoadAddress; loadAddress = mCurrentLoadAddress;
......
...@@ -13,7 +13,6 @@ import android.os.Build; ...@@ -13,7 +13,6 @@ import android.os.Build;
import android.os.Build.VERSION_CODES; import android.os.Build.VERSION_CODES;
import android.os.SystemClock; import android.os.SystemClock;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.system.Os; import android.system.Os;
...@@ -113,15 +112,6 @@ public class LibraryLoader { ...@@ -113,15 +112,6 @@ public class LibraryLoader {
// native. // native.
private boolean mCommandLineSwitched; private boolean mCommandLineSwitched;
// One-way switches recording attempts to use Relro sharing in the browser.
// The flags are used to report UMA stats later.
private boolean mIsUsingBrowserSharedRelros;
private boolean mLoadAtFixedAddressFailed;
// One-way switch becomes true if the Chromium library was loaded from the
// APK file directly.
private boolean mLibraryWasLoadedFromApk;
// The type of process the shared library is loaded in. // The type of process the shared library is loaded in.
private @LibraryProcessType int mLibraryProcessType; private @LibraryProcessType int mLibraryProcessType;
...@@ -332,28 +322,14 @@ public class LibraryLoader { ...@@ -332,28 +322,14 @@ public class LibraryLoader {
// Helper for loadAlreadyLocked(). Load a native shared library with the Chromium linker. // Helper for loadAlreadyLocked(). Load a native shared library with the Chromium linker.
// Sets UMA flags depending on the results of loading. // Sets UMA flags depending on the results of loading.
private void loadLibraryWithCustomLinkerAlreadyLocked( private void loadLibraryWithCustomLinkerAlreadyLocked(Linker linker, String libFilePath) {
Linker linker, @Nullable String zipFilePath, String libFilePath) {
assert Thread.holdsLock(mLock); assert Thread.holdsLock(mLock);
if (linker.isUsingBrowserSharedRelros()) { // Attempt shared RELROs, and if that fails then retry without.
// If the browser is set to attempt shared RELROs then we try first with shared try {
// RELROs enabled, and if that fails then retry without.
mIsUsingBrowserSharedRelros = true;
try {
linker.loadLibrary(libFilePath);
} catch (UnsatisfiedLinkError e) {
Log.w(TAG, "Failed to load native library with shared RELRO, retrying without");
mLoadAtFixedAddressFailed = true;
linker.loadLibraryNoFixedAddress(libFilePath);
}
} else {
// No attempt to use shared RELROs in the browser, so load as normal.
linker.loadLibrary(libFilePath); linker.loadLibrary(libFilePath);
} } catch (UnsatisfiedLinkError e) {
Log.w(TAG, "Failed to load native library with shared RELRO, retrying without");
// Loaded successfully, so record if we loaded directly from an APK. linker.loadLibraryNoFixedAddress(libFilePath);
if (zipFilePath != null) {
mLibraryWasLoadedFromApk = true;
} }
} }
...@@ -414,14 +390,13 @@ public class LibraryLoader { ...@@ -414,14 +390,13 @@ public class LibraryLoader {
try { try {
// Load the library using this Linker. May throw UnsatisfiedLinkError. // Load the library using this Linker. May throw UnsatisfiedLinkError.
loadLibraryWithCustomLinkerAlreadyLocked( loadLibraryWithCustomLinkerAlreadyLocked(linker, libFilePath);
linker, apkFilePath, libFilePath);
incrementRelinkerCountNotHitHistogram(); incrementRelinkerCountNotHitHistogram();
} catch (UnsatisfiedLinkError e) { } catch (UnsatisfiedLinkError e) {
if (!isInZipFile() if (!isInZipFile()
&& PLATFORM_REQUIRES_NATIVE_FALLBACK_EXTRACTION) { && PLATFORM_REQUIRES_NATIVE_FALLBACK_EXTRACTION) {
loadLibraryWithCustomLinkerAlreadyLocked( loadLibraryWithCustomLinkerAlreadyLocked(
linker, null, getExtractedLibraryPath(appInfo, library)); linker, getExtractedLibraryPath(appInfo, library));
incrementRelinkerCountHitHistogram(); incrementRelinkerCountHitHistogram();
} else { } else {
Log.e(TAG, "Unable to load library: " + library); Log.e(TAG, "Unable to load library: " + library);
......
...@@ -152,36 +152,6 @@ public abstract class Linker { ...@@ -152,36 +152,6 @@ public abstract class Linker {
// Name of the library that contains our JNI code. // Name of the library that contains our JNI code.
protected static final String LINKER_JNI_LIBRARY = "chromium_android_linker"; protected static final String LINKER_JNI_LIBRARY = "chromium_android_linker";
// Constants used to control the behaviour of the browser process with
// regards to the shared RELRO section.
// NEVER -> The browser never uses it itself.
// LOW_RAM_ONLY -> It is only used on devices with low RAM.
// ALWAYS -> It is always used.
// NOTE: These names are known and expected by the Linker test scripts.
public static final int BROWSER_SHARED_RELRO_CONFIG_NEVER = 0;
public static final int BROWSER_SHARED_RELRO_CONFIG_LOW_RAM_ONLY = 1;
public static final int BROWSER_SHARED_RELRO_CONFIG_ALWAYS = 2;
// Configuration variable used to control how the browser process uses the
// shared RELRO. Only change this while debugging linker-related issues.
// NOTE: This variable's name is known and expected by the Linker test scripts.
public static final int BROWSER_SHARED_RELRO_CONFIG =
BROWSER_SHARED_RELRO_CONFIG_LOW_RAM_ONLY;
// Constants used to control the memory device config. Can be set explicitly
// by setMemoryDeviceConfigForTesting().
// INIT -> Value is undetermined (will check at runtime).
// LOW -> This is a low-memory device.
// NORMAL -> This is not a low-memory device.
public static final int MEMORY_DEVICE_CONFIG_INIT = 0;
public static final int MEMORY_DEVICE_CONFIG_LOW = 1;
public static final int MEMORY_DEVICE_CONFIG_NORMAL = 2;
// Indicates if this is a low-memory device or not. The default is to
// determine this by probing the system at runtime, but this can be forced
// for testing by calling setMemoryDeviceConfigForTesting().
protected int mMemoryDeviceConfig = MEMORY_DEVICE_CONFIG_INIT;
// Set to true to enable debug logs. // Set to true to enable debug logs.
protected static final boolean DEBUG = false; protected static final boolean DEBUG = false;
...@@ -261,11 +231,10 @@ public abstract class Linker { ...@@ -261,11 +231,10 @@ public abstract class Linker {
/** /**
* Run runtime checks and return true if they all pass. * Run runtime checks and return true if they all pass.
* *
* @param memoryDeviceConfig The current memory device configuration.
* @param inBrowserProcess true iff this is the browser process. * @param inBrowserProcess true iff this is the browser process.
* @return true if all checks pass. * @return true if all checks pass.
*/ */
public boolean runChecks(int memoryDeviceConfig, boolean inBrowserProcess); public boolean runChecks(boolean inBrowserProcess);
} }
/** /**
...@@ -309,11 +278,9 @@ public abstract class Linker { ...@@ -309,11 +278,9 @@ public abstract class Linker {
* must be instantiated _after_ all libraries are loaded to ensure that its * must be instantiated _after_ all libraries are loaded to ensure that its
* native methods are properly registered. * native methods are properly registered.
* *
* @param memoryDeviceConfig LegacyLinker memory config, or 0 if unused
* @param inBrowserProcess true if in the browser process * @param inBrowserProcess true if in the browser process
*/ */
protected final void runTestRunnerClassForTesting( protected final void runTestRunnerClassForTesting(boolean inBrowserProcess) {
int memoryDeviceConfig, boolean inBrowserProcess) {
if (DEBUG) { if (DEBUG) {
Log.i(TAG, "runTestRunnerClassForTesting called"); Log.i(TAG, "runTestRunnerClassForTesting called");
} }
...@@ -338,7 +305,7 @@ public abstract class Linker { ...@@ -338,7 +305,7 @@ public abstract class Linker {
assert false; assert false;
} }
if (!testRunner.runChecks(memoryDeviceConfig, inBrowserProcess)) { if (!testRunner.runChecks(inBrowserProcess)) {
Log.wtf(TAG, "Linker runtime tests failed in this process"); Log.wtf(TAG, "Linker runtime tests failed in this process");
assert false; assert false;
} }
...@@ -347,35 +314,6 @@ public abstract class Linker { ...@@ -347,35 +314,6 @@ public abstract class Linker {
} }
} }
/**
* Call this method before any other Linker method to force a specific
* memory device configuration. Should only be used for testing.
*
* @param memoryDeviceConfig MEMORY_DEVICE_CONFIG_LOW or MEMORY_DEVICE_CONFIG_NORMAL.
*/
public final void setMemoryDeviceConfigForTesting(int memoryDeviceConfig) {
if (DEBUG) {
Log.i(TAG, "setMemoryDeviceConfigForTesting(" + memoryDeviceConfig + ") called");
}
// Sanity check. This method may only be called during tests.
assertLinkerTestsAreEnabled();
assert memoryDeviceConfig == MEMORY_DEVICE_CONFIG_LOW
|| memoryDeviceConfig == MEMORY_DEVICE_CONFIG_NORMAL;
synchronized (sLock) {
assert mMemoryDeviceConfig == MEMORY_DEVICE_CONFIG_INIT;
mMemoryDeviceConfig = memoryDeviceConfig;
if (DEBUG) {
if (mMemoryDeviceConfig == MEMORY_DEVICE_CONFIG_LOW) {
Log.i(TAG, "Simulating a low-memory device");
} else {
Log.i(TAG, "Simulating a regular-memory device");
}
}
}
}
/** /**
* Determine whether a library is the linker library. * Determine whether a library is the linker library.
* *
...@@ -445,16 +383,10 @@ public abstract class Linker { ...@@ -445,16 +383,10 @@ public abstract class Linker {
loadLibraryImpl(libFilePath, isFixedAddressPermitted); loadLibraryImpl(libFilePath, isFixedAddressPermitted);
} }
/**
* Call this method to determine if the linker will try to use shared RELROs
* for the browser process.
*/
public abstract boolean isUsingBrowserSharedRelros();
/** /**
* Call this method just before loading any native shared libraries in this process. * Call this method just before loading any native shared libraries in this process.
* *
* @param zipFilePath Optional current APK file path. If provided, the linker * @param apkFilePath Optional current APK file path. If provided, the linker
* will try to load libraries directly from it. * will try to load libraries directly from it.
*/ */
abstract void prepareLibraryLoad(@Nullable String apkFilePath); abstract void prepareLibraryLoad(@Nullable String apkFilePath);
......
...@@ -27,10 +27,7 @@ class LinkerTestInstance(test_instance.TestInstance): ...@@ -27,10 +27,7 @@ class LinkerTestInstance(test_instance.TestInstance):
return self._test_filter return self._test_filter
def GetTests(self): def GetTests(self):
tests = [ tests = [test_case.LinkerSharedRelroTest()]
test_case.LinkerSharedRelroTest(is_low_memory=False),
test_case.LinkerSharedRelroTest(is_low_memory=True)
]
if self._test_filter: if self._test_filter:
filtered_names = unittest_util.FilterTestNames( filtered_names = unittest_util.FilterTestNames(
......
...@@ -49,7 +49,6 @@ ResultType = base_test_result.ResultType ...@@ -49,7 +49,6 @@ ResultType = base_test_result.ResultType
_PACKAGE_NAME = 'org.chromium.chromium_linker_test_apk' _PACKAGE_NAME = 'org.chromium.chromium_linker_test_apk'
_ACTIVITY_NAME = '.ChromiumLinkerTestActivity' _ACTIVITY_NAME = '.ChromiumLinkerTestActivity'
_COMMAND_LINE_FILE = '/data/local/tmp/chromium-linker-test-command-line'
# Logcat filters used during each test. Only the 'chromium' one is really # Logcat filters used during each test. Only the 'chromium' one is really
# needed, but the logs are added to the TestResult in case of error, and # needed, but the logs are added to the TestResult in case of error, and
...@@ -126,23 +125,15 @@ class AddressList(list): ...@@ -126,23 +125,15 @@ class AddressList(list):
class LinkerTestCaseBase(object): class LinkerTestCaseBase(object):
"""Base class for linker test cases.""" """Base class for linker test cases."""
def __init__(self, is_low_memory=False): def __init__(self):
"""Create a test case. """Creates a test case."""
Args:
is_low_memory: True to simulate a low-memory device, False otherwise.
"""
test_suffix = 'ForLegacyLinker' test_suffix = 'ForLegacyLinker'
self.is_low_memory = is_low_memory
if is_low_memory:
test_suffix += 'LowMemoryDevice'
else:
test_suffix += 'RegularDevice'
class_name = self.__class__.__name__ class_name = self.__class__.__name__
self.qualified_name = '%s.%s' % (class_name, test_suffix) self.qualified_name = '%s.%s' % (class_name, test_suffix)
self.tagged_name = self.qualified_name self.tagged_name = self.qualified_name
def _RunTest(self, _device): def _RunTest(self, _device):
"""Run the test, must be overriden. """Runs the test, must be overridden.
Args: Args:
_device: A DeviceUtils interface. _device: A DeviceUtils interface.
Returns: Returns:
...@@ -153,7 +144,7 @@ class LinkerTestCaseBase(object): ...@@ -153,7 +144,7 @@ class LinkerTestCaseBase(object):
return ResultType.FAIL, 'Unimplemented _RunTest() method!' return ResultType.FAIL, 'Unimplemented _RunTest() method!'
def Run(self, device): def Run(self, device):
"""Run the test on a given device. """Runs the test on a given device.
Args: Args:
device: Name of target device where to run the test. device: Name of target device where to run the test.
Returns: Returns:
...@@ -163,11 +154,6 @@ class LinkerTestCaseBase(object): ...@@ -163,11 +154,6 @@ class LinkerTestCaseBase(object):
print('[ %-*s ] %s' % (margin, 'RUN', self.tagged_name)) print('[ %-*s ] %s' % (margin, 'RUN', self.tagged_name))
logging.info('Running linker test: %s', self.tagged_name) logging.info('Running linker test: %s', self.tagged_name)
command_line_flags = ''
if self.is_low_memory:
command_line_flags += ' --low-memory-device'
device.WriteFile(_COMMAND_LINE_FILE, command_line_flags)
# Run the test. # Run the test.
status, logs = self._RunTest(device) status, logs = self._RunTest(device)
......
...@@ -29,7 +29,7 @@ namespace { ...@@ -29,7 +29,7 @@ namespace {
using base::debug::MappedMemoryRegion; using base::debug::MappedMemoryRegion;
jboolean RunChecks(bool in_browser_process, bool need_relros) { jboolean RunChecks(bool in_browser_process) {
// IMPORTANT NOTE: The Python test control script reads the logcat for // IMPORTANT NOTE: The Python test control script reads the logcat for
// lines like: // lines like:
// BROWSER_LINKER_TEST: <status> // BROWSER_LINKER_TEST: <status>
...@@ -151,18 +151,10 @@ jboolean RunChecks(bool in_browser_process, bool need_relros) { ...@@ -151,18 +151,10 @@ jboolean RunChecks(bool in_browser_process, bool need_relros) {
return false; return false;
} }
if (need_relros) { if (num_shared_relros == 0) {
if (num_shared_relros == 0) { LOG(ERROR) << prefix
LOG(ERROR) << prefix << "FAIL Missing shared RELRO sections in this process!";
<< "FAIL Missing shared RELRO sections in this process!"; return false;
return false;
}
} else {
if (num_shared_relros > 0) {
LOG(ERROR) << prefix << "FAIL Unexpected " << num_shared_relros
<< " shared RELRO sections in this process!";
return false;
}
} }
VLOG(0) << prefix << "SUCCESS"; VLOG(0) << prefix << "SUCCESS";
...@@ -173,13 +165,7 @@ jboolean RunChecks(bool in_browser_process, bool need_relros) { ...@@ -173,13 +165,7 @@ jboolean RunChecks(bool in_browser_process, bool need_relros) {
jboolean JNI_LinkerTests_CheckForSharedRelros(JNIEnv* env, jboolean JNI_LinkerTests_CheckForSharedRelros(JNIEnv* env,
jboolean in_browser_process) { jboolean in_browser_process) {
return RunChecks(in_browser_process, true); return RunChecks(in_browser_process);
}
jboolean JNI_LinkerTests_CheckForNoSharedRelros(
JNIEnv* env,
jboolean in_browser_process) {
return RunChecks(in_browser_process, false);
} }
} // namespace content } // namespace content
...@@ -11,7 +11,6 @@ import android.os.Bundle; ...@@ -11,7 +11,6 @@ import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import org.chromium.base.CommandLine;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.library_loader.LibraryLoader; import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.library_loader.LibraryProcessType; import org.chromium.base.library_loader.LibraryProcessType;
...@@ -29,16 +28,6 @@ import org.chromium.ui.base.ActivityWindowAndroid; ...@@ -29,16 +28,6 @@ import org.chromium.ui.base.ActivityWindowAndroid;
public class ChromiumLinkerTestActivity extends Activity { public class ChromiumLinkerTestActivity extends Activity {
private static final String TAG = "LinkerTest"; private static final String TAG = "LinkerTest";
public static final String COMMAND_LINE_FILE =
"/data/local/tmp/chromium-linker-test-command-line";
public static final String COMMAND_LINE_ARGS_KEY = "commandLineArgs";
// Use this on the command-line to simulate a low-memory device, otherwise
// a regular device is simulated by this test, independently from what the
// target device running the test really is.
private static final String LOW_MEMORY_DEVICE = "--low-memory-device";
private ShellManager mShellManager; private ShellManager mShellManager;
private ActivityWindowAndroid mWindowAndroid; private ActivityWindowAndroid mWindowAndroid;
...@@ -46,40 +35,6 @@ public class ChromiumLinkerTestActivity extends Activity { ...@@ -46,40 +35,6 @@ public class ChromiumLinkerTestActivity extends Activity {
public void onCreate(final Bundle savedInstanceState) { public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// Initializing the command line must occur before loading the library.
if (!CommandLine.isInitialized()) {
CommandLine.initFromFile(COMMAND_LINE_FILE);
String[] commandLineParams = getCommandLineParamsFromIntent(getIntent());
if (commandLineParams != null) {
CommandLine.getInstance().appendSwitchesAndArguments(commandLineParams);
}
}
// CommandLine.getInstance().hasSwitch() doesn't work here for some funky
// reason, so parse the command-line differently here:
boolean hasLowMemoryDeviceSwitch = false;
String[] commandLine = CommandLine.getJavaSwitchesOrNull();
if (commandLine == null) {
Log.i(TAG, "Command line is null");
} else {
Log.i(TAG, "Command line is:");
for (int n = 0; n < commandLine.length; ++n) {
String option = commandLine[n];
Log.i(TAG, " '" + option + "'");
if (option.equals(LOW_MEMORY_DEVICE)) {
hasLowMemoryDeviceSwitch = true;
}
}
}
// Determine which kind of device to simulate from the command-line.
int memoryDeviceConfig = Linker.MEMORY_DEVICE_CONFIG_NORMAL;
if (hasLowMemoryDeviceSwitch) {
memoryDeviceConfig = Linker.MEMORY_DEVICE_CONFIG_LOW;
}
Linker linker = Linker.getInstance();
linker.setMemoryDeviceConfigForTesting(memoryDeviceConfig);
// Setup the TestRunner class name. // Setup the TestRunner class name.
Linker.setupForTesting("org.chromium.chromium_linker_test_apk.LinkerTests"); Linker.setupForTesting("org.chromium.chromium_linker_test_apk.LinkerTests");
...@@ -164,10 +119,6 @@ public class ChromiumLinkerTestActivity extends Activity { ...@@ -164,10 +119,6 @@ public class ChromiumLinkerTestActivity extends Activity {
mWindowAndroid.onActivityResult(requestCode, resultCode, data); mWindowAndroid.onActivityResult(requestCode, resultCode, data);
} }
private static String[] getCommandLineParamsFromIntent(Intent intent) {
return intent != null ? intent.getStringArrayExtra(COMMAND_LINE_ARGS_KEY) : null;
}
/** /**
* @return The {@link WebContents} owned by the currently visible {@link Shell} or null if * @return The {@link WebContents} owned by the currently visible {@link Shell} or null if
* one is not showing. * one is not showing.
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
package org.chromium.chromium_linker_test_apk; package org.chromium.chromium_linker_test_apk;
import org.chromium.base.Log;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.library_loader.Linker; import org.chromium.base.library_loader.Linker;
...@@ -19,46 +18,11 @@ public class LinkerTests implements Linker.TestRunner { ...@@ -19,46 +18,11 @@ public class LinkerTests implements Linker.TestRunner {
public LinkerTests() {} public LinkerTests() {}
@Override @Override
public boolean runChecks(int memoryDeviceConfig, public boolean runChecks(boolean isBrowserProcess) {
boolean isBrowserProcess) { return nativeCheckForSharedRelros(isBrowserProcess);
boolean checkSharedRelro;
if (isBrowserProcess) {
// LegacyLinker may share RELROs in the browser.
switch (Linker.BROWSER_SHARED_RELRO_CONFIG) {
case Linker.BROWSER_SHARED_RELRO_CONFIG_NEVER:
checkSharedRelro = false;
break;
case Linker.BROWSER_SHARED_RELRO_CONFIG_LOW_RAM_ONLY:
// A shared RELRO should only be used on low-end devices.
checkSharedRelro = (memoryDeviceConfig == Linker.MEMORY_DEVICE_CONFIG_LOW);
break;
case Linker.BROWSER_SHARED_RELRO_CONFIG_ALWAYS:
// Always check for a shared RELRO.
checkSharedRelro = true;
break;
default:
Log.e(TAG,
"Invalid shared RELRO linker configuration: "
+ Linker.BROWSER_SHARED_RELRO_CONFIG);
return false;
}
} else {
// Service processes should always use a shared RELRO section.
checkSharedRelro = true;
}
if (checkSharedRelro) {
return nativeCheckForSharedRelros(isBrowserProcess);
} else {
return nativeCheckForNoSharedRelros(isBrowserProcess);
}
} }
// Check that there are shared RELRO sections in the current process, // Check that there are shared RELRO sections in the current process,
// and that they are properly mapped read-only. Returns true on success. // and that they are properly mapped read-only. Returns true on success.
private static native boolean nativeCheckForSharedRelros(boolean isBrowserProcess); private static native boolean nativeCheckForSharedRelros(boolean isBrowserProcess);
// Check that there are no shared RELRO sections in the current process,
// return true on success.
private static native boolean nativeCheckForNoSharedRelros(boolean isBrowserProcess);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment