From: eLinux.org

Android Security

Contents

Overview

The overall architecture of Android security is described at:
http://developer.android.com/guide/topics/security/security.html

Each application is given its own Linux user id (UID) and group ID

Kernel-level security

Users and groups

Each application is assigned a uid and gid at install time. Application
data files are stored in /data/data/\/…, and are
read-writable only by that application process.

Sample File Permissions

Here is an example from my ADP1 phone (lots of lines omitted to reduce
noise):

(Oh, and yes, I’m using busybox - find, xargs, and sort are not
available otherwise)

  1. # find /data/data -type f | xargs ls -l | sort -k3 -n
  2. -rw------- 1 1000 1000 1954 Nov 12 01:10 /data/data/com.android.providers.subscribedfeeds/files/sslcache/android.clients.google.com.443
  3. -rw-r--r-- 1 1000 1000 147608 Apr 6 2009 /data/data/com.google.tts/lib/libspeechsynthesis.so
  4. -rw-rw---- 1 1000 1000 65 Nov 5 02:01 /data/data/com.google.android.systemupdater/shared_prefs/system_update_helper.xml
  5. -rw-rw---- 1 1000 1000 679 Nov 11 23:18 /data/data/com.android.settings/shared_prefs/com.android.settings_preferences.xml
  6. -rw-rw---- 1 1000 1000 2000 May 14 20:07 /data/data/com.google.android.location/files/DATA_Preferences
  7. -rw-rw---- 1 1000 1000 6144 Dec 19 2008 /data/data/com.android.settings/databases/webviewCache.db
  8. -rw-rw---- 1 1000 1000 11264 Nov 12 01:10 /data/data/com.android.providers.subscribedfeeds/databases/subscribedfeeds.db
  9. -rw-rw---- 1 1000 1000 14336 Dec 19 2008 /data/data/com.android.settings/databases/webview.db
  10. -rw-rw---- 1 1000 1000 36864 Nov 12 18:23 /data/data/com.android.providers.settings/databases/settings.db
  11. -rw-rw---- 1 1000 1000 129024 Nov 12 18:45 /data/data/com.google.android.server.checkin/databases/checkin.db
  12. -rw-rw-r-- 1 1000 1000 120 Nov 12 01:09 /data/data/com.android.providers.subscribedfeeds/shared_prefs/subscribedFeeds.xml
  13. -rwxrwx--- 1 1000 1000 54052 Dec 20 2008 /data/data/com.android.settings/files/wallpaper
  14. -rw------- 1 1001 1001 4 Oct 31 21:09 /data/data/com.android.providers.telephony/app_parts/PART_1257023388570
  15. -rw------- 1 1001 1001 4 Oct 31 21:10 /data/data/com.android.providers.telephony/app_parts/PART_1257023445796
  16. ...
  17. -rw-rw---- 1 1001 1001 103 May 13 2009 /data/data/com.android.providers.telephony/shared_prefs/preferred-apn.xml
  18. -rw-rw---- 1 1001 1001 122 Oct 28 17:37 /data/data/com.android.phone/shared_prefs/com.android.phone_preferences.xml
  19. -rw-rw---- 1 1001 1001 126 Sep 3 2008 /data/data/com.android.phone/shared_prefs/_has_set_default_values.xml
  20. -rw-rw---- 1 1001 1001 7168 Nov 5 02:01 /data/data/com.android.providers.telephony/databases/telephony.db
  21. -rw-rw---- 1 1001 1001 69632 Nov 6 01:58 /data/data/com.android.providers.telephony/databases/mmssms.db
  22. -rw-rw---- 1 10000 10000 114 Apr 20 2009 /data/data/com.android.alarmclock/shared_prefs/AlarmClock.xml
  23. -rw-rw---- 1 10000 10000 4096 Dec 19 2008 /data/data/com.android.alarmclock/databases/alarms.db
  24. -rw-rw---- 1 10001 10001 7168 Nov 12 18:43 /data/data/org.koxx.forecast_weather.v2/databases/forecasts.db
  25. -rw-rw---- 1 10002 10002 489 Nov 11 23:19 /data/data/com.android.calculator2/files/calculator.data
  26. -rw-rw---- 1 10003 10003 683 Jun 10 19:27 /data/data/com.android.camera/shared_prefs/com.android.camera_preferences.xml
  27. -rw-rw---- 1 10003 10003 5120 Dec 20 2008 /data/data/com.android.providers.drm/databases/drm.db
  28. -rw-rw---- 1 10003 10003 10240 Nov 1 16:24 /data/data/com.android.providers.downloads/databases/downloads.db
  29. -rw-rw---- 1 10003 10003 37888 May 13 2009 /data/data/com.android.providers.media/databases/internal.db
  30. -rw-rw---- 1 10003 10003 37888 Sep 4 23:25 /data/data/com.android.camera/databases/launcher.db
  31. -rw-rw---- 1 10003 10003 60416 Nov 12 19:01 /data/data/com.android.providers.media/databases/external-39636438.db
  32. -rw-r--r-- 1 10004 10004 0 Jun 12 01:13 /data/data/com.android.providers.im/databases/im.db-mj76B91FF8
  33. -rw-r--r-- 1 10004 10004 0 Jun 12 04:05 /data/data/com.android.providers.im/databases/im.db-mj0AB1E39C
  34. ...
  35. -rw-rw---- 1 10004 10004 105 Dec 18 2008 /data/data/com.android.providers.contacts/shared_prefs/owner-info.xml
  36. -rw-rw---- 1 10004 10004 125 Nov 11 16:37 /data/data/com.android.contacts/shared_prefs/dialtacts.xml
  37. -rw-rw---- 1 10004 10004 126 Dec 19 2008 /data/data/com.android.contacts/shared_prefs/_has_set_default_values.xml
  38. -rw-rw---- 1 10004 10004 146 Aug 28 16:02 /data/data/com.android.contacts/shared_prefs/com.android.contacts_preferences.xml
  39. -rw-rw---- 1 10004 10004 169 Nov 5 02:01 /data/data/com.android.launcher/shared_prefs/launcher.xml
  40. -rw-rw---- 1 10004 10004 4096 Jan 30 2009 /data/data/com.android.providers.userdictionary/databases/user_dict.db
  41. -rw-rw---- 1 10004 10004 20480 Oct 31 21:12 /data/data/com.android.launcher/databases/launcher.db
  42. -rw-rw---- 1 10004 10004 21504 Nov 12 18:45 /data/data/com.android.providers.im/databases/im.db
  43. -rw-rw---- 1 10004 10004 110592 Nov 12 02:08 /data/data/com.android.providers.contacts/databases/contacts.db
  44. -rw------- 1 10005 10005 270 Jun 13 03:36 /data/data/com.android.email/databases/0c180cf8-fb7b-4d3e-b994-4282611af63a.db_att/32
  45. -rw-r--r-- 1 10005 10005 1418240 Nov 5 02:01 /data/data/com.android.email/databases/0c180cf8-fb7b-4d3e-b994-4282611af63a.db
  46. -rw-rw---- 1 10005 10005 1866 Dec 20 2008 /data/data/com.android.email/shared_prefs/AndroidMail.Main.xml
  47. -rw-rw---- 1 10005 10005 6144 Sep 8 01:35 /data/data/com.android.email/databases/webviewCache.db
  48. -rw-rw---- 1 10005 10005 14336 May 14 17:58 /data/data/com.android.email/databases/webview.db
  49. -rw-rw---- 1 10006 10006 126 Dec 18 2008 /data/data/com.google.android.gm/shared_prefs/_has_set_default_values.xml
  50. -rw-rw---- 1 10006 10006 199 Jan 22 2009 /data/data/com.google.android.gm/shared_prefs/Gmail.xml
  51. -rw-rw---- 1 10006 10006 6144 Dec 19 2008 /data/data/com.google.android.gm/databases/gmail.db
  52. -rw-rw---- 1 10006 10006 6144 Dec 23 2008 /data/data/com.google.android.gm/databases/webviewCache.db
  53. -rw-rw---- 1 10006 10006 14336 Dec 23 2008 /data/data/com.google.android.gm/databases/webview.db
  54. -rw------- 1 10007 10007 1888 Nov 12 17:09 /data/data/com.google.android.apps.gtalkservice/files/sslcache/mtalk.google.com.5228
  55. -rw------- 1 10007 10007 1954 Nov 12 18:43 /data/data/com.google.android.providers.gmail/files/sslcache/android.clients.google.com.443
  56. -rw-rw---- 1 10007 10007 6144 Oct 23 22:43 /data/data/com.google.android.googleapps/databases/webviewCache.db
  57. -rw-rw---- 1 10007 10007 7168 May 13 2009 /data/data/com.google.android.providers.settings/databases/googlesettings.db
  58. -rw-rw---- 1 10007 10007 13312 Nov 11 20:37 /data/data/com.google.android.googleapps/databases/accounts.db
  59. -rw-rw---- 1 10007 10007 14336 May 13 2009 /data/data/com.google.android.googleapps/databases/webview.db
  60. -rw-rw---- 1 10007 10007 502784 Nov 12 18:45 /data/data/com.google.android.providers.gmail/databases/mailstore.tbird20d@gmail.com.db
  61. -rw-rw---- 1 10009 10009 126 Sep 3 2008 /data/data/com.android.mms/shared_prefs/_has_set_default_values.xml
  62. -rw-rw---- 1 10009 10009 585 Sep 3 2008 /data/data/com.android.mms/shared_prefs/com.android.mms_preferences.xml
  63. -rw-rw-rw- 1 10010 10010 310 Sep 18 01:12 /data/data/com.android.music/shared_prefs/Music.xml
  64. -rw-rw---- 1 10015 10015 126 Apr 29 2009 /data/data/com.google.android.street/shared_prefs/com.google.android.street.StreetView.xml
  65. -rw------- 1 10017 10017 35 Nov 12 16:49 /data/data/com.android.browser/cache/webviewCache/c24b0576
  66. -rw------- 1 10017 10017 43 Nov 12 16:47 /data/data/com.android.browser/cache/webviewCache/5446c8f2
  67. ...
  68. -rw------- 1 10017 10017 1204872 May 13 2009 /data/data/com.android.browser/app_plugins/gears.so
  69. -rw-r--r-- 1 10017 10017 512 Nov 12 19:18 /data/data/com.android.browser/databases/webviewCache.db-journal
  70. -rw-r--r-- 1 10017 10017 8192 May 14 19:15 /data/data/com.android.browser/gears/geolocation.db
  71. -rw-r--r-- 1 10017 10017 18432 Dec 19 2008 /data/data/com.android.browser/gears/localserver.db
  72. -rw-r--r-- 1 10017 10017 20480 Dec 19 2008 /data/data/com.android.browser/gears/permissions.db
  73. -rw-r--r-- 1 10017 10017 48128 Nov 12 19:01 /data/data/com.android.browser/app_icons/WebpageIcons.db
  74. -rw-rw---- 1 10017 10017 851 May 29 13:53 /data/data/com.android.browser/shared_prefs/com.android.browser_preferences.xml
  75. -rw-rw---- 1 10017 10017 32768 Nov 12 16:49 /data/data/com.android.browser/databases/webviewCache.db
  76. -rw-rw---- 1 10017 10017 68608 Nov 12 16:49 /data/data/com.android.browser/databases/browser.db
  77. -rw-rw---- 1 10017 10017 257024 Nov 12 17:09 /data/data/com.android.browser/databases/webview.db
  78. -rw-rw-rw- 1 10017 10017 0 Nov 12 16:48 /data/data/com.android.browser/app_plugins/gears-0.5.17.0/gearstimestamp
  79. -rw-rw---- 1 10018 10018 126 Sep 3 2008 /data/data/com.android.calendar/shared_prefs/_has_set_default_values.xml
  80. -rw-rw---- 1 10018 10018 539 Nov 11 23:19 /data/data/com.android.calendar/shared_prefs/com.android.calendar_preferences.xml
  81. -rw-rw---- 1 10018 10018 375808 Nov 12 09:58 /data/data/com.android.providers.calendar/databases/calendar.db
  82. -rw-rw---- 1 10019 10019 48 Nov 7 06:11 /data/data/com.google.android.apps.maps/files/DATA_Tiles
  83. -rw-rw---- 1 10019 10019 483 Nov 11 03:58 /data/data/com.google.android.apps.maps/shared_prefs/com.google.android.maps.MapsActivity.xml
  84. -rw-rw---- 1 10019 10019 708 Nov 12 17:09 /data/data/com.google.android.apps.maps/shared_prefs/friend_finder.xml
  85. -rw-rw---- 1 10019 10019 2000 Nov 11 03:58 /data/data/com.google.android.apps.maps/files/DATA_Preferences
  86. -rw-rw---- 1 10019 10019 6144 May 13 2009 /data/data/com.google.android.apps.maps/databases/webviewCache.db
  87. -rw-rw---- 1 10019 10019 6144 Nov 1 21:28 /data/data/com.google.android.apps.maps/databases/search_history.db
  88. -rw-rw---- 1 10019 10019 8192 Nov 11 03:52 /data/data/com.google.android.apps.maps/databases/friends.db
  89. -rw-rw---- 1 10019 10019 14336 May 13 2009 /data/data/com.google.android.apps.maps/databases/webview.db
  90. -rw-rw---- 1 10019 10019 16048 Nov 7 06:11 /data/data/com.google.android.apps.maps/files/DATA_Tiles_1
  91. -rw-rw-rw- 1 10019 10019 65 Nov 11 03:52 /data/data/com.google.android.apps.maps/shared_prefs/extra-features.xml
  92. -rw-rw---- 1 10021 10021 435 Oct 30 17:09 /data/data/com.android.vending/shared_prefs/vending_preferences.xml
  93. -rw-rw---- 1 10021 10021 5120 Oct 6 19:38 /data/data/com.android.vending/databases/suggestions.db
  94. -rw-rw---- 1 10021 10021 6144 May 14 17:17 /data/data/com.android.vending/databases/webviewCache.db
  95. -rw-rw---- 1 10021 10021 14336 May 14 17:21 /data/data/com.android.vending/databases/webview.db
  96. -rw-rw---- 1 10021 10021 17408 Oct 6 19:39 /data/data/com.android.vending/databases/assets.db
  97. -rw------- 1 10022 10022 50077 Nov 12 05:34 /data/data/com.google.android.youtube/cache/videos?vq=peter+sellers+inspector&format=2&restriction=us&start-index=18&max-results=8
  98. -rw------- 1 10022 10022 53110 Nov 12 05:33 /data/data/com.google.android.youtube/cache/videos?vq=peter+sellers+inspector&format=2&restriction=us&start-index=10&max-results=8
  99. -rw------- 1 10022 10022 57403 Nov 12 05:33 /data/data/com.google.android.youtube/cache/videos?vq=peter+sellers+inspector&format=2&restriction=us&start-index=1&max-results=9
  100. -rw------- 1 10022 10022 63761 Nov 12 05:32 /data/data/com.google.android.youtube/cache/recently_featured?format=2&start-index=1&max-results=9
  101. -rw-rw---- 1 10022 10022 739 Nov 12 16:45 /data/data/com.google.android.youtube/shared_prefs/youtube.xml
  102. -rw-rw---- 1 10022 10022 5120 Nov 12 05:34 /data/data/com.google.android.youtube/databases/suggestions.db
  103. -rw-rw---- 1 10025 10025 114 May 13 2009 /data/data/com.google.android.voicesearch/shared_prefs/com.google.android.voicesearch_preferences.xml
  104. -rw-rw---- 1 10025 10025 126 May 13 2009 /data/data/com.google.android.voicesearch/shared_prefs/_has_set_default_values.xml
  105. -rw-rw---- 1 10025 10025 2000 May 13 2009 /data/data/com.google.android.voicesearch/files/DATA_Preferences
  106. -rw-rw---- 1 10025 10025 8192 Jun 10 03:25 /data/data/com.google.android.voicesearch/databases/webviewCache.db
  107. -rw-rw---- 1 10025 10025 14336 May 13 2009 /data/data/com.google.android.voicesearch/databases/webview.db
  108. -rw-rw---- 1 10026 10026 688 Jan 10 2009 /data/data/com.quirkconsulting/shared_prefs/TouchTipv2.xml
  109. -rw-rw---- 1 10026 10026 6144 Dec 19 2008 /data/data/com.quirkconsulting/databases/webviewCache.db
  110. -rw-rw---- 1 10026 10026 14336 Dec 19 2008 /data/data/com.quirkconsulting/databases/webview.db
  111. -rw------- 1 10027 10027 4326 Aug 8 01:03 /data/data/com.a0soft.gphone.aCurrency/app_db/currency.db
  112. -rw-rw---- 1 10027 10027 170 Aug 8 01:04 /data/data/com.a0soft.gphone.aCurrency/shared_prefs/com.a0soft.gphone.aCurrency_preferences.xml
  113. -rw-rw---- 1 10027 10027 740 Dec 20 2008 /data/data/com.a0soft.gphone.aCurrency/shared_prefs/pref2.xml
  114. -rw-rw---- 1 10027 10027 801 Aug 8 01:05 /data/data/com.a0soft.gphone.aCurrency/shared_prefs/pref3.xml
  115. -rw-rw---- 1 10027 10027 6144 Aug 8 01:03 /data/data/com.a0soft.gphone.aCurrency/databases/webviewCache.db
  116. -rw-rw---- 1 10027 10027 14336 Aug 8 01:03 /data/data/com.a0soft.gphone.aCurrency/databases/webview.db
  117. -rw-rw---- 1 10028 10028 14336 Sep 19 22:17 /data/data/com.stylem.movies/databases/webview.db
  118. -rw-rw---- 1 10028 10028 53248 Sep 19 22:18 /data/data/com.stylem.movies/databases/webviewCache.db
  119. -rw-rw---- 1 10029 10029 241 Jan 10 2009 /data/data/com.capaci.android.flashlight/shared_prefs/SettingsFile.xml
  120. -rw-rw---- 1 10030 10030 233 Jun 15 15:02 /data/data/com.weather.Weather/files/tile-Radar-023010230-200906151450-twc.png
  121. -rw-rw---- 1 10030 10030 233 Jun 15 15:02 /data/data/com.weather.Weather/files/tile-Radar-023010231-200906151450-twc.png
  122. -rw-rw---- 1 10030 10030 233 Jun 15 15:02 /data/data/com.weather.Weather/files/tile-Radar-023010232-200906151450-twc.png
  123. -rw-rw---- 1 10030 10030 233 Mar 18 2009 /data/data/com.weather.Weather/files/tile-Radar-023010221-200903181940-twc.png
  124. -rw-rw---- 1 10030 10030 233 Mar 18 2009 /data/data/com.weather.Weather/files/tile-Radar-023010223-200903181940-twc.png
  125. -rw-rw---- 1 10030 10030 233 Mar 18 2009 /data/data/com.weather.Weather/files/tile-Radar-023010230-200903181940-twc.png
  126. -rw-rw---- 1 10030 10030 233 Mar 18 2009 /data/data/com.weather.Weather/files/tile-Radar-023010232-200903181940-twc.png

