summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJessica Wagantall <jwagantall@cyngn.com>2016-09-15 14:03:52 -0700
committerJessica Wagantall <jwagantall@cyngn.com>2016-10-13 12:13:16 -0700
commit7a979b3d89a29d8d28ab8860d083f87c6eb869b8 (patch)
treee1c6db8d077c619c9ce8d0898befa19d42e96956
parent738bd044cafd5991461b354a4030dd78b2fc0c90 (diff)
downloadandroid_packages_providers_TelephonyProvider-stable/cm-12.1-YOG4P.tar.gz
android_packages_providers_TelephonyProvider-stable/cm-12.1-YOG4P.tar.bz2
android_packages_providers_TelephonyProvider-stable/cm-12.1-YOG4P.zip
30481342: Security Vulnerability - TOCTOU in MmsProviderstable/cm-12.1-YOG4P
allows access to files as phone (radio) uid - DO NOT MERGE Problem: MmsProvider.openFile validated the current _data column in the DB and then called ContentProvider.openFileHelper which was again reading from the DB. A race condition could cause the second DB read to read an updated, malicious value. Fix: instead of doing the first DB check and calling ContentProvider.openFileHelper, we're now just calling MmsProvider.safeOpenFileHelper which does a single check. Test: used the POC provided for this incident. CYNGNOS-3286 b/30481342 Change-Id: I653129359130b9fae59d4c355320b266c158a698 (cherry picked from commit 53ff7691e0163f730ac9410da76e5ea61fe67343)
-rw-r--r--src/com/android/providers/telephony/MmsProvider.java36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/com/android/providers/telephony/MmsProvider.java b/src/com/android/providers/telephony/MmsProvider.java
index b095e66..4242158 100644
--- a/src/com/android/providers/telephony/MmsProvider.java
+++ b/src/com/android/providers/telephony/MmsProvider.java
@@ -16,6 +16,7 @@
package com.android.providers.telephony;
+import android.annotation.NonNull;
import android.app.AppOpsManager;
import android.content.ContentProvider;
import android.content.ContentValues;
@@ -276,7 +277,11 @@ public class MmsProvider extends ContentProvider {
@Override
public Uri insert(Uri uri, ContentValues values) {
- // Don't let anyone insert anything with the _data column
+ // The _data column is filled internally in MmsProvider, so this check is just to avoid
+ // it from being inadvertently set. This is not supposed to be a protection against
+ // malicious attack, since sql injection could still be attempted to bypass the check. On
+ // the other hand, the MmsProvider does verify that the _data column has an allowed value
+ // before opening any uri/files.
if (values != null && values.containsKey(Part._DATA)) {
return null;
}
@@ -727,9 +732,12 @@ public class MmsProvider extends ContentProvider {
}
@Override
- public int update(Uri uri, ContentValues values,
- String selection, String[] selectionArgs) {
- // Don't let anyone update the _data column
+ public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+ // The _data column is filled internally in MmsProvider, so this check is just to avoid
+ // it from being inadvertently set. This is not supposed to be a protection against
+ // malicious attack, since sql injection could still be attempted to bypass the check. On
+ // the other hand, the MmsProvider does verify that the _data column has an allowed value
+ // before opening any uri/files.
if (values != null && values.containsKey(Part._DATA)) {
return 0;
}
@@ -835,7 +843,12 @@ public class MmsProvider extends ContentProvider {
return null;
}
- // Verify that the _data path points to mms data
+ return safeOpenFileHelper(uri, mode);
+ }
+
+ @NonNull
+ private ParcelFileDescriptor safeOpenFileHelper(
+ @NonNull Uri uri, @NonNull String mode) throws FileNotFoundException {
Cursor c = query(uri, new String[]{"_data"}, null, null, null);
int count = (c != null) ? c.getCount() : 0;
if (count != 1) {
@@ -856,10 +869,16 @@ public class MmsProvider extends ContentProvider {
c.close();
if (path == null) {
- return null;
+ throw new FileNotFoundException("Column _data not found.");
}
+
+ File filePath = new File(path);
try {
- File filePath = new File(path);
+ // The MmsProvider shouldn't open a file that isn't MMS data, so we verify that the
+ // _data path actually points to MMS data. That safeguards ourselves from callers who
+ // inserted or updated a URI (more specifically the _data column) with disallowed paths.
+ // TODO(afurtado): provide a more robust mechanism to avoid disallowed _data paths to
+ // be inserted/updated in the first place, including via SQL injection.
if (!filePath.getCanonicalPath()
.startsWith(getContext().getApplicationInfo().dataDir + "/app_parts/")) {
return null;
@@ -868,7 +887,8 @@ public class MmsProvider extends ContentProvider {
return null;
}
- return openFileHelper(uri, mode);
+ int modeBits = ParcelFileDescriptor.parseMode(mode);
+ return ParcelFileDescriptor.open(filePath, modeBits);
}
private void filterUnsupportedKeys(ContentValues values) {