summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2014-08-08 12:44:12 +0100
committerNarayan Kamath <narayan@google.com>2014-08-15 12:50:10 +0100
commit6c4b9de8f1fd594038793c3924b52a44138c319e (patch)
tree7fe3145e6dbc6e35be1ce083e6128a40e1ee015b
parent4b2d0f20db2e0f9395a0c12ed5d4b6020eb272cb (diff)
downloadframeworks_base-6c4b9de8f1fd594038793c3924b52a44138c319e.zip
frameworks_base-6c4b9de8f1fd594038793c3924b52a44138c319e.tar.gz
frameworks_base-6c4b9de8f1fd594038793c3924b52a44138c319e.tar.bz2
Validate instruction sets passed to installd.
We don't want folks passing down arbitrary strings. bug: 16837404 Change-Id: I73ac66b376f1401f9f95f3c6323da6242ac8ed3d
-rw-r--r--core/java/android/app/LoadedApk.java4
-rw-r--r--services/core/java/com/android/server/pm/Installer.java56
2 files changed, 56 insertions, 4 deletions
diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java
index 24c2835..aa1f021 100644
--- a/core/java/android/app/LoadedApk.java
+++ b/core/java/android/app/LoadedApk.java
@@ -262,10 +262,6 @@ public final class LoadedApk {
if (!Objects.equals(mPackageName, ActivityThread.currentPackageName())) {
final String isa = VMRuntime.getRuntime().vmInstructionSet();
try {
- // TODO: We can probably do away with the isa argument since
- // the AM and PM have enough information to figure this out
- // themselves. If we do need it, we should match it against the
- // list of devices ISAs before sending it down to installd.
ActivityThread.getPackageManager().performDexOptIfNeeded(mPackageName, isa);
} catch (RemoteException re) {
// Ignored.
diff --git a/services/core/java/com/android/server/pm/Installer.java b/services/core/java/com/android/server/pm/Installer.java
index b261ef5..3e40d3f 100644
--- a/services/core/java/com/android/server/pm/Installer.java
+++ b/services/core/java/com/android/server/pm/Installer.java
@@ -16,6 +16,7 @@
package com.android.server.pm;
+import android.os.Build;
import com.android.server.SystemService;
import android.content.Context;
@@ -23,6 +24,7 @@ import android.content.pm.PackageStats;
import android.net.LocalSocket;
import android.net.LocalSocketAddress;
import android.util.Slog;
+import dalvik.system.VMRuntime;
import java.io.IOException;
import java.io.InputStream;
@@ -214,6 +216,11 @@ public final class Installer extends SystemService {
public int patchoat(String apkPath, int uid, boolean isPublic, String pkgName,
String instructionSet) {
+ if (!isValidInstructionSet(instructionSet)) {
+ Slog.e(TAG, "Invalid instruction set: " + instructionSet);
+ return -1;
+ }
+
StringBuilder builder = new StringBuilder("patchoat");
builder.append(' ');
builder.append(apkPath);
@@ -228,6 +235,11 @@ public final class Installer extends SystemService {
}
public int patchoat(String apkPath, int uid, boolean isPublic, String instructionSet) {
+ if (!isValidInstructionSet(instructionSet)) {
+ Slog.e(TAG, "Invalid instruction set: " + instructionSet);
+ return -1;
+ }
+
StringBuilder builder = new StringBuilder("patchoat");
builder.append(' ');
builder.append(apkPath);
@@ -241,6 +253,11 @@ public final class Installer extends SystemService {
}
public int dexopt(String apkPath, int uid, boolean isPublic, String instructionSet) {
+ if (!isValidInstructionSet(instructionSet)) {
+ Slog.e(TAG, "Invalid instruction set: " + instructionSet);
+ return -1;
+ }
+
StringBuilder builder = new StringBuilder("dexopt");
builder.append(' ');
builder.append(apkPath);
@@ -255,6 +272,11 @@ public final class Installer extends SystemService {
public int dexopt(String apkPath, int uid, boolean isPublic, String pkgName,
String instructionSet) {
+ if (!isValidInstructionSet(instructionSet)) {
+ Slog.e(TAG, "Invalid instruction set: " + instructionSet);
+ return -1;
+ }
+
StringBuilder builder = new StringBuilder("dexopt");
builder.append(' ');
builder.append(apkPath);
@@ -280,6 +302,11 @@ public final class Installer extends SystemService {
}
public int movedex(String srcPath, String dstPath, String instructionSet) {
+ if (!isValidInstructionSet(instructionSet)) {
+ Slog.e(TAG, "Invalid instruction set: " + instructionSet);
+ return -1;
+ }
+
StringBuilder builder = new StringBuilder("movedex");
builder.append(' ');
builder.append(srcPath);
@@ -291,6 +318,11 @@ public final class Installer extends SystemService {
}
public int rmdex(String codePath, String instructionSet) {
+ if (!isValidInstructionSet(instructionSet)) {
+ Slog.e(TAG, "Invalid instruction set: " + instructionSet);
+ return -1;
+ }
+
StringBuilder builder = new StringBuilder("rmdex");
builder.append(' ');
builder.append(codePath);
@@ -403,6 +435,13 @@ public final class Installer extends SystemService {
public int getSizeInfo(String pkgName, int persona, String apkPath, String libDirPath,
String fwdLockApkPath, String asecPath, String[] instructionSets, PackageStats pStats) {
+ for (String instructionSet : instructionSets) {
+ if (!isValidInstructionSet(instructionSet)) {
+ Slog.e(TAG, "Invalid instruction set: " + instructionSet);
+ return -1;
+ }
+ }
+
StringBuilder builder = new StringBuilder("getsize");
builder.append(' ');
builder.append(pkgName);
@@ -480,4 +519,21 @@ public final class Installer extends SystemService {
builder.append(uid);
return (execute(builder.toString()) == 0);
}
+
+ /**
+ * Returns true iff. {@code instructionSet} is a valid instruction set.
+ */
+ private static boolean isValidInstructionSet(String instructionSet) {
+ if (instructionSet == null) {
+ return false;
+ }
+
+ for (String abi : Build.SUPPORTED_ABIS) {
+ if (instructionSet.equals(VMRuntime.getInstructionSet(abi))) {
+ return true;
+ }
+ }
+
+ return false;
+ }
}