Remove modules no longer installed in init_boot
Test: run vts -m vts_generic_boot_image_test
Bug: 219841787
Change-Id: I5fc45c8de6c519f4abb908dcde15f6cb5e93d928
diff --git a/gki/generic_boot_image_test.cpp b/gki/generic_boot_image_test.cpp
index e3ae9af..5f0451c 100644
--- a/gki/generic_boot_image_test.cpp
+++ b/gki/generic_boot_image_test.cpp
@@ -17,6 +17,7 @@
#include <filesystem>
#include <android-base/properties.h>
+#include <android-base/strings.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <kver/kernel_release.h>
@@ -71,6 +72,7 @@
GTEST_SKIP() << "Exempt generic ramdisk test on kernel "
<< runtime_info->kernelVersion()
<< ". Only required on 5.10+.";
+ return;
}
using std::filesystem::recursive_directory_iterator;
@@ -97,18 +99,20 @@
GTEST_SKIP() << "Exempt generic ramdisk test on upgrading device that "
<< "launched before Android 13 and is now using an Android "
<< "13+ kernel.";
+ return;
}
} else {
boot_path = "/dev/block/by-name/boot" + slot_suffix;
}
- if (0 != access(boot_path.c_str(), F_OK)) {
+ if (0 != access(boot_path.c_str(), R_OK)) {
int saved_errno = errno;
FAIL() << "Can't access " << boot_path << ": " << strerror(saved_errno);
+ return;
}
auto extracted_ramdisk = android::ExtractRamdiskToDirectory(boot_path);
ASSERT_TRUE(extracted_ramdisk.ok())
- << "Failed to find the block device: " << boot_path;
+ << "Failed to extract ramdisk: " << extracted_ramdisk.error();
std::set<std::string> actual_files;
std::filesystem::path extracted_ramdisk_path((*extracted_ramdisk)->path);
@@ -122,10 +126,8 @@
std::set<std::string> generic_ramdisk_allowlist{
"init",
- "system/bin/e2fsck",
- "system/bin/fsck.f2fs",
- "system/bin/tune2fs",
"system/bin/snapuserd",
+ "system/etc/init/snapuserd.rc",
"system/etc/ramdisk/build.prop",
};
if (GetBoolProperty("ro.debuggable", false)) {
diff --git a/gki/lz4_legacy.cpp b/gki/lz4_legacy.cpp
index 55d0a9b..423687c 100644
--- a/gki/lz4_legacy.cpp
+++ b/gki/lz4_legacy.cpp
@@ -19,6 +19,7 @@
#include <fcntl.h>
#include <sys/stat.h>
+#include <iostream>
#include <vector>
#include <android-base/file.h>
@@ -41,13 +42,24 @@
constexpr uint32_t lz4_legacy_magic = 0x184C2102;
constexpr auto lz4_legacy_block_size = 8_MiB;
+ struct stat st_buf {};
+ if (stat(input, &st_buf) != 0) {
+ return ErrnoError() << "stat(" << input << ")";
+ }
+
unique_fd ifd(TEMP_FAILURE_RETRY(open(input, O_RDONLY | O_CLOEXEC)));
+ if (!ifd.ok()) {
+ return ErrnoError() << "open(" << input << ", O_RDONLY)";
+ }
unique_fd ofd(TEMP_FAILURE_RETRY(
open(output, O_WRONLY | O_CREAT | O_CLOEXEC | O_TRUNC, 0640)));
+ if (!ofd.ok()) {
+ return ErrnoError() << "open(" << output << ", O_WRONLY | O_CREAT)";
+ }
- uint32_t magic;
+ uint32_t magic{};
if (!ReadFully(ifd, &magic, sizeof(magic))) {
- return ErrnoError() << "read magic";
+ return ErrnoError() << "read lz4 magic " << input;
}
// Android is little-endian. No need to convert magic.
if (magic != lz4_legacy_magic) {
@@ -59,7 +71,7 @@
std::vector<char> obuf(lz4_legacy_block_size);
while (true) {
- uint32_t block_size;
+ uint32_t block_size{};
ssize_t read_bytes =
TEMP_FAILURE_RETRY(read(ifd.get(), &block_size, sizeof(block_size)));
if (read_bytes == 0) break;
diff --git a/gki/ramdisk_utils.cpp b/gki/ramdisk_utils.cpp
index a6ec24a..a133edf 100644
--- a/gki/ramdisk_utils.cpp
+++ b/gki/ramdisk_utils.cpp
@@ -18,6 +18,7 @@
#include <android-base/file.h>
#include <android-base/result.h>
#include <bootimg.h>
+#include <iostream>
#include "cpio.h"
#include "lz4_legacy.h"
@@ -37,7 +38,7 @@
android::base::unique_fd bootimg(
TEMP_FAILURE_RETRY(open(boot_path.data(), O_RDONLY)));
if (!bootimg.ok()) return ErrnoError() << "open(" << boot_path << ")";
- boot_img_hdr_v3 hdr;
+ boot_img_hdr_v3 hdr{};
if (!ReadFullyAtOffset(bootimg.get(), &hdr, sizeof(hdr), 0))
return ErrnoError() << "read header";
if (0 != memcmp(hdr.magic, BOOT_MAGIC, BOOT_MAGIC_SIZE))
@@ -45,6 +46,10 @@
if (hdr.header_version < 3)
return Error() << "Unsupported header version V" << hdr.header_version;
+ if (hdr.ramdisk_size <= 0) {
+ return Error() << boot_path
+ << " contains a valid bootimg header but no ramdisk";
+ }
// See bootimg.h
auto kernel_size_bytes = (hdr.kernel_size + 4096 - 1) / 4096 * 4096;
@@ -58,6 +63,7 @@
auto ramdisk_content_file = std::make_unique<TemporaryFile>();
if (!WriteStringToFd(ramdisk_content, ramdisk_content_file->fd))
return ErrnoError() << "write ramdisk section to file";
+ fsync(ramdisk_content_file->fd);
return ramdisk_content_file;
}