Commit graph

19 commits

Author SHA1 Message Date
Yabin Cui
a58a6dbe3d uncrypt: split libbootloader_message_writer for reuse.
init and vold also need to write bootloader message, so
split this function from uncrypt into a separate library.

Bug: 27176738
Change-Id: If9b0887b4f6ffab6162d9cb47a6ceb7eedd60b4d
2016-04-08 11:46:56 -07:00
Yabin Cui
912e87e91d Merge "uncrypt: fix call to close()." into nyc-dev 2016-03-29 22:48:08 +00:00
Yabin Cui
ffa3a1c222 uncrypt: fix call to close().
Bug: 27897229
Change-Id: Iab5e829af1676f7fcd8a4b00a194aa679ed4e372
2016-03-29 15:35:58 -07:00
Yabin Cui
61799baba3 uncrypt: remove --read-bcb option.
Bug: 27897241
Change-Id: I4f52ada58e8f204dba8c974ea0ae03876411ecf0
2016-03-29 14:33:35 -07:00
Tao Bao
3a2bb594df uncrypt: Communicate via /dev/socket/uncrypt.
We used to rely on files (e.g. /cache/recovery/command and
/cache/recovery/uncrypt_status) to communicate between uncrypt and its
caller (i.e. system_server). Since A/B devices may not have /cache
partitions anymore, we switch to socket communication instead.

We will keep the use of /cache/recovery/uncrypt_file to indicate the OTA
package to be uncrypt'd though. Because there is existing logic in
ShutdownThread.java that depends on the existence of the file to
detect pending uncrypt works. This part won't affect A/B devices without
/cache partitions, because such devices won't need uncrypt service (i.e
the real de-encrypt work) anyway.

Bug: 27176738
Change-Id: I481406e09e3ffc7b80f2c9e39003b9fca028742e
2016-03-02 23:23:32 -08:00
Tao Bao
5b3b373a49 uncrypt: Retire pre-recovery service.
The framework CL in [1] removes the use of "pre-recovery" service which
is basically to trigger a reboot into the recovery.

[1] commit e8a403d57c8ea540f8287cdaee8b90f0cf9626a3

Bug: 26830925
Change-Id: I131f31a228df59e4f9c3024b238bbdee0be2b157
2016-02-22 17:33:41 -08:00
Yabin Cui
2d46da57e1 uncrypt: add options to setup bcb and clear bcb.
Bug: 26696173

Change-Id: I3a612f045aaa9e93e61ae45b05300d02b19bb3ad
2016-02-03 10:43:03 -08:00
Yabin Cui
25dd0386fe uncrypt: generate map file by renaming tmp file.
Writing map file directly can break consistency in map file if
it fails in the middle. Instead, we write a temporary file and
rename the temporary file to map file.

Bug: 26883096
Change-Id: I5e99e942e1b75e758af5f7a48f8a08a0b0041d6a
2016-02-01 14:43:14 -08:00
Daniel Micay
c5631fc096 uncrypt: avoid use-after-free
The `std::string package` variable goes out of scope but the input_path
variable is then used to access the memory as it's set to `c_str()`.

This was detected via OpenBSD malloc's junk filling feature.

Change-Id: Ic4b939347881b6ebebf71884e7e2272ce99510e2
2016-01-12 14:08:34 -08:00
Tao Bao
b8df5fb90e uncrypt: Suppress the compiler warnings on LP64.
We have the following warnings when compiling uncrypt on LP64 (e.g.
aosp_angler-userdebug).

bootable/recovery/uncrypt/uncrypt.cpp:77:53: warning: format specifies type 'long long' but the argument has type 'off64_t' (aka 'long') [-Wformat]
        ALOGE("error seeking to offset %lld: %s\n", offset, strerror(errno));
                                       ~~~~         ^~~~~~
                                       %ld
bootable/recovery/uncrypt/uncrypt.cpp:84:54: warning: format specifies type 'long long' but the argument has type 'unsigned long' [-Wformat]
            ALOGE("error writing offset %lld: %s\n", (offset + written), strerror(errno));
                                        ~~~~         ^~~~~~~~~~~~~~~~~~
                                        %lu
