Commit graph

168 commits

Author SHA1 Message Date
Jeff Sharkey
cbe69fc060 Destroy vold socket interface completely.
Long live Binder.

Test: yes
Bug: 13758960
Change-Id: If6be379b5a873f1b0c66dd1522b87413ad10fc46
2017-09-18 16:00:14 -06:00
Jeff Sharkey
52f7a91934 Move long-running calls to async with listeners.
Now that we're using Binder, we can have callers provide explicit
listeners for every request instead of trying to squeeze them all
into unsolicited socket events.

Move benchmarking to be async to avoid blocking other commands for
up to several minutes.  Remove post-trim benchmarking flag, since
benchmarking now requires a separate callback.  Will bring back in
a future CL.

Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.AdoptableHostTest
Test: adb shell sm fstrim
Bug: 62201209, 13758960
Change-Id: I0f2ebf1ac3b4252ecd6b44303f2887adfdb58e86
2017-09-15 14:18:00 -06:00
Jeff Sharkey
11c2d380a7 Move even more vold commands over to Binder.
This moves fstrim, obb and appfuse commands over to the new Binder
interface.  This change also separates creating/destroying and
mounting/unmounting of OBB volumes, which means they finally flow
nicely into the modern VolumeInfo/VolumeBase design.

We now generate unique identifiers for all OBB volumes, instead of
using a shady MD5 hash.

Change all "loop" and "dm" devices to tag the kernel resources with
a vold-specific prefix so that we can clean them up if vold crashes;
there are new destroyAll() methods that handle this cleanup.

Move appfuse mounting/unmounting into VolumeManager so it can be
shared.  Move various model objects into a separate directory to
tidy things up.

Test: cts-tradefed run commandAndExit cts-dev -m CtsOsTestCases -t android.os.storage.cts.StorageManagerTest
Bug: 13758960
Change-Id: I7294e32b3fb6efe07cb3b77bd20166e70b66958f
2017-09-11 18:44:17 -06:00
Jeff Sharkey
9462bdd512 Move "volume" commands over to Binder.
Keep the old socket-based commands intact for awhile so we can
rapidly disable this change using the ENABLE_BINDER feature flag.

Define constants in AIDL to keep Java and C++ in sync.

Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.ExternalStorageHostTest
Test: cts-tradefed run commandAndExit cts-dev --abi armeabi-v7a -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.AdoptableHostTest
Bug: 13758960
Change-Id: I0d6f82cbebe67f671b60949fd727409aeb1fdc0d
2017-09-07 15:27:30 -06:00
Keun-young Park
23b87ecf41 Merge "mInternalEmulated could be used after shutdown() called" am: 9b4a443bd6 am: 92052aa582
am: 1b6d8237f2

Change-Id: I71b1ec275e2850c1a8273ac5eebc7373a0729552
2017-08-17 22:21:40 +00:00
Keun-young Park
92052aa582 Merge "mInternalEmulated could be used after shutdown() called"
am: 9b4a443bd6

Change-Id: Ia1007988297c39f391b35ad51645556ceeaf0cc6
2017-08-17 22:13:40 +00:00
Gao Xiang
d263da8807 mInternalEmulated could be used after shutdown() called
It fixes the findvolume() / reset() use-after-free issue after
shutdown called to avoid vold crash.

Fixes: a5bbb5e3c1 ("make shutdown safe for double calls.")
Change-Id: I50f216141b20da08549080291091dc5690c00ffe
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
2017-08-14 14:26:56 +08:00
Keun-young Park
375ac25773 do not sleep if it is shutting down
- Various sleep(5) for vold shutdown can increase shutdown time a lot.
- If it is shutting down, do not sleep at all. init will take care of
  active partitions if not unmounted.

bug: 64143519
Test: reboot and check logs from vold, check if "ShutdownThread: Shutdown wait timed out" happens.
Change-Id: I7cb91427ad2205fe23a054d255caf7ffdfd9f6c3
2017-08-02 17:45:48 -07:00
Elliott Hughes
e4775fdbca Merge "vold should #include <sys/sysmacros.h>" am: 398c0e8274 am: 208b464f72 am: fb3e85cf99
am: 048422d46e