When Dalvik (actually, the ‘zygote’ process’) loads an application, it
changes to the uid and gid for the application, so that the process is
running in the correct security context.

Sample Process List

If you compare the Uids below with the above list, you’ll see the
correspondence between the assigned UID and the running processes. (For
example, 10017 is the browser).

  1. # ps
  2. PID Uid VSZ Stat Command
  3. 1 0 288 S /init
  4. [kernel threads omitted...]
  5. 30 1000 808 S /system/bin/servicemanager
  6. 31 0 848 S /system/bin/vold
  7. 32 0 668 S /system/bin/debuggerd
  8. 33 1001 7888 S /system/bin/rild
  9. 34 0 70548 S zygote /bin/app_process -Xzygote /system/bin --zygote
  10. 35 1013 30032 S /system/bin/mediaserver
  11. 36 1002 1172 S /system/bin/dbus-daemon --system --nofork
  12. 37 0 816 S /system/bin/installd
  13. 39 0 744 S /system/bin/sh /runme.sh
  14. 40 1008 1304 S /system/bin/akmd
  15. 41 0 3340 S /sbin/adbd
  16. 64 1000 171284 S system_server
  17. 108 1001 122172 S com.android.phone
  18. 110 10004 129936 S android.process.acore
  19. 387 10004 101668 S com.android.inputmethod.latin
  20. 6721 10017 158272 S com.android.browser
  21. 6901 10019 96340 S com.google.android.apps.maps
  22. 7166 0 740 S /system/bin/sh -
  23. 7635 10007 123776 S com.google.process.gapps
  24. 7727 10000 91284 S com.android.alarmclock
  25. 7753 0 872 S sleep 3
  26. 7754 0 2104 R ps

