From 354417a7fb856f08a1305b9dc0b3e580d76f833a Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Fri, 5 Jan 2018 12:20:25 -0700 Subject: [PATCH 1/3] Allocate GID to use reserved disk space. Filesystems allow the setting of the "resgid" parameter to designate a GID that is allowed to use the "reserved" disk space (in addition to UID 0). We'll be granting this GID to critical system processes, so that the system is usable enough for the user to free up disk space used by abusive apps. Test: builds, boots Bug: 62024591 Change-Id: I2d166f3b730f0a3e7279fb40f12db7413c1dadad --- libcutils/include/private/android_filesystem_config.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libcutils/include/private/android_filesystem_config.h b/libcutils/include/private/android_filesystem_config.h index 2ecf5bce6..2f2e26238 100644 --- a/libcutils/include/private/android_filesystem_config.h +++ b/libcutils/include/private/android_filesystem_config.h @@ -122,6 +122,7 @@ #define AID_AUTOMOTIVE_EVS 1062 /* Automotive rear and surround view system */ #define AID_LOWPAN 1063 /* LoWPAN subsystem */ #define AID_HSM 1064 /* hardware security module subsystem */ +#define AID_RESERVED_DISK 1065 /* GID that has access to reserved disk space */ /* Changes to this file must be made in AOSP, *not* in internal branches. */ #define AID_SHELL 2000 /* adb and debug shell user */ From 47dc236d2f3227b4d952ad490939f7c9b0f8c90b Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Sun, 7 Jan 2018 19:17:39 -0700 Subject: [PATCH 2/3] Set reserved GID when setting reserved blocks. If we're setting up the number of reserved blocks, we also want to set our new AID_DISK_RESERVED as the GID that's allowed to use those blocks. Test: builds, boots Bug: 62024591 Change-Id: Iaabfa7d63ad9ff0b9732e2b9996937607d622fe2 --- fs_mgr/fs_mgr.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs_mgr/fs_mgr.cpp b/fs_mgr/fs_mgr.cpp index 4b94f9c97..a2b80ad9f 100644 --- a/fs_mgr/fs_mgr.cpp +++ b/fs_mgr/fs_mgr.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -353,7 +354,7 @@ static void tune_reserved_size(const char* blk_device, const struct fstab_rec* r reserved_blocks = max_reserved_blocks; } - if (ext4_r_blocks_count(sb) == reserved_blocks) { + if ((ext4_r_blocks_count(sb) == reserved_blocks) && (sb->s_def_resgid == AID_RESERVED_DISK)) { return; } @@ -363,11 +364,12 @@ static void tune_reserved_size(const char* blk_device, const struct fstab_rec* r return; } - char buf[32]; - const char* argv[] = {TUNE2FS_BIN, "-r", buf, blk_device}; - - snprintf(buf, sizeof(buf), "%" PRIu64, reserved_blocks); LINFO << "Setting reserved block count on " << blk_device << " to " << reserved_blocks; + + auto reserved_blocks_str = std::to_string(reserved_blocks); + auto reserved_gid_str = std::to_string(AID_RESERVED_DISK); + const char* argv[] = { + TUNE2FS_BIN, "-r", reserved_blocks_str.c_str(), "-g", reserved_gid_str.c_str(), blk_device}; if (!run_tune2fs(argv, ARRAY_SIZE(argv))) { LERROR << "Failed to run " TUNE2FS_BIN " to set the number of reserved blocks on " << blk_device; From 9410d572fb6202727580fa62815b694998b6421f Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Fri, 5 Jan 2018 17:16:49 -0700 Subject: [PATCH 3/3] Add reserved disk GID to critical component. We recently created a new GID that can be granted to critical system processes, so that the system is usable enough for the user to free up disk space used by abusive apps. Test: builds, boots Bug: 62024591 Change-Id: Ia5af7535cc05a214f8720ac08c594c6db888597a --- rootdir/init.zygote32.rc | 2 +- rootdir/init.zygote32_64.rc | 4 ++-- rootdir/init.zygote64.rc | 2 +- rootdir/init.zygote64_32.rc | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rootdir/init.zygote32.rc b/rootdir/init.zygote32.rc index d836c4ef7..ac87979ec 100644 --- a/rootdir/init.zygote32.rc +++ b/rootdir/init.zygote32.rc @@ -2,7 +2,7 @@ service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-sys class main priority -20 user root - group root readproc + group root readproc reserved_disk socket zygote stream 660 root system onrestart write /sys/android_power/request_state wake onrestart write /sys/power/state on diff --git a/rootdir/init.zygote32_64.rc b/rootdir/init.zygote32_64.rc index 80bb6730d..a535846de 100644 --- a/rootdir/init.zygote32_64.rc +++ b/rootdir/init.zygote32_64.rc @@ -2,7 +2,7 @@ service zygote /system/bin/app_process32 -Xzygote /system/bin --zygote --start-s class main priority -20 user root - group root readproc + group root readproc reserved_disk socket zygote stream 660 root system onrestart write /sys/android_power/request_state wake onrestart write /sys/power/state on @@ -17,7 +17,7 @@ service zygote_secondary /system/bin/app_process64 -Xzygote /system/bin --zygote class main priority -20 user root - group root readproc + group root readproc reserved_disk socket zygote_secondary stream 660 root system onrestart restart zygote writepid /dev/cpuset/foreground/tasks diff --git a/rootdir/init.zygote64.rc b/rootdir/init.zygote64.rc index 05ec16fc9..6fc810bfa 100644 --- a/rootdir/init.zygote64.rc +++ b/rootdir/init.zygote64.rc @@ -2,7 +2,7 @@ service zygote /system/bin/app_process64 -Xzygote /system/bin --zygote --start-s class main priority -20 user root - group root readproc + group root readproc reserved_disk socket zygote stream 660 root system onrestart write /sys/android_power/request_state wake onrestart write /sys/power/state on diff --git a/rootdir/init.zygote64_32.rc b/rootdir/init.zygote64_32.rc index 09db7b03d..7ddd52ee5 100644 --- a/rootdir/init.zygote64_32.rc +++ b/rootdir/init.zygote64_32.rc @@ -2,7 +2,7 @@ service zygote /system/bin/app_process64 -Xzygote /system/bin --zygote --start-s class main priority -20 user root - group root readproc + group root readproc reserved_disk socket zygote stream 660 root system onrestart write /sys/android_power/request_state wake onrestart write /sys/power/state on @@ -17,7 +17,7 @@ service zygote_secondary /system/bin/app_process32 -Xzygote /system/bin --zygote class main priority -20 user root - group root readproc + group root readproc reserved_disk socket zygote_secondary stream 660 root system onrestart restart zygote writepid /dev/cpuset/foreground/tasks