Change-Id: I33406265fcf0c77a6289cb429aa6a2cc5e8f7146
2017-05-19 19:01:20 +00:00
Elliott Hughes
048422d46e Merge "vold should #include <sys/sysmacros.h>" am: 398c0e8274 am: 208b464f72
am: fb3e85cf99

Change-Id: I32ed2a66bb60ba1042737b4bbb0a2195a3fe8e6f
2017-05-19 18:38:38 +00:00
Elliott Hughes
0e08e84df0 vold should #include <sys/sysmacros.h>
Bug: https://github.com/android-ndk/ndk/issues/398
Test: builds
Change-Id: I7a1ca1701099886fb493cc5288d6ee867d5f520a
2017-05-18 09:08:24 -07:00
Jeff Sharkey
32ebb739cb Enable clang-tidy for security sensitive domain.
Start with clang-analyzer-security* and cert-*, but disable two
specific errors:

-- cert-err34-c, which checks for atoi(); heavily triggered by
CommandListener, but will disappear when we move to Binder.
-- cert-err58-cpp, which checks for exceptions before main(); it's
a "Low" severity issue, and filed 36656327 to track cleanup.

Fix all other triggered errors along the way.

Test: builds, boots
Bug: 36655947
Change-Id: I1391693fb521ed39700e25ab6b16bc741293bb79
2017-03-27 17:14:52 -06:00
Jeff Sharkey
fd3dc3c076 Spread around some O_CLOEXEC love.
Also remove some unnecessary SELinux logic when creating image files
for loop devices.

Test: builds, boots, common operations work
Bug: 34903607
Change-Id: I68dfa022ecc39f56c175e786694e0de35b954ca0
2017-03-27 11:13:36 -06:00
Jeff Sharkey
fa1c677c1a Add a new "virtual disk" feature.
It's extremely difficult to test storage related logic on devices
that don't have physical SD card slots.  So to support better
debugging and testing, add a new "virtual disk" feature which mounts
a 512MB file through loop device.

It relies on the kernel having the "loop.max_part" value set to
something other than 0 via the boot command line, since that allows
all the existing partition logic to fall into place.

Bug: 34903607
Test: builds, boots, virtual disk works
Change-Id: I04c5b33e37319d867542985a56b7999a9b7cf35d
2017-03-25 23:25:14 -06:00
Keun-young Park
3918ae6c76 Merge "make shutdown safe for double calls." am: 71fa1068de am: 2f93c657f4
am: 2a8605b9d1

Change-Id: Id1cd83d307e7791359bc6dfd96368f1138ff21d2
2017-03-15 02:56:40 +00:00
Keun-young Park
a5bbb5e3c1 make shutdown safe for double calls.
- In new shutdown sequence, volume shutdown is requested in two places:
  system_server and init.
- Make VolumeManager.shutdown safe for double calls.
  It crashed before this change.

bug: 36004738
Test: reboot and check last_kmsg for crash / vdc timeout
Change-Id: I296913959b2647b65d66553073f2032545beba57
2017-03-14 17:27:02 -07:00
Wei Wang
b7336860a6 Merge "Remove coldboot from vold" am: cc29c526d4 am: 9a2e29fe32 am: 78bf4cbb12
am: 787930f5b6

Change-Id: Id9b356819d22c23d79a576851580a1016f799ecb
2017-01-25 19:52:55 +00:00
Wei Wang
6b455c29be Remove coldboot from vold
coldboot is now taken care by ueventd, so removing the duplicate
logic to save boottime.
This CL also fixes a missing lock.


Bug: 33786699
Test: manual
Change-Id: I71270252f3153abc815d142b5da7a9cb85b94dac
2017-01-25 18:15:38 +00:00
Chih-hung Hsieh
0955770f88 Merge \\\\"Fix clang-tidy performance warnings in system/vold.\\\\" am: e24d4eef9b am: aa668f3d13 am: ed1c4cf456
am: 73a3576ef9

