summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Furtado <afurtado@google.com>2016-08-22 21:03:50 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-08-22 21:03:50 +0000
commit37e2a4dca915130794e2967d103f081ef9ae1b5a (patch)
tree4accdcf14f01515a1bab3a535e095bc99d5032a0
parent3c88f50e9557cb1ab5df9ba20a04d0669db48a97 (diff)
parent20903846d562d78851c4b1b108efe3597450dead (diff)
downloadandroid_packages_providers_TelephonyProvider-37e2a4dca915130794e2967d103f081ef9ae1b5a.tar.gz
android_packages_providers_TelephonyProvider-37e2a4dca915130794e2967d103f081ef9ae1b5a.tar.bz2
android_packages_providers_TelephonyProvider-37e2a4dca915130794e2967d103f081ef9ae1b5a.zip
30481342: Security Vulnerability - TOCTOU in MmsProvider allows access to files as phone (radio) uid - DO NOT MERGE am: 53ff7691e0
am: 20903846d5 Change-Id: I8fa3907f62dcdb63c29f6770dd0ae0772394c008
-rw-r--r--src/com/android/providers/telephony/MmsProvider.java37
1 files changed, 28 insertions, 9 deletions
diff --git a/src/com/android/providers/telephony/MmsProvider.java b/src/com/android/providers/telephony/MmsProvider.java
index 6b5b29e..329f505 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;
@@ -277,7 +278,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;
}
@@ -702,9 +707,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;
}
@@ -810,7 +818,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) {
@@ -831,10 +844,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().getDir(PARTS_DIR_NAME, 0).getPath())) {
Log.e(TAG, "openFile: path "
@@ -842,7 +861,6 @@ public class MmsProvider extends ContentProvider {
+ " does not start with "
+ getContext().getDir(PARTS_DIR_NAME, 0).getPath());
// Don't care return value
- filePath.delete();
return null;
}
} catch (IOException e) {
@@ -850,7 +868,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) {