diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp index 3a474d710..e4a6153a8 100644 --- a/fs_mgr/libsnapshot/snapshot.cpp +++ b/fs_mgr/libsnapshot/snapshot.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -90,6 +91,8 @@ static constexpr char kBootIndicatorPath[] = "/metadata/ota/snapshot-boot"; static constexpr char kRollbackIndicatorPath[] = "/metadata/ota/rollback-indicator"; static constexpr char kSnapuserdFromSystem[] = "/metadata/ota/snapuserd-from-system"; static constexpr auto kUpdateStateCheckInterval = 2s; +static constexpr char kOtaFileContext[] = "u:object_r:ota_metadata_file:s0"; + /* * The readahead size is set to 32kb so that * there is no significant memory pressure (/proc/pressure/memory) during boot. @@ -2134,6 +2137,24 @@ bool SnapshotManager::MarkSnapuserdFromSystem() { PLOG(ERROR) << "Unable to write to vendor update path: " << path; return false; } + + unique_fd fd(open(path.c_str(), O_PATH)); + if (fd < 0) { + PLOG(ERROR) << "Failed to open file: " << path; + return false; + } + + /* + * This function is invoked by first stage init and hence we need to + * explicitly set the correct selinux label for this file as update_engine + * will try to remove this file later on once the snapshot merge is + * complete. + */ + if (fsetxattr(fd.get(), XATTR_NAME_SELINUX, kOtaFileContext, strlen(kOtaFileContext) + 1, 0) < + 0) { + PLOG(ERROR) << "fsetxattr for the path: " << path << " failed"; + } + return true; } @@ -2184,18 +2205,24 @@ bool SnapshotManager::MarkSnapuserdFromSystem() { * */ bool SnapshotManager::IsLegacySnapuserdPostReboot() { - if (is_legacy_snapuserd_.has_value() && is_legacy_snapuserd_.value() == true) { - auto slot = GetCurrentSlot(); - if (slot == Slot::Target) { - // If this marker is present, then daemon can handle userspace - // snapshots; also, it indicates that the vendor partition was - // updated from Android 12. - if (access(GetSnapuserdFromSystemPath().c_str(), F_OK) == 0) { - return false; - } + auto slot = GetCurrentSlot(); + if (slot == Slot::Target) { + /* + If this marker is present, the daemon can handle userspace snapshots. + During post-OTA reboot, this implies that the vendor partition is + Android 13 or higher. If the snapshots were created on an + Android 12 vendor, this means the vendor partition has been updated. + */ + if (access(GetSnapuserdFromSystemPath().c_str(), F_OK) == 0) { + is_snapshot_userspace_ = true; + return false; + } + // If the marker isn't present and if the vendor is still in Android 12 + if (is_legacy_snapuserd_.has_value() && is_legacy_snapuserd_.value() == true) { return true; } } + return false; }