Commit graph

36 commits

Author SHA1 Message Date
Pierre-Hugues Husson
5687befd86 Merge "Workaround perdev_minors path change in Linux"
am: d3870c5167

Change-Id: Ia7ec03a566f8c122dff05bcc3d996c05cf2b7771
2017-11-28 18:59:56 +00:00
Pierre-Hugues Husson
f347cd0249 Workaround perdev_minors path change in Linux
This upstream Linux change has been discussed at https://patchwork.kernel.org/patch/8281851/
And included in AOSP in https://android-review.googlesource.com/c/kernel/common/+/202752
Some devices have been released without it, so we need this change to
have a working SDcard on those devices.

Change-Id: I323d85bd8381f82b75db09493ddc22f432cec548
2017-11-28 17:53:42 +01:00
Jeff Sharkey
46bb69f49a Progress towards FBE and adoptable storage.
Offer to adopt storage devices on FBE devices, but keep it guarded
behind a system property for now, since we still need to work out key
storage details.

When migrating shared storage, leave user-specific /data/media
directories in place, since they already have the needed crypto
policies defined.

Enable journaling, quotas, and encrypt options when formatting
newly adopted devices.  installd already gracefully handles older
partitions without quota enabled.

Test: cts-tradefed run commandAndExit cts-dev --abi armeabi-v7a -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.AdoptableHostTest
Bug: 62290006, 36757864, 29117062, 37395736
Bug: 29923055, 25861755, 30230655, 37436961
Change-Id: Ibbeb6ec9db2394a279bbac221a2b20711d65494e
2017-06-26 09:53:10 -06: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
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
Jeff Sharkey
697cd037ad DO NOT MERGE. Block adoptable storage when using FBE. am: 84be704af4
am: 1fbe38f424

Change-Id: I7331a05a5d40d8cf1d946971e86097e716580094
2016-08-31 23:56:45 +00:00
Jeff Sharkey
84be704af4 DO NOT MERGE. Block adoptable storage when using FBE.
For adoptable storage and FBE to coexist we need a new dm-biocrypt
kernel feature which isn't ready yet.  So for now, prevent devices
from being adopted on FBE devices.

Bug: 30770036
Change-Id: I47639209161ee403ce13ea9a60da235e97c3fc30
(cherry picked from commit 1571751109)
2016-08-31 21:42:32 +00:00
Jeff Sharkey
1571751109 Block adoptable storage when using FBE.
For adoptable storage and FBE to coexist we need a new dm-biocrypt
kernel feature which isn't ready yet.  So for now, prevent devices
from being adopted on FBE devices.

Bug: 30770036
Change-Id: I47639209161ee403ce13ea9a60da235e97c3fc30
2016-08-23 13:49:00 -06: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
Jeff Sharkey
f84fe90714 Merge "Print size as unsigned when sending to framework." into nyc-dev 2016-03-11 00:07:25 +00:00
Jeff Sharkey
d087bbc66f Print size as unsigned when sending to framework.
Otherwise we might output negative numbers that confuse the rest
of the recovery stack.

Bug: 26007445
Change-Id: Ic99b49360732e5389c6330be065e1222e25b60ca
2016-03-10 12:11:20 -07: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
Elliott Hughes
a9d5080109 Merge "Track rename from base/ to android-base/."
am: 20a8fa98f6

* commit '20a8fa98f6b858999b623272a182843259e1044c':
  Track rename from base/ to android-base/.
2015-12-04 17:39:41 -08:00
Elliott Hughes
7e128fbe21 Track rename from base/ to android-base/.
Change-Id: I3096cfa50afa395d8e9a8043ab69c1e390f86ccb
2015-12-04 15:50:53 -08:00
Jeff Sharkey
dadcceea7a Clean up any/all stale partition tables.
When formatting media as a public volume, we write an MBR, but we
might leave a stale GPT floating around.  Some devices are configured
to aggressively prefer GPT when detected, even if the checksums
between primary/secondary don't match.

To work around this, nuke both MBR and GPT tables from the media
before we lay down our new MBR.

Bug: 24112219
Change-Id: Ibf1be466a6877cbab925a24db5e5dbab0613bea7
2015-09-23 14:14:12 -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
63123c067a Last ditch check for partition on raw disk.
Some storage devices can be formatted as bare partitions, without an
MBR or GPT header.  If we found no partitions, try poking at the raw
disk, and treat it as a public volume if we found a valid filesystem.

Bug: 20503551
Change-Id: I80304e1ad865435321c341b667c0daf2daf4d56c
2015-06-26 11:16:17 -07: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
d0640f6358 Add f2fs support for private volumes.
When formatting volumes, pass along fsType string which can be "auto"
to let the volume select the best choice.  For now, private volumes
assume that MMC devices (like SD cards) are best off using f2fs when
both kernel support and tools are present, otherwise fall back to
ext4.  Use blkid when mounting to pick the right set of tools.

Move filesystem utility methods into namespaces and place in separate
directory to be more organized.

Bug: 20275581
Change-Id: Id5f82d8672dda2e9f68c35b075f28232b0b55ed4
2015-06-08 20:21:25 -07:00
Jeff Sharkey
ba6747f119 Scan failure still means we finished scan.
Bug: 19993667
Change-Id: If6a79391e34b652b2ba4e6df40a8e712f7a2e172
2015-04-28 21:17:43 -07:00
Jeff Sharkey
c8e04c5a82 Wider volume mutation lock, move force adoptable.
We eventually should move back to per-disk locks, but use a giant
lock to keep development rolling forward.  Also move force adoptable
flag to framework since, since encrypted devices don't have persisted
properties loaded early during boot.

Bug: 19993667
Change-Id: Ifa3016ef41b038f8f71fc30bc81596cfd21dcd2a
2015-04-21 12:24:57 -07:00
Jeff Sharkey
f3ee200303 Handle *ALL* the SCSI disks!
Bug: 19993667
Change-Id: I47099c262686127f82dd376570d49cf0ad119842
2015-04-19 15:55:42 -07:00
Jeff Sharkey
613b26f8e3 Notify when disk scan finished.
Bug: 19993667
Change-Id: I20dc183a35c11b5b4ba6139e690929b9c279b830
2015-04-19 14:57:55 -07:00
Jeff Sharkey
f1b996df6f Volumes know parent disks; unsupported disks.
This is cleaner and more direct than the reverse of having the disk
publish child volume membership.  Rename state constants to match
public API.  Add state representing bad removal.  Make it clear that
volume flags are related to mounting.

Send new unsupported disk event when we finish scanning an entire
disk and have no meaningful volumes.

Bug: 19993667
Change-Id: I08a91452ff561171a484d1da5745293ec893aec0
2015-04-17 17:43:56 -07:00
Jeff Sharkey
7d9d011865 Lock while partitioning.
Otherwise we get really excited and trip over ourselves while
partitions are still being created.

Bug: 19993667
Change-Id: I034e56b3063a71d73f9311a945c05ea2ae255f7d
2015-04-14 23:14:23 -07:00
Jeff Sharkey
ffeb007978 Don't be picky about zap status.
Bug: 19993667
Change-Id: Id125d9252bf7130516c0ec619d5f067fea24d560
2015-04-14 22:22:34 -07:00
Jeff Sharkey
502164deaa Fix destroy ordering bug; add debug flag.
Bug: 19993667
Change-Id: Ib15e79a94a185843dace35fea7daaea866120f87
2015-04-14 16:45:18 -07:00
Jeff Sharkey
3161fb3702 Emulated volumes above private volumes.
When a private volume is mounted, create an emulated volume above it
hosted at the /media path on that device.  That emulated volume is
automatically torn down when unmounting the private volume.

Add "removed" state for volume, which signals to framework that
media has left the building, send when the volume is destroyed.

Bug: 19993667
Change-Id: I1f82b51de578ac5cfcc5d7b9a6fb44f6f25c775c
2015-04-12 16:03:40 -07:00
Jeff Sharkey
ce6a913aea Exclusive exec() path, format after partition.
Sadly setexeccon() is process global, so we need to carefully ensure
that all exec() are mutually exclusive to avoid transitioning into
unwanted domains.  Also, because we have several threads floating
around, we need to guard all our FDs with O_CLOEXEC.

Format all newly created volumes immediately after partitioning,
but silence all events emitted from those volumes to prevent the
framework from getting all excited.  Unify all notify events under a
single codepath to make them easy to silence.

Sent SIGINT before escalating to SIGTERM when unmounting.

Bug: 19993667
Change-Id: Idc6c806afc7919a004a93e2240b42884f6b52d6b
2015-04-11 08:48:13 -07:00
Jeff Sharkey
9c48498f45 Support for private (adopted) volumes.
This adds support for private volumes which is just a filesystem
wrapped in a dm-crypt layer.  For now we're using the exact same
configuration as internal encryption (aes-cbc-essiv:sha256), but we
don't store any key material on the removable media.  Instead, we
store the key on internal storage, and use the GPT partition GUID
to identify which key should be used.

This means that private external storage is effectively as secure as
the internal storage of the device.  That is, if the internal storage
is encrypted, then our external storage key is also encrypted.

When partitioning disks, we now support a "private" mode which has
a PrivateVolume partition, and a currently unused 16MB metadata
partition reserved for future use.  It also supports a "mixed" mode
which creates both a PublicVolume and PrivateVolume on the same
disk.  Mixed mode is currently experimental.

For now, just add ext4 support to PrivateVolume; we'll look at f2fs
in a future change.  Add VolumeBase lifecycle for setting up crypto
mappings, and extract blkid logic into shared method.  Sprinkle some
more "static" around the cryptfs code to improve invariants.

Bug: 19993667
Change-Id: Ibd1df6250735b706959a1eb9d9f7219ea85912a0
2015-04-01 10:45:05 -07:00
Jeff Sharkey
38cfc02860 Fix 64 bit builds.
Change-Id: I4e30ecff3c29d0f8351c6f43de1c979c8c792fab
2015-03-30 21:23:16 -07:00
Jeff Sharkey
36801cccf2 Progress towards dynamic storage support.
Wire up new Disk and VolumeBase objects and events to start replacing
older DirectVolume code.  Use filesystem UUID as visible PublicVolume
name to be more deterministic.

When starting, create DiskSource instances based on fstab, and watch
for kernel devices to appear.  Turn matching devices into Disk
objects, scan for partitions, and create any relevant VolumeBase
objects.  Broadcast all of these events towards userspace so the
framework can decide what to mount.

Keep track of the primary VolumeBase, and update the new per-user
/storage/self/primary symlink for all started users.

Provide a reset command that framework uses to start from a known
state when runtime is restarted.  When vold is unexpectedly killed,
try recovering by unmounting everything under /mnt and /storage
before moving forward.

Remove UMS sharing support for now, since no current devices support
it; MTP is the recommended solution going forward because it offers
better multi-user support.

Switch killProcessesWithOpenFiles() to directly take signal.  Fix
one SOCK_CLOEXEC bug, but SELinux says there are more lurking.

Bug: 19993667
Change-Id: I2dad1303aa4667ec14c52f774e2a28b3c1c1ff6d
2015-03-30 19:46:31 -07:00
Dan Albert
ae9e890337 Update for libbase.
Change-Id: I23b1281a63031a7481ea7b33c9ddbdbe7d3d6174
2015-03-16 10:35:17 -07:00
Jeff Sharkey
deb2405737 Checkpoint of better dynamic device support.
This is the first in a series of changes that are designed to
introduce better support for dynamic block devices.

It starts by defining a new Volume object which represents a storage
endpoint that knows how to mount, unmount, and format itself.  This
could be a filesystem directly on a partition, or it could be an
emulated FUSE filesystem, an ASEC, or an OBB.

These new volumes can be "stacked" so that unmounting a volume will
also unmount any volumes stacked above it.  Volumes that provide
shared storage can also be asked to present themselves (through bind
mounts) into user-specific mount areas.

This change also adds a Disk class which is created based on block
kernel netlink events.  Instead of waiting for partition events from
the kernel, it uses gptfdisk to read partition details and creates
the relevant Volume objects.

Change-Id: I0e8bc1f8f9dcb24405f5e795c0658998e22ae2f7
2015-03-13 10:12:57 -07:00