Paranoid network-ing

Android adds a “paranoid network” option to the Linux kernel, which
restricts access to some networking features depending on the group of
the calling process.

The list of groups that are allowed access to networking features is in
the kernel source file: /include/linux/android_aids.h

Here is the list:


































#defineGIDCapability
AID_NET_BT_ADMIN3001Can create an RFCOMM, SCO, or L2CAPP Bluetooth socket
AID_NET_BT3002Can create a Bluetooth socket
AID_INET3003Can create IPv4 or IPv6 socket
AID_NET_RAW3004Can create certain kinds of IPv4 sockets??
AID_NET_ADMIN*3005Allow CAP_NET_ADMIN permissions for process

Note: * Added in Donut (not in original Android 1.0)

Application-level security

Android also uses a user-space level security system to regulate
communication and interaction among applications and system components.
This is described at:
http://developer.android.com/guide/topics/security/security.html

Tutorial

See
http://siis.cse.psu.edu/android-tutorial.html

(With an abridged version at:
http://siis.cse.psu.edu/android_sec_tutorial.html)

Security Analysis

See a good analysis of Android security at:
http://www.isecpartners.com/files/iSEC_Android_Exploratory_Blackhat_2009.pdf

Security Investigations

TOMOYO Linux investigation

Presentation

Code

Contact

haradats@gmail.com

Security Tricks

Changing application security permissions after installation

Some applications request more permissions than they really need. You
can alter the set of permissions granted to an application by editing
/data/system/pacakges.xml.

lbcoder wrote this on the android-platform mailing list:

Go into /data/system/packages.xml and you can remove permission lines.
Immediately after saving the packages.xml, reboot the phone (otherwise
the file will get overwritten by the system again). The newly reduced
permissions will be read on boot.

Category: