Commit graph

184 commits

Author SHA1 Message Date
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
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
Elliott Hughes
2a8c10965a am 8a0fde27: am e9623fed: Merge "Fixed type mismatch for ioctl(BLKGETSIZE)"
* commit '8a0fde272be430f66b2e5db6236aa732d2ba6efc':
  Fixed type mismatch for ioctl(BLKGETSIZE)
2015-03-30 21:28:10 +00:00
Hiroaki Miyazawa
14eab550e8 Fixed type mismatch for ioctl(BLKGETSIZE)
ioctl(BLKGETSIZE) expects unsigned long
(8 bytes on 64 bit environment).

This is fixing fails in android.os.storage.StorageManagerIntegrationTest
(in FrameworkCoreTests).

To verify, install FrameworksCoreTests.apk and do:

adb shell am instrument -r -w -e class android.os.storage.\
StorageManagerIntegrationTest#testMountSingleEncryptedObb \
com.android.frameworks.coretests/android.test.InstrumentationTestRunner

Change-Id: Ib6d5c7490c02521c93f107c35ad0aac49f6a3f1a
2015-03-30 11:28:11 -07:00
Paul Lawrence
8175a0b65d Adding e4crypt support
Redirect all crypto calls to e4crypt equivalents if file level encryption
detected. Note this change implements only the ones needed for minimal
functionality.

Requires matching change:
  https://googleplex-android-review.git.corp.google.com/#/c/642778/

Change-Id: I622d1a91704de4b3ab655486e6d38cd6718e6016
2015-03-27 13:38:41 -07:00
Paul Lawrence
05335c344d Adding e4crypt support
Redirect all crypto calls to e4crypt equivalents if file level encryption
detected. Note this change implements only the ones needed for minimal
functionality.

Requires matching change:
  https://googleplex-android-review.git.corp.google.com/#/c/642778/

Change-Id: I622d1a91704de4b3ab655486e6d38cd6718e6016
2015-03-19 09:46:47 -07:00
Shawn Willden
47bc0ffadd am 5054f7ee: Merge "Rename keymaster_device_t to keymaster0_device_t."
* commit '5054f7ee4fa6e747eb8d08f60ec91ba6a9363878':
  Rename keymaster_device_t to keymaster0_device_t.
2015-02-26 23:31:10 +00:00
Shawn Willden
8af33350cd Rename keymaster_device_t to keymaster0_device_t.
This is to accomodate the new keymaster1_device_t, which has an entirely
different interface.

Soon I'll provide a libkeymaster which provides a unified (and nicer)
interface for dealing with both v0 and v1 keymaster implementations
using a v1 keymaster API.  For now this change is just so that vold will
build and run.

Change-Id: I5c54282c12d1c4b8b22ed4929b6e6c724a94ede4
2015-02-25 23:08:46 -07:00
Shawn Willden
d1fd8468d0 Rename keymaster_device_t to keymaster0_device_t.
This is to accomodate the new keymaster1_device_t, which has an entirely
different interface.

Soon I'll provide a libkeymaster which provides a unified (and nicer)
interface for dealing with both v0 and v1 keymaster implementations
using a v1 keymaster API.  For now this change is just so that vold will
build and run.

Change-Id: I5c54282c12d1c4b8b22ed4929b6e6c724a94ede4
2015-02-24 09:55:04 -07:00
JP Abgrall
933216c886 crytpfs: fix clobbering of crypto info on keymaster failure
Changing the device lock (even from swipe to none) will cause the
master key to be re-encrypted.
If at that point keymaster fails (e.g. due to an incompatible keymaster update)
cryptfs will write back the now-incomplete crypto metadata.
Upon next reboot, userdata can't be decrypted.

Now we don't bother writing on keymaster failure.

Bug: 19301883
Change-Id: I2b9a1278f8b4d333ac8d567e17e2263005e99409
2015-02-11 13:44:32 -08:00
Elliott Hughes
d32b75e6dc am 33b6de4b: am d55d8dac: Merge "prevent ioctl_init() to write outside buffer"
* commit '33b6de4b94e018b3cb621db5eabcb3a4f18bdd3d':
  prevent ioctl_init() to write outside buffer
2015-02-09 04:15:13 +00:00
Paul Lawrence
a655b9a39f am 38394c7d: am 223fd1ca: Revert "Make encryption configurable"
* commit '38394c7d2d6d5bd8c7467155587a78b912e2b7ab':
  Revert "Make encryption configurable"
2015-02-09 04:14:28 +00:00
Elliott Hughes
33b6de4b94 am d55d8dac: Merge "prevent ioctl_init() to write outside buffer"
* commit 'd55d8dac45dc60cb2cc9e599d3e89532db0cfc39':
  prevent ioctl_init() to write outside buffer
2015-02-07 07:38:37 +00:00
Elliott Hughes
d55d8dac45 Merge "prevent ioctl_init() to write outside buffer" 2015-02-07 07:29:43 +00:00
Paul Lawrence
38394c7d2d am 223fd1ca: Revert "Make encryption configurable"
* commit '223fd1cad8d627dc36e11da8cdd342c1a810d226':
  Revert "Make encryption configurable"
2015-02-07 00:11:29 +00:00
Paul Lawrence
223fd1cad8 Revert "Make encryption configurable"
This reverts commit 6a69cfc411.

The original fix seems to have led to boot failures in QA. Rather than
risk shipping, revert the change. Bug 18764230 reopened.

Requires change
    https://googleplex-android-review.git.corp.google.com/#/c/629950/

Bug: 19278390
Bug: 19199624

Change-Id: Ia858c4db0abb917f9364ec8048f59ca4fb48e233
2015-02-06 17:32:56 +00:00
Marek Pola
5e6b9141c1 prevent ioctl_init() to write outside buffer
The strncpy operation does not write a 0 termination
if the name is larger than the target buffer.

Ensure that zero termination is always written using
safe strlcpy function.

Change-Id: Idb68cdff7cd1a860c1dfac7494fa99f3d382cb91
2015-02-06 08:01:43 +01:00
Elliott Hughes
efb4c6d79a am 71f8d86f: am f805a8b3: Merge "Change lseek to lseek64"
* commit '71f8d86fdfc2c11f2d4176eabb98812bf41792e7':
  Change lseek to lseek64
2015-02-05 20:35:09 +00:00
Elliott Hughes
71f8d86fdf am f805a8b3: Merge "Change lseek to lseek64"
* commit 'f805a8b3a917b163c789f1ad4b272560f98eb6f1':
  Change lseek to lseek64
2015-02-05 20:26:52 +00:00
Elliott Hughes
394cd68fcd am e22b21af: am ebc83b3e: Merge "Fix memory leak in upgrade_crypt_ftr"
* commit 'e22b21af3a4d7729c23f559add26bc4f78cbaab1':
  Fix memory leak in upgrade_crypt_ftr
2015-02-05 20:16:03 +00:00
Elliott Hughes
e22b21af3a am ebc83b3e: Merge "Fix memory leak in upgrade_crypt_ftr"
* commit 'ebc83b3e8ef6d0dbab84bec88e0231c7911e5378':
  Fix memory leak in upgrade_crypt_ftr
2015-02-05 18:51:07 +00:00
Elliott Hughes
f805a8b3a9 Merge "Change lseek to lseek64" 2015-02-05 17:36:02 +00:00
Elliott Hughes
ebc83b3e8e Merge "Fix memory leak in upgrade_crypt_ftr" 2015-02-05 17:08:59 +00:00
Björn Landström
96dbee7bd6 Change lseek to lseek64
Using lseek on 64-bit offset parameter caused failure
to write persistent data in crypto footer.

Changed calls to use lseek64 instead.

Change-Id: I4e4c397a6d36201b8b08be3017e17c9fac3b34e4
2015-02-05 15:18:44 +01:00
Henrik Baard
91064633ff Fix memory leak in upgrade_crypt_ftr
The structure crypt_persist_data was allocated,
but never freed.

Added free of allocated memory in normal and
error case.

Change-Id: I9aaa067e6f6501e8ce007f8659004b5dbcf2b246
2015-02-05 15:09:17 +01:00
Paul Lawrence
db3730c454 Remove kdfs that were only used internally in LMP
Bug: 17439091
Change-Id: I55f92984c8234362597be3976a10626a0ed8763f
2015-02-03 13:08:10 -08:00
Paul Lawrence
c19cb9c832 Make encryption configurable
Add maybeenabledefaultencryption function, that encrypts based
on the encryption flag and appropriate environment variable

