From 6151bff500d7a2fc9464a3008fa05685e88c8e57 Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Fri, 24 Jan 2025 18:02:28 -0800 Subject: [PATCH 1/3] Fix UFS err_stats Bug: 392193452 Change-Id: I159f5bcfb8de1b33f46ba860b4436d1dfc6907f2 Signed-off-by: Jaegeuk Kim --- storage/dump_storage.cpp | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/storage/dump_storage.cpp b/storage/dump_storage.cpp index 272b1ee..d40d963 100644 --- a/storage/dump_storage.cpp +++ b/storage/dump_storage.cpp @@ -27,7 +27,6 @@ #define F2FS_FSCK_TIME_PROPERTY "ro.boottime.init.fsck.data" #define F2FS_MNT_TIME_PROPERTY "ro.boottime.init.mount.data" -#define BOOTDEVICE_PROPERTY "ro.boot.bootdevice" #define BUILD_TYPE_PROPERTY "ro.build.type" void read_buffer(int buf_id, int total_len, const char* path) @@ -90,24 +89,10 @@ int main() { if (statdir) { dirent *stat_entry; while ((stat_entry = readdir(statdir.get())) != nullptr) { - std::string ufs_err_stats_path(stat_entry->d_name); - if (!strcmp(ufs_err_stats_path.c_str(), ".") - || !strcmp(ufs_err_stats_path.c_str(), "..")) - continue; - std::string bootdevice = android::base::GetProperty( - BOOTDEVICE_PROPERTY, ""); - std::string err_stat_path = "/sys/devices/platform/"; - err_stat_path.append(bootdevice.c_str()); - err_stat_path.append("/err_stats/"); - err_stat_path.append(ufs_err_stats_path.c_str()); - std::ifstream err_stat_file(err_stat_path); - if (err_stat_file.is_open()) { - std::string err_stat_atom; - err_stat_file >> err_stat_atom; - printf("%s:%s\n", ufs_err_stats_path.c_str(), - err_stat_atom.c_str()); - err_stat_file.close(); - } + std::string stat_name(stat_entry->d_name); + if (stat_name == "." || stat_name == "..") continue; + dumpFileContent(stat_name.c_str(), + (ufs_err_stats_path + stat_name).c_str()); } } From 7bd70d06d76e6a032501581d08beb5567e75a731 Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Fri, 24 Jan 2025 17:47:41 -0800 Subject: [PATCH 2/3] Dump F2FS disk_map and UFS phy version [ 91.358748] type=1400 audit(1737771651.492:274): avc: denied { search } for comm="dump_storage" name="f2fs" dev="proc" ino=4026532053 scontext=u:r:dump_storage:s0 tcontext=u:object_r:proc_f2fs:s0 tclass=dir permissive=0 [ 49.564560] type=1400 audit(1737778106.496:153): avc: denied { read } for comm="dump_storage" name="f2fs" dev="proc" ino=4026532053 scontext=u:r:dump_storage:s0 tcontext=u:object_r:proc_f2fs:s0 tclass=dir permissive=0 [ 91.358930] type=1400 audit(1737771651.492:275): avc: denied { read } for comm="dump_storage" name="phy_version" dev="sysfs" ino=109125 scontext=u:r:dump_storage:s0 tcontext=u:object_r:sysfs:s0 tclass=file permissive=0 [ 91.359249] type=1400 audit(1737771651.492:276): avc: denied { read } for comm="dump_storage" name="phy_release_date" dev="sysfs" ino=109126 scontext=u:r:dump_storage:s0 tcontext=u:object_r:sysfs:s0 tclass=file permissive=0 Bug: 392193452 Flag: EXEMPT bugfix Change-Id: I8e174e378064a94681f74a88ee13b4461527076a Signed-off-by: Jaegeuk Kim --- storage/dump_storage.cpp | 20 ++++++++++++++++++++ storage/sepolicy/dump_storage.te | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/storage/dump_storage.cpp b/storage/dump_storage.cpp index d40d963..2367d4c 100644 --- a/storage/dump_storage.cpp +++ b/storage/dump_storage.cpp @@ -67,11 +67,31 @@ int main() { int mnt_time = android::base::GetIntProperty(F2FS_MNT_TIME_PROPERTY, 0); printf("--- F2FS - checkpoint=disable time (ms) ---\n%d\n\n", mnt_time); + const std::string f2fs_proc_path("/proc/fs/f2fs/"); + std::unique_ptr procdir( + opendir(f2fs_proc_path.c_str()), closedir); + if (procdir) { + dirent *proc_entry; + while ((proc_entry = readdir(procdir.get())) != nullptr) { + std::string proc_name(proc_entry->d_name); + if (proc_name == "." || proc_name == ".." || + strncmp(proc_name.c_str(), "dm-", 3)) + continue; + dumpFileContent(("F2FS - " + proc_name).c_str(), + (f2fs_proc_path + proc_name + "/disk_map").c_str()); + } + } + //UFS dumpFileContent("UFS model", "/sys/block/sda/device/model"); dumpFileContent("UFS rev", "/sys/block/sda/device/rev"); dumpFileContent("UFS size", "/sys/block/sda/size"); + dumpFileContent("UFS phy version", + "/dev/sys/block/bootdevice/pixel/phy_version"); + dumpFileContent("UFS phy release_date", + "/dev/sys/block/bootdevice/pixel/phy_release_date"); + dumpFileContent("UFS Slow IO Read", "/dev/sys/block/bootdevice/slowio_read_cnt"); dumpFileContent("UFS Slow IO Write", diff --git a/storage/sepolicy/dump_storage.te b/storage/sepolicy/dump_storage.te index 7a5f563..67c4b9a 100644 --- a/storage/sepolicy/dump_storage.te +++ b/storage/sepolicy/dump_storage.te @@ -4,6 +4,10 @@ pixel_bugreport(dump_storage) # adb bugreport allow dump_storage sysfs_scsi_devices_0000:dir r_dir_perms; allow dump_storage sysfs_scsi_devices_0000:file r_file_perms; +allow dump_storage sysfs:file r_file_perms; + +allow dump_storage proc_f2fs:dir r_dir_perms; +allow dump_storage proc_f2fs:file r_file_perms; # adb bugreport userdebug_or_eng(` From b1072785ba5a99035b9c21f46f8e3eced2ac82b6 Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Sat, 25 Jan 2025 13:50:16 -0800 Subject: [PATCH 3/3] Allow write for restorecon [ 8345.125689] type=1400 audit(1737841652.160:245): avc: denied { write } for comm="kworker/u16:2" path="/dev/block/sda34" dev="tmpfs" ino=1060 scontext=u:r:kernel:s0 tcontext=u:object_r:userdata_exp_block_device:s0 tclass=blk_file permissive=0 Bug: 361093433 Flag: EXEMPT bugfix Change-Id: Ia03cddd6eebe9b8875bdbd1a8eb3a67f51269032 Signed-off-by: Jaegeuk Kim --- storage/sepolicy/kernel.te | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/sepolicy/kernel.te b/storage/sepolicy/kernel.te index 55882ed..b9712b1 100644 --- a/storage/sepolicy/kernel.te +++ b/storage/sepolicy/kernel.te @@ -1,3 +1,3 @@ # for intelligence service -allow kernel userdata_exp_block_device:blk_file read; +allow kernel userdata_exp_block_device:blk_file { read write };