32807795 Security Vulnerability - AOSP Messaging App: thirdparty can

attach private files from "/data/data/com.android.messaging/"
directory to the messaging app.

* This is a manual merge from ag/871758 -- backporting a security fix from
Bugle to Kazoo.
* Don't export the MediaScratchFileProvider or the MmsFileProvider. This
will block external access from third party apps. In addition, make both
providers more robust in handling path names. Make sure the file paths
handled in the providers point to the expected directory.

Change-Id: I9e6b3ae0e122e3f5022243418f2893d4a0859edb
Fixes: 32807795
This commit is contained in:
Tom Taylor
2016-12-05 16:39:55 -08:00
parent bcc1f62715
commit a2aa53f83a
3 changed files with 39 additions and 4 deletions

View File

@@ -317,11 +317,13 @@
<provider android:name=".datamodel.MmsFileProvider"
android:authorities="com.android.messaging.datamodel.MmsFileProvider"
android:grantUriPermissions="true" />
android:grantUriPermissions="true"
android:exported="false" />
<provider android:name=".datamodel.MediaScratchFileProvider"
android:authorities="com.android.messaging.datamodel.MediaScratchFileProvider"
android:grantUriPermissions="true" />
android:grantUriPermissions="true"
android:exported="false" />
<!-- Action Services -->

View File

@@ -32,6 +32,7 @@ import com.android.messaging.util.LogUtil;
import com.google.common.annotations.VisibleForTesting;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
@@ -89,8 +90,23 @@ public class MediaScratchFileProvider extends FileProvider {
private static File getFileWithExtension(final String path, final String extension) {
final Context context = Factory.get().getApplicationContext();
return new File(getDirectory(context),
final File filePath = new File(getDirectory(context),
TextUtils.isEmpty(extension) ? path : path + "." + extension);
try {
if (!filePath.getCanonicalPath()
.startsWith(getDirectory(context).getCanonicalPath())) {
LogUtil.e(TAG, "getFileWithExtension: path "
+ filePath.getCanonicalPath()
+ " does not start with "
+ getDirectory(context).getCanonicalPath());
return null;
}
} catch (IOException e) {
LogUtil.e(TAG, "getFileWithExtension: getCanonicalPath failed ", e);
return null;
}
return filePath;
}
private static File getDirectory(final Context context) {

View File

@@ -18,12 +18,14 @@ package com.android.messaging.datamodel;
import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import com.android.messaging.Factory;
import com.android.messaging.util.LogUtil;
import com.google.common.annotations.VisibleForTesting;
import java.io.File;
import java.io.IOException;
/**
* A very simple content provider that can serve mms files from our cache directory.
@@ -60,7 +62,22 @@ public class MmsFileProvider extends FileProvider {
private static File getFile(final String path) {
final Context context = Factory.get().getApplicationContext();
return new File(getDirectory(context), path + ".dat");
final File filePath = new File(getDirectory(context), path + ".dat");
try {
if (!filePath.getCanonicalPath()
.startsWith(getDirectory(context).getCanonicalPath())) {
LogUtil.e(TAG, "getFile: path "
+ filePath.getCanonicalPath()
+ " does not start with "
+ getDirectory(context).getCanonicalPath());
return null;
}
} catch (IOException e) {
LogUtil.e(TAG, "getFile: getCanonicalPath failed ", e);
return null;
}
return filePath;
}
private static File getDirectory(final Context context) {