Bug: 18764230
Change-Id: Id9a1967d09a7ae63a51240c0a5f3c41505af0e9a
2015-01-28 11:42:55 -08:00
Paul Lawrence
4a36ca0038 am 6a69cfc4: Make encryption configurable
* commit '6a69cfc411c086f15d59b7dc105763af16620414':
  Make encryption configurable
2015-01-26 15:53:01 +00:00
Kenny Root
ba5834dcea am 26970299: Merge "Remove superfluous OpenSSL include paths."
* commit '269702997153cdf92c65cfee277c76afed44e9e5':
  Remove superfluous OpenSSL include paths.
2015-01-23 01:17:16 +00:00
Adam Langley
41405bb3e5 Remove superfluous OpenSSL include paths.
The libcrypto and libssl modules (and their respective static and host
versions) use LOCAL_EXPORT_C_INCLUDE_DIRS thus just including the module
is sufficient.

Additionally, cryptfs.h was including an OpenSSL header just to get the
length of a SHA-256 hash. Rather than force all users of this header to
also depend on libcrypto, it's easier just to define that value in the
header file.

Change-Id: I3e3e0db906a212e1093944b298e4a8ff2e2fb07d
2015-01-22 16:45:28 -08:00
Paul Lawrence
6a69cfc411 Make encryption configurable
Add maybeenabledefaultencryption function, that encrypts based
on the encryption flag and appropriate environment variable

Bug: 18764230
Change-Id: Id9a1967d09a7ae63a51240c0a5f3c41505af0e9a
2015-01-21 10:00:17 -08:00
Brian Carlstrom
da91b1915c Remove unused local variable to fix the build
Change-Id: Ic0a77a754b649d360d07eaa9e6a93274e7eaf0a8
2014-12-18 17:01:40 -08:00
Dan Albert
210caabdb5 resolved conflicts for merge of 88aba541 to lmp-mr1-dev-plus-aosp
Change-Id: Ie5ef819dd8168cb6a73f84a881a92c116705fffc
2014-12-18 14:08:43 -08:00
Dan Albert
c07fa3fa5a Fix alignment of buffer used for dm_ioctl.
Since the dm_ioctl struct was being allocated on the stack as a large
character array, it was getting character alignment rather than the
proper alignment for the struct. GCC had been getting away with this
so far, but it's undefined behavior that clang managed to expose.

Bug: 18736778
Change-Id: Ied275dfad7fcc41d712b2d02c8a185f499221f57
2014-12-18 10:24:23 -08:00
Tim Murray
6c78e7d772 resolved conflicts for merge of 4be36106 to lmp-mr1-dev-plus-aosp
Change-Id: If504710a618d8c3adf85297d5fd2909558ed57a3
2014-12-17 16:41:07 -08:00
Tim Murray
8439dc9fd5 Make vold compile with -Werror -Wall.
-Wno-missing-field-initializers is used as well, but that is an
overzealous warning from initializing structs with {0} and not a
real warning.

bug 18736778 and 16868177

Change-Id: Iffde89cd7200d9a11193e1614f1819f9fcace30a
2014-12-18 00:21:21 +00:00
Paul Lawrence
6322302a5a am acfdc30e: Merge "Fix error in clocks leading to devices staying unlocked" into lmp-mr1-dev
* commit 'acfdc30e3793512de4b9a5e15da69533735dd8be':
  Fix error in clocks leading to devices staying unlocked
2014-12-02 18:54:41 +00:00
Paul Lawrence
82b451dacb am d44a8f59: Merge "Fix encrypt-and-wipe" into lmp-mr1-dev
* commit 'd44a8f59a7518b87a3fe4174c78dfb9727e63f89':
  Fix encrypt-and-wipe
2014-12-02 18:45:42 +00:00
Paul Lawrence
acfdc30e37 Merge "Fix error in clocks leading to devices staying unlocked" into lmp-mr1-dev 2014-12-02 18:34:14 +00:00
Paul Lawrence
ef2b5bea6b Fix error in clocks leading to devices staying unlocked
Use BOOTTIME consistently!

Bug: 18246810
Change-Id: I630bf39f72ab69f971d2f772e8d4545ffe467b82
2014-12-02 08:03:15 -08:00
Paul Lawrence
b1eb7a06ee Fix encrypt-and-wipe
encrypt-and-wipe was broken when checks were added that encryption succeeded
which assumed a 'normal' full encrypt traversing the device.