Change-Id: I7aa15c236ba857833b392e2eb5646f468761749a
2016-07-28 00:50:26 +00:00
Chih-Hung Hsieh
aa668f3d13 Merge \"Fix clang-tidy performance warnings in system/vold.\"
am: e24d4eef9b

Change-Id: I8e882391fb343a5dd8b5cd32b2e7c087219334dc
2016-07-27 23:17:57 +00:00
Chih-Hung Hsieh
11a2ce8da3 Fix clang-tidy performance warnings in system/vold.
* Use const reference type for for-loop index variables
  to avoid unnecessary copy.

Bug: 30413223
Change-Id: Id4d980ae8afec1374fc3be0b23f1c6a39bff86e0
Test: build with WITH_TIDY=1
2016-07-27 14:11:02 -07:00
Chih-Hung Hsieh
629a360ace Merge "Fix misc-macro-parentheses warnings." am: 0c0f9228cf am: 4ff367a593 am: 5dc0aa6e41
am: 6e8ebe8f76

* commit '6e8ebe8f763bfcea9b7420e9efa62e61e2260f58':
  Fix misc-macro-parentheses warnings.

Change-Id: I518c580eda89fbc9f987e8ac36001b57c29f7f01
2016-05-12 00:55:30 +00:00
Chih-Hung Hsieh
5dc0aa6e41 Merge "Fix misc-macro-parentheses warnings." am: 0c0f9228cf
am: 4ff367a593

* commit '4ff367a5934a906ba2008e530efca220deb96af7':
  Fix misc-macro-parentheses warnings.

Change-Id: I67d525e6f78b1d4e5854d40c30ad0bb96a3490dc
2016-05-11 23:03:58 +00:00
Chih-Hung Hsieh
cc5d580858 Fix misc-macro-parentheses warnings.
Add parentheses around macro arguments used beside binary operators.

Bug: 28705665
Change-Id: I0731cb8b22b3a9bdadac6414473d90e8398a8e89
2016-05-11 15:05:05 -07:00
Daniel Rosenberg
e4c291a1ee Fix resizeAsec to determine correct size
This fixes an eror where resizeAsec would attempt
to read from the superblock struct before initializing
it.

Bug: 28292918
Change-Id: Ic6804e97e7c83bcedfb682a187b8d5e0e1bc51f9
2016-04-20 14:16:19 -07:00
Hidehiko Abe
e6bd7850ff Merge "Split slave-bind mount into two." 2016-03-11 04:34:31 +00:00
Hidehiko Abe
674bed18bd Split slave-bind mount into two.
mount(2) does not work with MS_BIND | MS_SLAVE at a time.
Instead, this CL calls mount twice.

Change-Id: I072fd5377e35fff5ed3fa2798eea084d86fe2977
2016-03-09 16:42:10 +09:00
Yu Ning
942d4e830b Support emulator's virtio-blk based SD card
Currently, vold only supports MMC (for SD cards) and SCSI (for USB
drives) devices. It does not recognize any device whose major number is
not one of those used by MMC and SCSI. Unfortunately, virtio-blk is one
such device. It is used by the new Android emulator (a.k.a. qemu2,
featuring the "ranchu" virtual board) for SD card emulation.

In order to make this virtio-blk based SD card device appear in Android
and appear as an SD card (rather than a USB drive), changes have to be
made to both vold (wherever the device major number is checked) and
ranchu's storage configuration. This CL implements former.

This is a stop-gap solution for emulator in nyc.
A longer term solution in-tune with upstream kernel is in the pipes.

Updated from aosp/master version.

BUG:27431753

Change-Id: I5014edec73be7c5b565d91542464c82cbe58992c
Signed-off-by: Yu Ning <yu.ning@intel.com>
(cherry picked from commit 5b1d1c7dfa13b4dca75213581dc8351b841b76c8)
2016-03-08 12:19:41 -08:00
Daichi Hirono
10d34887b3 Mount appfuse in process namespace.
BUG=26148108

