Android Permissions Demystified PDF
Android Permissions Demystified PDF
Android Permissions Demystified PDF
Adrienne Porter Felt, Erika Chin, Steve Hanna, Dawn Song, David Wagner
University of California, Berkeley
{ apf, emc, sch, dawnsong, daw }@ cs.berkeley.edu
627
Contributions. We provide the following contributions: Applications can define their own permissions for the pur-
1. We developed Stowaway, a tool for detecting overpriv- pose of self-protection, but we focus on Android-defined per-
ilege in Android applications. We evaluate 940 appli- missions that protect system resources. We do not consider
cations from the Android Market with Stowaway and developer-defined permissions at any stage of our analysis.
find that about one-third are overprivileged. Similarly, we do not consider Google-defined permissions
2. We identify and quantify patterns of developer error that are included in Google applications like Google Reader
that lead to overprivilege. but are not part of the operating system.
3. Using automated testing techniques, we determine An- Permissions may be required when interacting with the
droid’s access control policy. Our results represent a system API, databases, and the message-passing system.
fifteen-fold improvement over the documentation. The public API [2] describes 8, 648 methods, some of which
Other existing tools [11, 12] and future program analyses are protected by permissions. User data is stored in Con-
could make use of our permission map to study permission tent Providers, and permissions are required for operations
usage in Android applications. Stowaway and the permis- on some system Content Providers. For example, applica-
sion map data are available at android-permissions.org. tions must hold the READ_CONTACTS permission in order to
execute READ queries on the Contacts Content Provider.
Organization. Section 2 provides an overview of Android
Applications may also need permissions to receive Intents
and its permission system, Section 3 discusses our API test-
(i.e., messages) from the operating system. Intents notify
ing methodology, and Section 4 describes our analysis of the
applications of events, such as a change in network connec-
Android API. Section 5 describes our static analysis tools
tivity, and some Intents sent by the system are delivered
for detecting overprivilege, and Section 6 discusses our ap-
only to applications with appropriate permissions. Further-
plication overprivilege analysis.
more, permissions are required to send Intents that mimic
the contents of system Intents.
2. THE ANDROID PERMISSION SYSTEM 2.2 Permission Enforcement
Android has an extensive API and permission system. We We describe how the system API, Content Providers, and
first provide a high-level overview of the Android application Intents are implemented and protected. To our knowledge,
platform and permissions. We then present a detailed de- we are the first to describe the Android permission enforce-
scription of how Android permissions are enforced. ment mechanisms in detail.
628
Application Process System Processes
Dalvik Virtual Machine Dalvik Virtual Machine
API Library Thread
IBinder
Public
Application RPC Stub Binder Service1
API
Hidden
...
Native Code Thread
Native
Application C Library Binder ServiceN
Component
Figure 1: The architecture of the Android platform. Permission checks occur in the system process.
Permissions. To enforce permissions, various parts of the permissions are applied to all resources stored by the Con-
system invoke a permission validation mechanism to check tent Provider. Restrictions can also be applied at a finer
whether a given application has a specified permission. The granularity by associating permissions with a path (e.g.,
permission validation mechanism is implemented as part of content://a/b). For example, a Content Provider that
the trusted system process, and invocations of the permis- stores both public and private notes might want to set a
sion validation mechanism are spread throughout the API. default permission requirement for the whole Content Pro-
There is no centralized policy for checking permissions when vider, but then allow unrestricted access to the public notes.
an API is called. Rather, mediation is contingent on the cor- Extra permission requirements can similarly be set for cer-
rect placement of permission validation calls. tain paths, making data under those paths accessible only
Permission checks are placed in the API implementation if the calling application has the default permissions for the
in the system process. When necessary, the API implemen- provider as well as the path-specific permissions.
tation calls the permission validation mechanism to check Content Providers can also enforce permissions program-
that the invoking application has the necessary permissions. matically: the Content Provider code that handles a query
In some cases, the API library may also redundantly check can explicitly call the system’s permission validation mech-
these permissions, but such checks cannot be relied upon: anism to require certain permissions. This gives the devel-
applications can circumvent them by directly communicat- oper greater control over the granularity of the permission
ing with the system process via the RPC stubs. Permission enforcement mechanism, allowing her to selectively require
checks therefore should not occur in the API library. In- permissions for query values or database data.
stead, the API implementation in the system process should
invoke the permission validation mechanism. 2.2.3 Intents
A small number of permissions are enforced by Unix groups, Android’s Intent system is used extensively for inter- and
rather than the Android permission validation mechanism. intra-application communication. To prevent applications
In particular, when an application is installed with the INTER- from mimicking system Intents, Android restricts who may
NET, WRITE_EXTERNAL_STORAGE, or BLUETOOTH permissions, it send certain Intents. All Intents are sent through the Ac-
is assigned to a Linux group that has access to the pertinent tivityManagerService (a system service), which enforces this
sockets and files. Thus, the Linux kernel enforces the access restriction. Two techniques are used to restrict the sending
control policy for these permissions. The API library (which of system Intent. Some Intents can only be sent by appli-
runs with the same rights as the application) can accordingly cations with appropriate permissions. Other system Intents
operate directly on these sockets and files, without needing can only be sent by processes whose UID matches the sys-
to invoke the API implementation in the system process. tem’s. Intents in the latter category cannot be sent by appli-
Native Code. Applications can include native code in ad- cations, regardless of what permissions they hold, because
dition to Java code, but native code is still beholden to the these Intents must originate from the system process.
permission system. Attempts to open sockets or files are me- Applications may also need permissions to receive some
diated by Linux permissions. Native code cannot communi- system Intents. The OS uses the standard Android mecha-
cate directly with the system API. Instead, the application nism for restricting its Intent recipients. An application (in
must create Java wrapper methods to invoke the API on this case, the OS) may restrict who can receive an Intent by
behalf of the native code. Android permissions are enforced attaching a permission requirement to the Intent [13].
as usual when the API calls are executed.
3. PERMISSION TESTING
2.2.2 Content Providers METHODOLOGY
System Content Providers are installed as standalone ap- Android’s access control policy is not well documented,
plications, separate from the system process and API library. but the policy is necessary to determine whether applica-
They are protected with both static and dynamic permission tions are overprivileged. To address this shortcoming, we
checks, using the same mechanisms that are available to ap- empirically determined the access control policy that An-
plications to protect their own Content Providers. droid enforces. We used testing to construct a permission
Static declarations assign separate read and write per- map that identifies the permissions required for each method
missions to a given Content Provider. By default, these in the Android API. In particular, we modified Android 2.2’s
629
permission verification mechanism to log permission checks for example, a WifiManager instance can be obtained by call-
as they occur. We then generated unit test cases for API ing android.content.Context.getSystemService(String)
calls, Content Providers, and Intents. Executing these tests with the parameter "wifi". We addressed this by augment-
allowed us to observe the permissions required to interact ing the input pool with specific primitive constants and se-
with system APIs. A core challenge was to build unit tests quences. Additionally, some API calls expect memory ad-
that obtain call coverage of all platform resources. dresses that store specific values for parameters, which we
were unable to solve at scale.
3.1 The API Randoop also does not handle ordering requirements that
As described in §2.2.1, the Android API provides applica- are independent of input parameters. In some cases, An-
tions with a library that includes public, private, and hidden droid expects methods to precede each other in a very spe-
classes and methods. The set of private classes includes the cific order. Randoop only generates sequence chains for the
RPC stubs for the system services.1 All of these classes and purpose of creating arguments for methods; it is not able to
methods are accessible to applications using Java reflection, generate sequences to satisfy dependencies that are not in
so we must test them to identify permission checks. We con- the form of an input variable. Further aggravating this prob-
ducted testing in three phases: feedback-directed testing; lem, many Android methods with underlying native code
customizable test case generation; and manual verification. generate segmentation faults if called out of order, which
terminates the Randoop testing process.
3.1.1 Feedback-Directed Testing
For the first phase of testing, we used Randoop, an auto-
3.1.2 Customizable Test Case Generation
mated, feedback-directed, object-oriented test generator for
Java [20, 22]. Randoop takes a list of classes as input and Randoop’s feedback-directed approach to testing failed to
searches the space of possible sequences of methods from cover certain types of methods. When this happened, there
these classes. We modified Randoop to run as an Android was no way to manually edit its test sequences to control
application and to log every method it invokes. Our modi- sequence order or establish method pre-conditions. To ad-
fications to Android log every permission that is checked by dress these limitations and improve coverage, we built our
the Android permission validation mechanism, which lets us own test generation tool. Our tool accepts a list of method
deduce which API calls trigger permission checks. signatures as input, and outputs at least one unit test for
Randoop searches the space of methods to find methods each method. It maintains a pool of default input parame-
whose return values can be used as parameters for other ters that can be passed to methods to be called. If multiple
methods. It maintains a pool of valid initial input sequences values are available for a parameter, then our tool creates
and parameters, initially seeded with primitive values (e.g., multiple unit tests for that method. (Tests are created com-
int and String). Randoop builds test sequences incremen- binatorially when multiple parameters of the same method
tally by randomly selecting a method from the test class’s have multiple possible values.) It also generates tests using
methods and selecting sequences from the input pool to null values if it cannot find a suitable parameter. Because
populate the method’s arguments. If the new sequence is our tool separates test case generation from execution, a hu-
unique, then it is executed. Sequences that complete suc- man tester can edit the test sequences produced by our tool.
cessfully (i.e., without generating an exception) are added When tests fail, we manually adjust the order of method
to the sequence pool. Randoop’s goal is full coverage of the calls, introduce extra code to satisfy method pre-conditions,
test space. Unlike comparable techniques [4,9,21], Randoop or add new parameters for the failing tests.
does not need a sample execution trace as input, making Our test generation tool requires more human effort than
large-scale testing such as API fuzzing more manageable. Randoop, but it is effective for quickly achieving coverage
Because Randoop uses Java reflection to generate the test of methods that Randoop was unable to properly invoke.
methods from the supplied list of classes, it supports test- Overseeing and editing a set of generated test cases pro-
ing non-public methods. We modified Randoop to also test duced by our tool is still substantially less work than manu-
nested classes of the input classes. ally writing test cases. Our experience with large-scale API
testing was that methods that are challenging to invoke by
Limitations. Randoop’s feedback-guided space exploration feedback-directed testing occur often enough to be problem-
is limited by the objects and input values it has access to. atic. When a human tester has the ability to edit failing
If Randoop cannot find an object of the correct type needed sequences, these methods can be properly invoked.
to invoke a method in the sequence pool, then it will never
try to invoke the method. The Android API is too large to
test all interdependent classes at once, so in practice many 3.1.3 Manual Verification
objects are not available in the sequence pool. We mitigated The first two phases of testing generate a map of the per-
this problem by testing related classes together (for example, mission checks performed by each method in the API. How-
Account and AccountManager) and adding seed sequences ever, these results contain three types of inconsistencies.
that return common Android-specific data types. Unfortu- First, the permission checks caused by asynchronous API
nately, this was insufficient to produce valid input parame- calls are sometimes incorrectly associated with subsequent
ters for many methods. Many singleton object instances can API calls. Second, a method’s permission requirements can
only be created through API calls with specific parameters; be argument-dependent, in which case we see intermittent
1 or different permission checks for that method. Third, per-
The operating system also includes many internal methods
that make permission checks. However, applications cannot mission checks can be dependent on the order in which API
invoke them because they are not currently exposed with calls are made. To identify and resolve these inconsistencies,
RPC stubs. Since we are focused on the application-facing we manually verified the correctness of the permission map
API, we do not test or discuss these permission checks. generated by the first two phases of testing.
630
We used our customizable test generation tool to create 4. PERMISSION MAP RESULTS
tests to confirm the permission(s) associated with each API Our testing of the Android application platform resulted
method in our permission map. We carefully experimented in a permission map that correlates permission requirements
with the ordering and arguments of the test cases to en- with API calls, Content Providers, and Intents. In this sec-
sure that we correctly matched permission checks to asyn- tion, we discuss our coverage of the API, compare our results
chronous API calls and identified the conditions of permis- to the official Android documentation, and present charac-
sion checks. When confirming permissions for potentially teristics of the Android API and permission map.
asynchronous or order-dependent API calls, we also created
confirmation test cases for related methods in the perti- 4.1 Coverage
nent class that were not initially associated with permission The Android API consists of 1, 665 classes with a total
checks. We ran every test case both with and without their of 16, 732 public and private methods. We attained 85%
required permissions in order to identify API calls with mul- coverage of the Android API through two phases of testing.
tiple or substitutable permission requirements. If a test case (We define a method as covered if we executed it without
throws a security exception without a permission but suc- generating an exception; we do not measure branch cover-
ceeds with a permission, then we know that the permission age.) Randoop attained an initial method coverage of 60%,
map for the method under test is correct. spread across all packages. We supplemented Randoop’s
Testing The Internet Permission. Applications can access coverage with our proprietary test generation tool, accom-
the Internet through the Android API, but other packages plishing close to 100% coverage of the methods that belong
such as java.net and org.apache also provide Internet ac- to classes with at least one permission check.
cess. In order to determine which methods require access The uncovered portion of the API is due to native calls
to the Internet, we scoured the documentation and searched and the omission of second-phase tests for packages that did
the Internet for any and all methods that suggest Internet not yield permission checks in the first phase. First, native
access. Using this list, we wrote test cases to determine methods often crashed the application when incorrect pa-
which of those methods require the INTERNET permission. rameters were supplied, making them difficult to test. Many
native method parameters are integers that represent point-
3.2 Content Providers ers to objects in native code, making it difficult to supply
Our Content Provider test application executes query, correct parameters. Approximately one-third of uncovered
insert, update, and delete operations on Content Pro- methods are native calls. Second, we decided to omit sup-
vider URIs associated with the Android system and pre- plemental tests for packages that did not reveal permission
installed appliactions. We collected a list of URIs from the checks during the Randoop testing phase. If Randoop did
android.provider package to determine the core set of Con- not trigger at least one permission check in a package, we
tent Providers to test. We additionally collected Content did not add more tests to the classes in the package.
Provider URIs that we discovered during other phases of
testing. For each URI, we attempted to execute each type 4.2 Comparison With Documentation
of database operation without any permissions. If a security Clear and well-developed documentation promotes correct
exception was thrown, we recorded the required permission. permission usage and safe programming practices. Errors
We added and tested combinations of permissions to iden- and omissions in the documentation can lead to incorrect
tify multiple or substitutable permission requirements. Each developer assumptions and overprivilege. Android’s docu-
Content Provider was tested until security exceptions were mentation of permissions is limited, which is likely due to
no longer thrown for a given operation, indicating the mini- their lack of a centralized access control policy. Our test-
mum set of permissions required to complete that operation. ing identified 1, 259 API calls with permission checks. We
In addition to testing, we also examined the system Content compare this to the Android 2.2 documentation.
Providers’ static permission declarations. We crawled the Android 2.2 documentation and found
that it specifies permission requirements for 78 methods.
3.3 Intents The documentation additionally lists permissions in several
We built a pair of applications to send and receive In- class descriptions, but it is not clear which methods of the
tents. The Android documentation does not provide a sin- classes require the stated permissions. Of the 78 permission-
gle, comprehensive list of the available system Intents, so we protected API calls in the documentation, our testing indi-
scraped the public API to find string constants that could cates that the documentation for 6 API calls is incorrect. It
be the contents of an Intent.2 We sent and received Intents is unknown to us whether the documentation or implemen-
with these constants between our test applications. In order tation is wrong; if the documentation is correct, then these
to test the permissions needed to receive system broadcast discrepancies may be security errors.
Intents, we triggered system broadcasts by sending and re- Three of the documentation errors list a different permis-
ceiving text messages, sending and receiving phone calls, sion than was found through testing. In one place, the doc-
connecting and disconnecting WiFi, connecting and discon- umentation claims an API call is protected by the Danger-
necting Bluetooth devices, etc. For all of these tests, we ous permission MANAGE_ACCOUNTS, when it actually can be
recorded whether permission checks occurred and whether accessed with the lower-privilege Normal permission GET_
the Intents were delivered or received successfully. ACCOUNTS. Another error claims an API call requires the
ACCESS_COARSE_UPDATES permission, which does not exist.
As a result, 5 of the 900 applications that we study in §6.2
request this non-existent permission. A third error states
2 that a method is protected with the BLUETOOTH permission,
For those familiar with Android terminology, we searched
for Intent action strings. when the method is in fact protected with BLUETOOTH_ADMIN.
631
Permission Usage should be substitutable for lesser permissions relating to the
BLUETOOTH 85 same resource. However, we find no evidence of planned hi-
BlUETOOTH_ADMIN 45 erarchy. Our testing indicates that BLUETOOTH_ADMIN is not
READ_CONTACTS 38 substitutable for BLUETOOTH, nor is WRITE_CONTACTS substi-
ACCESS_NETWORK_STATE 24 tutable for READ_CONTACTS. Similarly, CHANGE_WIFI_STATE
WAKE_LOCK 24 cannot be used in place of ACCESS_WIFI_STATE.
ACCESS_FINE_LOCATION 22 Only one pair of permissions has a hierarchical relation-
WRITE_SETTINGS 21 ship: ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION.
MODIFY_AUDIO_SETTINGS 21 Every method that accepts the COARSE permission also ac-
ACCESS_COARSE_LOCATION 18 cepts FINE as a substitute. We found only one exception to
CHANGE_WIFI_STATE 16 this, which may be a bug: TelephonyManager.listen() ac-
Table 1: Android’s 10 most checked permissions. cepts either ACCESS_COARSE_LOCATION or READ_PHONE_STATE,
but it does not accept ACCESS_FINE_LOCATION.
The other three documentation errors pertain to methods
Permission Granularity. If a single permission is applied
with multiple permission requirements. In one error, the
to a diverse set of functionality, applications that request the
documentation claims that a method requires one permis-
permission for a subset of the functionality will have unnec-
sion, but our testing shows that two are required. For the
essary access to the rest. Android aims to prevent this by
last two errors, the documentation states that two methods
splitting functionality into multiple permissions when possi-
require one permission each; in practice, however, the two
ble, and their approach has been shown to benefit platform
methods both accept two permissions (i.e., they are ORs).
security [15]. As a case study, we examine the division of
Bluetooth functionality, as the Bluetooth permissions are
4.3 Characterizing Permissions the most heavily checked permissions.
Based on our permission map, we characterize how per- We find that the two Bluetooth permissions are applied
mission checks are distributed throughout the API. to 6 large classes. They are divided between methods that
change state (BLUETOOTH_ADMIN) and methods that get de-
4.3.1 API Calls vice information (BLUETOOTH). The BluetoothAdapter class
We examined the Android API to see how many methods is one of several that use the Bluetooth permissions, and
and classes have permission checks. We present the number it appropriately divides most of its permission assignments.
of permission checks, unused permissions, hierarchical per- However, it features some inconsistencies. One method only
missions, permission granularity, and class characteristics. returns information but requires the BLUETOOTH_ADMIN per-
mission, and another method changes state but requires
Number of Permissions Checks. We identified 1, 244
both permissions. This type of inconsistency may lead to
API calls with permission checks, which is 6.45% of all API
developer confusion about which permissions are required
methods (including hidden and private methods). Of those,
for which types of operations.
816 are methods of normal API classes, and 428 are methods
of RPC stubs that are used to communicate with system ser- Class Characteristics. Figure 2 presents the percentage
vices. We additionally identified 15 API calls with permis- of methods that are protected per class. We initially ex-
sion checks in a supplementary part of the API added by a pected that the distribution would be bimodal, with most
manufacturer, for a total of 1, 259 API calls with permission classes protected entirely or not at all. Instead, however, we
checks. Table 1 provides the rates of the most commonly- see a wide array of class protection rates. Of these classes,
checked permissions for the normal API. only 8 require permissions to instantiate an object, and 4 re-
quire permissions only for the object constructor.
Signature/System Permissions. We found that 12% of
the normal API calls are protected with Signature/System
permissions, and 35% of the RPC stubs are protected with '%"
!"#$%&'()'*+,--%-'./'0%&1%/2,3%'4,/3%'
632
4.3.2 Content Providers and Intents that hold references to hidden interfaces. Applications can
We examined Content Providers to determine whether only access these member variables reflectively, which ob-
they are protected by permissions. We investigated a total scures their type information. We created a mapping be-
of 62 Content Providers. We found that there are 18 Con- tween member variables and their types and propagate the
tent Providers that do not have permissions for any of the type data accordingly. If an application subsequently ac-
methods that we tested (insert, query, update, and delete). cesses methods on a member variable after retrieving it, we
All of the Content Providers that lack permissions are asso- can resolve the member variable’s type.
ciated with the content://media content URI. Internet. Any application that includes a WebView must
We examined Intent communication and measured whether have the Internet permission. A WebView is a user interface
permissions are required for sending and receiving Intents. component that allows an application to embed a web site
When sending broadcast Intents, 62 broadcasts are prohib- into its UI. WebViews can be instantiated programmatically
ited by non-system senders, 6 require permissions before or declared in XML files. Stowaway identifies programmatic
sending the Intent, and 2 can be broadcast but not received instantiations of WebViews. It also decompiles application
by system receivers. Broadcast receivers must have permis- XML files and parses them to detect WebView declarations.
sions to receive 23 broadcast Intents, of which 14 are pro-
tected by a Bluetooth permission. When sending Intents External Storage. If an application wants to access files
to start Activities, 7 Intent messages require permissions. stored on the SD card, it must have the WRITE_EXTERNAL_
When starting Services, 2 Intents require permissions. STORAGE permission. This permission does not appear in
our permission map because it (1) is enforced entirely using
Linux permissions and (2) can be associated with any file
5. APPLICATION ANALYSIS TOOL operation or API call that accesses the SD card from within
We built a static analysis tool, Stowaway, which analyzes the library. We handle this permission by searching the ap-
an Android application and determines the maximum set of plication’s string literals and XML files for strings that con-
permissions it may require. Stowaway analyzes the applica- tain sdcard; if any are found, we assume WRITE_EXTERNAL_
tion’s use of API calls, Content Providers, and Intents and STORAGE is needed. Additionally, we assume this permission
then uses the permission map built in §3 to determine what is needed if we see API calls that return paths to the SD card,
permissions those operations require. such as Environment.getExternalStorageDirectory().
Compiled applications for the Android platform include
Dalvik executable (DEX) files that run on Android’s Dalvik 5.2 Content Providers
Virtual Machine. We disassemble application DEX files us- Content Providers are accessed by performing a database
ing the publicly available Dedexer tool [23]. Each stage of operation on a URI. Stowaway collects all strings that could
Stowaway takes the disassembled DEX as input. be used as Content Provider URIs and links those strings to
the Content Providers’ permission requirements. Content
5.1 API Calls Provider URIs can be obtained in two ways:
Stowaway first parses the disassembled DEX files and iden- 1. A string or set of strings can be passed into a method
tifies all calls to standard API methods. Stowaway tracks that returns a URI. For example, the API call android.
application-defined classes that inherit methods from An- net.Uri.parse("content://browser/bookmarks") re-
droid classes so we can differentiate between invocations of turns a URI for accessing the Browser bookmarks. To
application-defined methods and Android-defined inherited handle this case, Stowaway finds all string literals that
methods. We use heuristics to handle Java reflection and begin with content://.
two unusual permissions. 2. The API provides Content Provider helper classes that
Reflection. Java reflection is a challenging problem [6, 18, include public URI constants. For example, the value
24]. In Java, methods can be reflectively invoked with java. of android.provider.Browser.BOOKMARKS_URI is
lang.reflect.Method.invoke() or java.lang.reflect. content://browser/bookmarks. Stowaway recognizes
Constructor.newInstance(). Stowaway tracks which Class known URI constants, and we created a mapping from
objects and method names are propagated to the reflec- all known URI constants to their string values.
tive invocation. It performs flow-sensitive, intra-procedural A limitation of our tool is that we cannot tell which database
static analysis, augmented with inter-procedural analysis to operations an application performs with a URI; there are
a depth of 2 method calls. Within each method body, it many ways to perform an operation on a Content Provider,
tracks the value of each String, StringBuilder, Class, Method, and users can set their own query strings. To account for
Constructor, Field, and Object. We also track the state of this, we say that an application may require any permission
static member variables of these types. We identify method associated with any operation on a given Content Provider
calls that convert strings and objects to type Class, as well URI. This provides an upper bound on the permissions that
as method calls that convert Class objects to Methods, Con- could be required in order to use a specific Content Provider.
structors, and Fields.
We also apply Android-specific heuristics to resolving re- 5.3 Intents
flection by handling methods and fields that may affect re- We use ComDroid [8] to detect the sending and receiv-
flective calls. We cannot model the behavior of the en- ing of Intents that require permissions. ComDroid performs
tire Android and Java APIs, but we identify special cases. flow-sensitive, intra-procedural static analysis, augmented
First, Context.getSystemService(String) returns differ- with limited inter-procedural analysis that follows method
ent types of objects depending on the argument. We main- invocations to a depth of one method call. ComDroid tracks
tain a mapping of arguments to the types of return objects. the state of Intents, registers, sinks (e.g., sendBroadcast),
Second, some API classes contain private member variables and application components. When an Intent object is in-
633
stantiated, passed as a method parameter, or obtained as We also analyzed overprivilege warnings by running the
a return value, ComDroid tracks all changes to it from its application in our modified version of Android (which records
source to its sink and outputs all information about the In- permission checks as they occur) and interacting with it. It
tent and all components expecting to receive messages. was not possible to test all applications at runtime; for ex-
Stowaway takes ComDroid’s output and, for each sent In- ample, some applications rely on server-side resources that
tent, checks whether a permission is required to send that have moved or changed since we downloaded them. We were
Intent. For each Intent that an application is registered to able to test 10 of the 18 application in this way. In each case,
receive, Stowaway checks whether a permission is required runtime testing confirmed the results of our code review.
to receive the Intent. Occasionally ComDroid is unable to
identify the message or sink of an Intent. To mitigate these 6.1.2 False Positives
cases, Stowaway searches for protected Intents in the list of Stowaway identified 18 of the 40 applications (45%) as
all string literals in the application. having 42 unnecessary permissions. Our manual review de-
termined that 17 applications (42.5%) are overprivileged,
6. APPLICATION ANALYSIS RESULTS with a total of 39 unnecessary permissions. This represents
We applied Stowaway to 940 Android applications to iden- a 7% false positive rate.
tify the prevalence of overprivilege. Applications with un- All three of the false warnings were caused by incom-
necessary permissions violate the principle of least privilege. pleteness in our permission map. Each was a special case
Overprivilege undermines the benefits of a per-application that we failed to anticipate. Two of the three false positives
permission system: extra permissions unnecessarily condi- were caused by applications using Runtime.exec to execute
tion users to casually accept dangerous permissions and need- a permission-protected shell command. (For example, the
lessly exacerbate application vulnerabilities. logcat command performs a READ_LOGS permission check.)
Stowaway calculates the maximum set of Android permis- The third false positive was caused by an application that
sions that an application may need. We compare that set to embeds a web site that uses HTML5 geolocation, which re-
the permissions actually requested by the application. If the quires a location permission. We wrote test cases for these
application requests more permissions, then it is overprivi- scenarios and updated our permission map.
leged. Our full set of applications consists of 964 Android Of the 40 applications in this set, 4 contain at least one
2.2 applications.3 We set aside 24 randomly selected appli- reflective call that our static analysis tool cannot resolve or
cations for tool testing and training, leaving 940 for analysis. dismiss. 2 of them are overprivileged. This means that 50%
of the applications with at least one unresolved reflective call
6.1 Manual Analysis are overprivileged, whereas other applications are overpriv-
ileged at a rate of 42%. However, a sample size of 4 is too
6.1.1 Methodology small to draw conclusions. We investigated the unresolved
We randomly selected 40 applications from the set of 940 reflective calls and do not believe they led to false positives.
and ran Stowaway on them. Stowaway identified 18 appli-
cations as overprivileged. We then manually analyzed each 6.2 Automated Analysis
overprivilege warning to attribute it to either tool error (i.e., We ran Stowaway on 900 Android applications. Over-
a false positive) or developer error. We looked for false pos- all, Stowaway identified 323 applications (35.8%) as hav-
itives due to three types of failures: ing unnecessary permissions. Stowaway was unable to re-
1. Stowaway misses an API, Content Provider, or Intent solve some applications’ reflective calls, which might lead
operation that needs a permission. For example, Stow- to a higher false positive rate in those applications. Con-
away misses an API call when it cannot resolve the sequently, we discuss applications with unresolved reflective
target of a reflective call. calls separately from other applications.
2. Stowaway correctly identifies the API, Content Pro-
vider, or Intent operation, but our permission map 6.2.1 Applications With Fully Handled Reflection
lacks an entry for that platform resource. Stowaway was able to handle all reflective calls for 795 of
3. The application sends an Intent to some other ap- the 900 applications, meaning that it should have identified
plication, and the recipient accepts Intents only from all API access for those applications. Stowaway produces
senders with a certain permission. Stowaway cannot overprivilege warnings for 32.7% of the 795 applications. Ta-
detect this case because we cannot determine the per- ble 2 shows the 10 most common unnecessary permissions
mission requirements of other non-system applications. among these applications.
We reviewed the 18 applications’ bytecode, searching for 56% of overprivileged applications have 1 extra permis-
any of these three types of error. If we found functionality sion, and 94% have 4 or fewer extra permissions. Although
that could plausibly pertain to a permission that Stowaway one-third of applications are overprivileged, the low degree
identified as unnecessary, we manually wrote additional test of per-application overprivilege indicates that developers are
cases to confirm the accuracy of our permission map. We attempting to add correct permissions rather than arbitrar-
investigated the third type of error by checking whether the ily requesting large numbers of unneeded permissions. This
application sends Intents to pre-installed or well-known ap- supports the potential effectiveness of install-time permis-
plications. When we determined that a warning was not a sion systems like Android’s.
false positive, we attempted to identify why the developer We believe that Stowaway should produce approximately
had added the unnecessary permission. the same false positive rate for these applications as it did
3
In October 2010, we downloaded the 100 most popular paid for the set of 40 that we evaluated in §6.1. If we assume
applications, the 764 most popular free applications, and 100 that the 7% false positive rate from our manual analysis
recently added free applications from the Android Market. applies to these results, then 30.4% of the 795 applications
634
Permission Usage tive calls. Although our manual review (§6.1) did not find
ACCESS_NETWORK_STATE 16% that reflective failures led to false positives, a subsequent re-
READ_PHONE_STATE 13% view of additional applications identified several erroneous
ACCESS_WIFI_STATE 8% warnings that were caused by reflection. On the other hand,
WRITE_EXTERNAL_STORAGE 7% developer error may increase with the complexity associated
CALL_PHONE 6% with complicated reflective calls.
ACCESS_COARSE_LOCATION 6% Improving the resolution of reflective calls in Android ap-
CAMERA 6% plications is an important open problem. Stowaway’s re-
WRITE_SETTINGS 5% flection analysis fails when presented with the creation of
ACCESS_MOCK_LOCATION 5% method names based on non-static environment variables,
GET_TASKS 5% direct generation of Dalvik bytecode, arrays with two point-
Table 2: The 10 most common unnecessary permis- ers that reference the same location, or Method and Class
sions and the percentage of overprivileged applica- objects that are stored in hash tables. Stowaway’s primar-
tions that request them. ily linear traversal of a method also experiences problems
with non-linear control flow, such as jumps; we only handle
Apps with Total simple gotos that appear at the ends of methods. We also
Warnings Apps Rate observed several applications that iterate over a set of classes
Reflection, failures 56 105 53% or methods, testing each element to decide which one to in-
Reflection, no failures 151 440 34% voke reflectively. If multiple comparison values are tested
No reflection 109 355 31% and none are used within the block, Stowaway only tracks
Table 3: The rates at which Stowaway issues over- the last comparison value beyond the block; this value may
privilege warnings, by reflection status. be null. Future work may be able to solve some of these
problems, possibly with the use of dynamic analysis.
are truly overprivileged. Applications could also be more
overprivileged in practice than indicated by our tool, due to 6.3 Common Developer Errors
unreachable code. Stowaway does not perform dead code In some cases, we are able to determine why developers
elimination; dead code elimination for Android applications asked for unnecessary permissions. Here, we consider the
would need to take into account the unique Android lifecycle prevalence of different types of developer error among the
and application entry points. Additionally, our overapprox- 40 applications from our manual review and the 795 fully
imation of Content Provider operations (§5.2) might over- handled applications from our automated analysis.
look some overprivilege. We did not quantify Stowaway’s
false negative rate, and we leave dead code elimination and Permission Name. Developers sometimes request permis-
improved Content Provider string tracking to future work. sions with names that sound related to their applications’
functionality, even if the permissions are not required. For
6.2.2 The Challenges of Java Reflection example, one application from our manual review unnec-
essarily requests the MOUNT_UNMOUNT_FILESYSTEMS permis-
Reflection is commonly used in Android applications. Of
sion to receive the android.intent.action.MEDIA_MOUNTED
the 900 applications, 545 (61%) use Java reflection to make
Intent. As another example, the ACCESS_NETWORK_STATE
API calls. We found that reflection is used for many pur-
and ACCESS_WIFI_STATE permissions have similar-sounding
poses, such as to deserialize JSON and XML, invoke hidden
names, but they are required by different classes. Develop-
or private API calls, and handle API classes whose names
ers often request them in pairs, even if only one is necessary.
changed between versions. The prevalence of reflection indi-
Of the applications that unnecessarily request the network
cates that it is important for an Android static analysis tool
permission, 32% legitimately require the WiFi permission.
to handle Java reflection, even if the static analysis tool is
Of the applications that unnecessarily request the WiFi per-
not intended for obfuscated or malicious code.
mission, 71% legitimately need the network permission.
Stowaway was able to fully resolve the targets of reflective
calls in 59% of the applications that use reflection. We han- Deputies. An application can send an Intent to another
dled a further 117 applications with two techniques: elim- deputy application, asking the deputy to perform an op-
inating failures where the target class of the reflective call eration. If the deputy makes a permission-protected API
was known to be defined within the application, and man- call, then the deputy needs a permission. The sender of the
ually examining and handling failures in 21 highly popular Intent, however, does not. We noticed instances of appli-
libraries. This left us with 105 applications with reflective cations requesting permissions for actions that they asked
calls that Stowaway could not resolve or dismiss, which is deputies to do. For example, one application asks the An-
12% of the 900 applications. droid Market to install another application. The sender asks
Stowaway identifies 53.3% of the 105 applications as over- for INSTALL_PACKAGES, which it does not need because the
privileged. Table 3 compares this to the rate at which warn- Market application does the installation.
ings are issued for applications without unhandled reflec- We find widespread evidence of this type of error. Of the
tions. There are two possible explanations for the difference: applications that unnecessarily request the CAMERA permis-
Stowaway might have a higher false positive rate in appli- sion, 81% send an Intent that opens the default Camera
cations with unresolved reflective calls, or applications that application to take a picture. 82% of the applications that
use Java reflection in complicated ways might have a higher unnecessarily request INTERNET send an Intent that opens a
rate of actual overprivilege due to a correlated trait. URL in the browser. Similarly, 44% of the applications that
We suspect that both factors play a role in the higher over- unnecessarily request CALL_PHONE send an Intent to the de-
privilege warning rate in applications with unhandled reflec- fault Phone Dialer application.
635
Related Methods. As shown in Figure 2, most classes con- 7. RELATED WORK
tain a mix of permission-protected and unprotected meth-
ods. We have observed applications that use unprotected Android Permissions. Previous studies of Android ap-
methods but request permissions that are required for other plications have been limited in their understanding of per-
methods in the same class. For example, android.provider. mission usage. Our permission map can be used to greatly
Settings.Secure is a convenience class in the API for ac- increase the scope of application analysis. Enck et al. apply
cessing the Settings Content Provider. The class includes Fortify’s Java static analysis tool to decompiled applications;
both setters and getters. The setters require the WRITE_ they study their API use [11]. However, they are limited to
SETTINGS permission, but the getters do not. Two of the studying applications’ use of a small number of permissions
applications that we manually reviewed use only the getters and API calls. In a recent study, Felt et al. manually classify
but request the WRITE_SETTINGS permission. a small set of Android applications as overprivileged or not,
but they were limited by the Android documentation [15].
Copy and Paste. Popular message boards contain An- Kirin [12] reads application permission requirements dur-
droid code snippets and advice about permission require- ing installation and checks them against a set of security
ments. Sometimes this information is inaccurate, and de- rules. They rely solely on developer permission requests,
velopers who copy it will overprivilege their applications. rather than examining whether or how permissions are used
For example, one of the applications that we manually re- by applications. Barrera et al. examine 1, 100 Android ap-
viewed registers to receive the android.net.wifi.STATE_ plications’ permission requirements and use self-organizing
CHANGE Intent and requests the ACCESS_WIFI_STATE permis- maps to visualize which permissions are used in applications
sion. As of May 2011, the third-highest Google search re- with similar characteristics [5]. Their work also relies on the
sult for that Intent contains the incorrect assertion that it permissions requested by the applications.
requires that permission [25]. Vidas et al. [27] provide a tool that performs an overpriv-
Deprecated Permissions. Permissions that are unneces- ilege analysis on application source code. Their tool could
sary in Android 2.2 could be necessary in older Android re- be improved by using our permission map; theirs is based
leases. Old or backwards-compatible applications therefore on the limited Android documentation. Our static analysis
might have seemingly extra permissions. However, develop- tool also performs a more sophisticated application analysis.
ers may also accidentally use these permissions because they Unlike their Eclipse plugin, Stowaway attempts to handle
have read out-of-date material. 8% of the overprivileged ap- reflective calls, Content Providers, and Intents.
plications request either ACCESS_GPS or ACCESS_LOCATION, In concurrent work, Gibler et al. [16] applied static anal-
which were deprecated in 2008. Of those, all but one specify ysis to the Android API to find permission checks. Their
that their lowest supported API version is higher than the permission map includes internal methods within the sys-
last version that included those permissions. tem process that are not reachable across the RPC bound-
ary, which we excluded because applications cannot access
Testing Artifacts. A developer might add a permission them. Unlike our dynamic approach, their static analysis
during testing and then forget to remove it when the test might have false positives, will miss permission checks in
code is removed. For example, ACCESS_MOCK_LOCATION is native code, and will miss Android-specific control flow.
typically used only for testing but can be found in released
applications. All of the applications in our data set that un- Java Testing. Randoop is not the only Java unit test gen-
necessarily include the ACCESS_MOCK_LOCATION permission eration tool. Tools like Eclat [21], Palulu [4] and JCrasher [9]
also include a real location permission. work similarly but require an example execution as input.
Given the size of the Android API, building such an example
Signature/System Permissions. We find that 9% of execution would be a challenge. Enhanced JUnit [14] gen-
overprivileged applications request unneeded Signature or erates tests by chaining constructors to some fixed depth.
SignatureOrSystem permissions. Standard versions of An- However, it does not use subtyping to provide instances and
droid will silently refuse to grant those permissions to appli- relies on bytecode as input. Korat [7] requires formal specifi-
cations that are not signed by the device manufacturer. The cations of methods as input, which is infeasible for post-facto
permissions were either requested in error, or the developers testing of the Android API.
removed the related code after discovering it did not work
on standard handsets. Java Reflection. Handling Java reflection is necessary to
develop sound and complete program analyses. However, re-
We can attribute many instances of overprivilege to de- solving reflective calls is an area of open research. Livshits et
veloper confusion over the permission system. Confusion al. created a static algorithm which approximates reflective
over permission names, related methods, deputies, and dep- targets by tracking string constants passed to reflections [18].
recated permissions could be addressed with improved API Their approach falls short when the reflective call depends
documentation. To avoid overprivilege due to related meth- on user input or environment variables. We use the same ap-
ods, we recommend listing permission requirements on a proach and suffer from the same limitations. They improve
per-method (rather than per-class) basis. Confusion over their results with developer annotations, which is not a fea-
deputies could be reduced by clarifying the relationship be- sible approach for our domain. A more advanced technique
tween permissions and pre-installed system applications. combines static analysis with information about the environ-
Despite the number of unnecessary permissions that we ment of the Java program in order to resolve reflections [24].
can attribute to error, it is possible that some developers However, their results are sound only if the program is exe-
request extra permissions intentionally. Developers are in- cuted in an identical environment as the original evaluation.
centivized to ask for unnecessary permissions because ap- Even with their modifications, they are able to resolve only
plications will not receive automatic updates if the updated 74% of reflective calls in the Java 1.4 API. We do not claim
version of the application requests more permissions [15].
636
to improve the state of the art in resolving Java reflection; Communication in Android. In Proc. of the Annual
instead, we focus on domain-specific heuristics for how re- International Conference on Mobile Systems,
flection is used in Android applications. We are the first to Applications, and Services (2011).
discuss reflection in Android applications. [9] Csallner, C., and Smaragdakis, Y. JCrasher: an
automatic robustness tester for Java. Software:
8. CONCLUSION Practice and Experience 34, 11 (2004).
In this paper, we developed tools to detect overprivilege in [10] Distimo. The battle for the most content and the
Android applications. We applied automated testing tech- emerging tablet market. http://www.distimo.com/
niques to Android 2.2 to determine the permissions required blog/2011_04_the-battle-for-the-most-content
to invoke each API method. Our tool, Stowaway, generates -and-the-emerging-tablet-market.
the maximum set of permissions needed for an application [11] Enck, W., Octeau, D., McDaniel, P., and
and compares them to the set of permissions actually re- Chaudhuri, S. A Study of Android Application
quested. Currently, Stowaway is unable to handle some Security. In USENIX Security (2011).
complex reflective calls, and we identify Java reflection as an [12] Enck, W., Ongtang, M., and McDaniel, P. On
important open problem for Android static analysis tools. lightweight mobile phone application certification. In
We applied Stowaway to 940 Android applications and Proc. of the ACM conference on Computer and
found that about one-third of them are overprivileged. Our Communications Security (2009).
results show that applications generally are overprivileged [13] Enck, W., Ongtang, M., and McDaniel, P.
by only a few permissions, and many extra permissions can Understanding Android security. IEEE Security and
be attributed to developer confusion. This indicates that Privacy 7, 1 (2009).
developers attempt to obtain least privilege for their appli- [14] Enhanced JUnit. http://www.silvermark.com/
cations but fall short due to API documentation errors and Product/java/enhancedjunit/index.html.
lack of developer understanding. [15] Felt, A. P., Greenwood, K., and Wagner, D.
The Effectiveness of Application Permissions. In Proc.
Acknowledgements of the USENIX Conference on Web Application
Development (2011).
We thank Royce Cheng-Yue and Kathryn Lingel for their
[16] Gibler, C., Crussell, J., Erickson, J., and Chen,
help testing the API and Content Providers. This work is
H. AndroidLeaks: Detecting Privacy Leaks in Android
partially supported by NSF grants CCF-0424422, 0311808,
Applications. Tech. rep., UC Davis, 2011.
0832943, 0448452, 0842694, a gift from Google, and the
MURI program under AFOSR grant FA9550-08-1-0352. This [17] Hackborn, D. Re: List of private / hidden / system
material is also based upon work supported under a NSF APIs? http://groups.google.com/group/
Graduate Research Fellowship. Any opinions, findings, con- android-developers/msg/a9248b18cba59f5a.
clusions, or recommendations expressed here are those of the [18] Livshits, B., Whaley, J., and Lam, M. S.
authors and do not necessarily reflect the views of the NSF. Reflection Analysis for Java. In Asian Symposium on
Programming Languages and Systems (2005).
[19] McCluskey, G. Using Java Reflection.
9. REFERENCES http://java.sun.com/developer/
[1] Amazon Appstore for Android. http://www.amazon. technicalArticles/ALT/Reflection/, 1998.
com/mobile-apps/b?ie=UTF8&node=2350149011. [20] Pacheco, C., and Ernst, M. Randoop.
[2] Android Developers Reference. http://code.google.com/p/randoop/.
http://developer.android.com/reference/. [21] Pacheco, C., and Ernst, M. Eclat: Automatic
[3] Android Market. http://www.android.com/market/. generation and classification of test inputs. European
[4] Artzi, S., Ernst, M., Kiezun, A., Pacheco, C., Conference on Object-Oriented Programming (2005).
and Perkins, J. Finding the needles in the haystack: [22] Pacheco, C., Lahiri, S., Ernst, M., and Ball, T.
Generating legal test inputs for object-oriented Feedback-directed random test generation. In Proc. of
programs. In Workshop on Model-Based Testing and the International Conference on Software Engineering
Object-Oriented Systems (2006). (2007).
[5] Barrera, D., Kayacik, H., van Oorschot, P., [23] Paller, G. Dedexer.
and Somayaji, A. A methodology for empirical http://dedexer.sourceforge.net.
analysis of permission-based security models and its [24] Sawin, J., and Rountev, A. Improving static
application to android. In Proc. of the ACM conference resolution of dynamic class loading in java using
on Computer and Communications Security (2010). dynamically gathered environment information.
[6] Bodden, E., Sewe, A., Sinschek, J., and Mezini, Automated Software Eng. 16 (June 2009), 357–381.
M. Taming reflection: Static analysis in the presence [25] Stack Overflow. Broadcast Intent when network
of reflection and custom class loaders. Tech. Rep. state has changend.
TUD-CS-2010-0066, CASED, Mar. 2010. http://stackoverflow.com/questions/2676044/
[7] Boyapati, C., Khurshid, S., and Marinov, D. broadcast-intent-when-network-state-has-changend.
Korat: Automated testing based on Java predicates. [26] Vennon, T., and Stroop, D. Threat Analysis of the
In Proc. of the 2002 ACM SIGSOFT International Android Market. Tech. rep., SMobile Systems, 2010.
Symposium on Software Testing and Analysis (2002).
[27] Vidas, T., Christin, N., and Cranor, L. Curbing
[8] Chin, E., Felt, A. P., Greenwood, K., and Android Permission Creep. In W2SP (2011).
Wagner, D. Analyzing Inter-Application
637