encrypt-and-wipe doesn't traverse, it just lays down a file system over
the encrypted device, so in this mode do not check the amount encrypted -
it will always be 0.

Bug: 18511900
Change-Id: Icb1d7e0cdb67abd2eac0ab3cbfc1a88912768f9d
2014-12-02 16:02:05 +00:00
Iliyan Malchev
c9c5171792 am bb7d9afe: fall back to dm-crypt if device already encrypted
* commit 'bb7d9afea9479eabbc98133d3d968225a1e1019e':
  fall back to dm-crypt if device already encrypted
2014-11-21 08:56:42 +00:00
Iliyan Malchev
b7d35115dc resolved conflicts for merge of 87701e27 to lmp-mr1-dev-plus-aosp
Change-Id: Ie873baff626fe786515497f2e81aa9db2329168d
2014-11-21 00:52:40 -08:00
Iliyan Malchev
bb7d9afea9 fall back to dm-crypt if device already encrypted
Devices already encrypted with aes-cbc-essiv:sha256 will continue to be
decrypted in software, until a factory data reset.  New devices that
implement CONFIG_HW_DISK_ENCRYPTION will switch to aes-xts.

b/17475056 Enable hardware crypto for userdata encryption

Change-Id: I62d1583bdaf7ff06b87e386e758fa3b18c719bca
Signed-off-by: Iliyan Malchev <malchev@google.com>
2014-11-21 08:19:33 +00:00
Ajay Dudani
87701e2755 Adding support of dm-req-crypt
Currently Android provides disk encryption support using dm-crypt
which is based on bios. dm-crypt uses 512 bytes packet size for
crypto operations. While 512 bytes size packet is ok for SW based
disk encryption, it is inefficient for HW based crypto engines.
dm-req-crypt is similar to dm-crypt except it uses block requests
rathe bios for crypto operations. block requests when unpacked
carries data upto 512KB. Hence, HW based crypto engine can be used
more efficiently.

Also move create disk encryption key before framework start as
HW based disk encryption creates key in secure side. Key creation
can take sometime to create the key securely. If framework is
started before creating the key, it is possible that framework
requests service from secure side. Secure side can serve mostly one
request at a time. Secure side may reject framework request if key
creation request is still going on. This may cause problem in the
system

b/17475056 Enable hardware crypto for userdata encryption

Change-Id: I5480ab72a37c02532218a18faaba598a824589fd
Signed-off-by: Iliyan Malchev <malchev@google.com>
2014-11-21 08:17:32 +00:00
Shawn Willden
b4be7416f8 Modify vold to check for hardware keymaster.
automerge: 7c49ab0

* commit '7c49ab0a0b3c1ee9b24a4b0b1a2c0a8c86acea41':
  Modify vold to check for hardware keymaster.
2014-11-05 18:03:47 +00:00
Shawn Willden
7c49ab0a0b Modify vold to check for hardware keymaster.
vold should only use hardware keymaster implementations to protect the
disk encryption key, because there's little value in using the software
implementation.  More importantly, if we allow vold to use softkeymaster
in the absence of a HW keymaster and (somehow) a HW keymaster is added
to a device, the HW version will be loaded, and will be unable to use
the softkeymaster key found in the crypto footer, forcing a factory
reset.

This CL will not break devices without HW keymaster, because
softkeymaster currently reports its keys as non-standalone (which isn't
correct).  After this CL is in, I will fix softkeymaster.

Bug: 17362157
Change-Id: I98b169e7a59ff7d44b72069b87743463ec823ea2
2014-11-04 17:58:12 +00:00
Rubin Xu
84f2515008 Merge "Make persistent field in cryptofs support longer values." into lmp-mr1-dev
automerge: 13c3a90

* commit '13c3a90b586d272b391bd0e2795717db75a4d853':
  Make persistent field in cryptofs support longer values.
2014-10-30 18:59:11 +00:00
Rubin Xu
85c01f95c7 Make persistent field in cryptofs support longer values.
Store long field values in multiple underlying fixed-length entries
and concatenate them together when reading back.

Bug: 17556485
Change-Id: I2f8033d18c208993fa1b010712be0dad5d8b646b
2014-10-24 10:56:02 +01:00