Change-Id: I2297fd227a4c607054e0403e73bd9c857f580a1c
2016-02-02 18:56:19 +09:00
Elliott Hughes
6bf0547ccc resolve merge conflicts of b7d5a47cec to master.
Change-Id: I0c5211a00d92d0ee796bb9c77d2e13675a2a3e8d
2015-12-04 17:55:33 -08:00
Jeff Sharkey
90cca664e1 Merge "Make sure path is not NULL to avoid fatal exception." am: e0e5bfeb3c am: de629f105e
am: 9e807ea6db

* commit '9e807ea6db2c3ea7203844cefb31b1afa06619c3':
  Make sure path is not NULL to avoid fatal exception.
2015-12-05 00:54:27 +00:00
Jeff Sharkey
20826a1574 Merge "vold: fix 64 bit ioctl error" am: 3e6c59dc16 am: bf6acf44a9
am: a619c191cc

* commit 'a619c191cc06c08fb19e1bdd486a41da65f6c0af':
  vold: fix 64 bit ioctl error
2015-12-05 00:54:22 +00:00
Elliott Hughes
7e128fbe21 Track rename from base/ to android-base/.
Change-Id: I3096cfa50afa395d8e9a8043ab69c1e390f86ccb
2015-12-04 15:50:53 -08:00
Jeff Sharkey
e0e5bfeb3c Merge "Make sure path is not NULL to avoid fatal exception." 2015-12-03 17:39:39 +00:00
Mateusz Nowak
a4f48d0f44 vold: fix 64 bit ioctl error
Changing the num_sectors used in ioctl with BLKGETSIZE because
the kernel expects an unsigned long type and then changes 64 bits
with a 64 bits userspace. This overwrites what's located close to
the parameter location if any.

Change-Id: I78fd61a1084de2741f39b926aa436462518709a0
Signed-off-by: Mateusz Nowak <mateusz.nowak@intel.com>
Signed-off-by: Zhiquan Liu <zhiquan.liu@intel.com>
2015-10-21 11:16:19 +08:00
Mateusz Nowak
6440379f1b Make sure path is not NULL to avoid fatal exception.
Change-Id: I75fd5d90cf0f75c28e75582fcae934afa4bf29c4
Signed-off-by: Mateusz Nowak <mateusz.nowak@intel.com>
Signed-off-by: Zhiquan Liu <zhiquan.liu@intel.com>
2015-10-21 11:15:39 +08:00
Jeff Sharkey
228f9509e1 am 47f0531e: am 4fc30636: am 1bd078fa: Protect runtime storage mount points.
* commit '47f0531ec9adf7a29873ccdb11a1ee7b11e76c80':
  Protect runtime storage mount points.
2015-08-06 21:45:56 +00:00
Jeff Sharkey
1bd078fa7b Protect runtime storage mount points.
We have a bunch of magic that mounts the correct view of storage
access based on the runtime permissions of an app, but we forgot to
protect the real underlying data sources; oops.

This series of changes just bumps the directory heirarchy one level
to give us /mnt/runtime which we can mask off as 0700 to prevent
people from jumping to the exposed internals.

Also add CTS tests to verify that we're protecting access to
internal mount points like this.

Bug: 22964288
Change-Id: I83f09f0423f4993e766273c50389dd29b1c50589
2015-08-06 11:45:50 -07:00
Jeff Sharkey
16b3ba4bd7 am 90db4d90: am 78003caf: am 32679a82: Create user directory on emulated storage.
* commit '90db4d909a95cb2a9c9143a4b116822dd6cf4707':
  Create user directory on emulated storage.
2015-07-24 04:05:26 +00:00
Jeff Sharkey
32679a82d9 Create user directory on emulated storage.
When mounting a primary external storage device that is multi-user
aware, ensure that the user-specific directory actually exists before
moving forward.

Bug: 22472026
Change-Id: I33c8eed261a9c0d5acedd5be6133ed9990679d08
2015-07-21 14:22:03 -07:00
Jeff Sharkey
5ceafb42ca Merge commit '3ff337db' into merge
Change-Id: I3c09d1f888da684b50d79a8e539f47c8bcf85646
2015-07-03 13:31:30 -07:00
Jeff Sharkey
c86ab6f538 Trim both internal and adopted private storage.
Refactor fstrim code to be encapsulated in unique task object, and
give it option of benchmarking when finished.  Trimming now includes
both storage from fstab and adopted private volumes.  Cleaner timing
stats are logged for each unique volume.