bootable/recovery/uncrypt/uncrypt.cpp:246:16: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'off_t' (aka 'long') [-Wsign-compare]
    while (pos < sb.st_size) {
           ~~~ ^ ~~~~~~~~~~

According to POSIX spec [1], we have:
  off_t and blksize_t shall be signed integer types;
  size_t shall be an unsigned integer type;
  blksize_t and size_t are no greater than the width of type long.

And on Android, we always have a 64-bit st_size from stat(2)
(//bionic/libc/include/sys/stat.h).

Fix the type and add necessary casts to suppress the warnings.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html

Change-Id: I5d64d5b7919c541441176c364752de047f9ecb20
2015-12-09 10:45:39 -08:00
Elliott Hughes
4b166f0e69 Track rename from base/ to android-base/.
Change-Id: I354a8c424d340a9abe21fd716a4ee0d3b177d86f
2015-12-04 15:30:20 -08:00
Elliott Hughes
63b089e3aa We can use fclose directly in std::unique_ptr.
It turns out the standard explicitly states that if the pointer is
null, the deleter function won't be called. So it doesn't matter that
fclose(3) doesn't accept null.

Change-Id: I10e6e0d62209ec03ac60e673edd46f32ba279a04
2015-11-12 21:07:55 -08:00
Jaegeuk Kim
cc4e3c6002 uncrypt: remove O_SYNC to avoid time-out failures
This patch removes costly O_SYNC flag for encrypted block device.
After writing whole decrypted blocks, fsync should guarantee their consistency
from further power failures.
This patch reduces the elapsed time significantly consumed by upgrading packages
on an encrypted partition, so that it could avoid another time-out failures too.

Change-Id: I1fb9022c83ecc00bad09d107fc87a6a09babb0ec
Signed-off-by: Jaegeuk Kim <jaegeuk@motorola.com>
2015-11-04 11:43:58 -08:00
Tao Bao
c754792a07 Use unique_ptr and unique_fd to manager FDs.
Clean up leaky file descriptors in uncrypt/uncrypt.cpp. Add unique_fd
for open() and unique_file for fopen() to close FDs on destruction.

Bug: 21496020
Change-Id: I0174db0de9d5f59cd43b44757b8ef0f5912c91a2
2015-08-09 22:35:49 -07:00
Tao Bao
7cf50c60b5 uncrypt: Support file level encryption.
Bug: 22534003
Change-Id: I2bc22418c416491da573875dce78daed24f2c046
(cherry picked from commit 6e9dda70cb)
2015-07-24 11:13:25 -07:00
Tao Bao
ac6aa7ede0 uncrypt: Write status when it reboots to factory reset
When it reboots into recovery for a factory reset, it still needs to
write the uncrypt status (-1) to the pipe.

Bug: 21511893
(cherry picked from commit 2c2cae8a4a)
Change-Id: Ia5a75c5edf3afbd916153da1b4de4db2f00d0209
2015-06-09 15:02:22 -07:00
Tao Bao
383b00d0e4 Separate uncrypt into two modes
uncrypt needs to be triggered to prepare the OTA package before
rebooting into the recovery. Separate uncrypt into two modes. In
mode 1, it uncrypts the OTA package, but will not reboot the
device. In mode 2, it wipes the /misc partition and reboots.

Needs matching changes in frameworks/base, system/core and
external/sepolicy to work properly.

Bug: 20012567
Bug: 20949086
(cherry picked from commit 158e11d673)
Change-Id: I349f6d368a0d6f6ee4332831c4cd4075a47426ff
2015-06-09 15:01:10 -07:00
Tao Bao
752386319c Clean up the sleep()'s after poking init services
Change-Id: I77564fe5c59e604f1377b278681b7d1bff53a77a
2015-05-27 14:48:56 -07:00
Tao Bao
381f455cac uncrypt: Switch to C++
Also apply some trivial changes like int -> bool and clean-ups.

Change-Id: Ic55fc8b82d7e91b321f69d10175be23d5c04eb92
2015-05-06 11:43:11 -07:00
Renamed from uncrypt/uncrypt.c (Browse further)