From a946b9e2419e0d7f29a52a047c70857eb9251cbd Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Tue, 21 Mar 2017 16:24:57 -0700 Subject: Fix the permission of stashed blocks created by updater Our updater created the stashes with root permission. This causes an access denial when the RecoverySystem service tries to clean up these blocks after a failing update. As a result, the subsequent OTA updates may fail due to insufficient cache space. Bug: 36457133 Test: stashed blocks cleaned successfully after reboot Change-Id: If0ca99638cdfa1033646f29d9cc92b5ff1bacac1 --- updater/blockimg.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp index 0fa83d9d5..8dbd8c7d1 100644 --- a/updater/blockimg.cpp +++ b/updater/blockimg.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include "edify/expr.h" @@ -772,6 +773,11 @@ static int WriteStash(const std::string& base, const std::string& id, int blocks return -1; } + if (fchown(fd, AID_SYSTEM, AID_SYSTEM) != 0) { // system user + PLOG(ERROR) << "failed to chown \"" << fn << "\""; + return -1; + } + if (write_all(fd, buffer, blocks * BLOCKSIZE) == -1) { return -1; } @@ -841,6 +847,12 @@ static int CreateStash(State* state, size_t maxblocks, const std::string& blockd return -1; } + if (chown(dirname.c_str(), AID_SYSTEM, AID_SYSTEM) != 0) { // system user + ErrorAbort(state, kStashCreationFailure, "chown \"%s\" failed: %s\n", dirname.c_str(), + strerror(errno)); + return -1; + } + if (CacheSizeCheck(max_stash_size) != 0) { ErrorAbort(state, kStashCreationFailure, "not enough space for stash (%zu needed)\n", max_stash_size); -- cgit v1.2.3