Add wakelock during ongoing async move tasks.  Push disk sysfs path
to framework so it can parse any SD card registers as desired.

Bug: 21831325
Change-Id: I76577685f5cae4929c251ad314ffdaeb5eb1c8bf
2015-07-01 15:53:51 -07:00
Jeff Sharkey
bf19f7e389 am 1458955f: am c7b5b570: Null-terminate readlink() result, full remount.
* commit '1458955fec0a4973b68795b334530578241532a8':
  Null-terminate readlink() result, full remount.
2015-07-01 00:40:00 +00:00
Jeff Sharkey
c7b5b570bd Null-terminate readlink() result, full remount.
In order to compare results from readlink() calls, we need to null
terminate the read value, otherwise we can end up doing an infinitely
recursive remount in the root namespace.

When remounting inside a namespace, unmount all existing mounts before
mounting the new storage into place.  This also means we need to mount
the user-specific symlinks back into place.

Skip spinning up the FUSE daemon when not visible, otherwise we get
stuck waiting for a daemon that never shows up.

Bug: 22192518, 22204412
Change-Id: Icc7db822354ab7ffc47c39cd0611f65edecc32e5
2015-06-30 15:54:17 -07:00
Jeff Sharkey
c36ffa0010 am 0deb385f: am 66270a21: Let\'s reinvent storage, yet again!
* commit '0deb385f85b4569d98ed9d1df96de1761b378c17':
  Let's reinvent storage, yet again!
2015-06-26 16:37:15 +00:00
Jeff Sharkey
66270a21df Let's reinvent storage, yet again!
Now that we're treating storage as a runtime permission, we need to
grant read/write access without killing the app.  This is really
tricky, since we had been using GIDs for access control, and they're
set in stone once Zygote drops privileges.

The only thing left that can change dynamically is the filesystem
itself, so let's do that.  This means changing the FUSE daemon to
present itself as three different views:

/mnt/runtime_default/foo - view for apps with no access
/mnt/runtime_read/foo - view for apps with read access
/mnt/runtime_write/foo - view for apps with write access

There is still a single location for all the backing files, and
filesystem permissions are derived the same way for each view, but
the file modes are masked off differently for each mountpoint.

During Zygote fork, it wires up the appropriate storage access into
an isolated mount namespace based on the current app permissions.  When
the app is granted permissions dynamically at runtime, the system
asks vold to jump into the existing mount namespace and bind mount
the newly granted access model into place.

Bug: 21858077
Change-Id: Iade538e4bc7af979fe20095f74416e8a0f165a4a
2015-06-25 22:40:08 -07:00
Jeff Sharkey
83434e3714 am b5e680ac: am bc40cc8f: Add method to forget private partition keys.
* commit 'b5e680ac377619286d4b8566a3b736fcf0ee7bb0':
  Add method to forget private partition keys.
2015-06-22 21:57:15 +00:00
Jeff Sharkey
bc40cc8f07 Add method to forget private partition keys.
Report both the disk and the partition GUID for private volumes to
userspace, and offer to forget the encryption key for a given
partition GUID.

Bug: 21782268
Change-Id: Ie77a3a58e47bf3563cdb3e4b0edfab1de4d0e6b4
2015-06-22 14:04:54 -07:00
Jeff Sharkey
7744be3ac7 am b75343ae: am 210228a0: Merge "Start tracking added users with serial numbers." into mnc-dev
* commit 'b75343ae9968326a7d93b3e8981fb3734a11b81d':
  Start tracking added users with serial numbers.
2015-06-10 17:21:01 +00:00
Jeff Sharkey
bd3038df74 Start tracking added users with serial numbers.
vold will eventually use the serial numbers to clean up stale user
directories when mounting private storage devices.

Bug: 20275572
Change-Id: Ia29cb5da23e969f3087bb5caa5dc8f4e88f07613
2015-06-10 09:42:01 -07:00