Compare commits

...

10 commits

Author SHA1 Message Date
chiteroman
afee2eb6bf init: Spoof additional props
Change-Id: I3a22f2a923628c54462ed878f2c98a228d355f60
Signed-off-by: Alvin Francis <nivlafx@gmail.com>
2025-05-16 23:26:19 +00:00
Alexander Martinz
d306178c83 init: reboot to recovery on panic by default to allow reading pstore
Note: bootloaders can still change the reboot target using cmdline.

Change-Id: I982ddb0b5720c660026e9b8b2ec4d0c3196b6442
Signed-off-by: Alexander Martinz <amartinz@shiftphones.com>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
2025-05-16 23:26:19 +00:00
Pranav Vashi
cbc854979e init: Do not set safety net props for ENG builds
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
2025-05-16 23:26:19 +00:00
jhenrique09
37bf4cfa91 init: Spoof more props
Change-Id: Ic0ddbd6a0dd40c877248f7864082eddab2b32366
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
2025-05-16 23:26:19 +00:00
spezi77
141ca75530 init: Add more properties to spoof.
Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
2025-05-16 23:26:19 +00:00
Alex Naidis
782929f388 init: Weaken property override security for the init extension
Sometimes we need to override ro.* properties by using our vendor init
extension.

Previously there was a security check which was blocking that.
To resolve the issue, we need to weaken the security check during the
execution of our vendor init extension.

This is safe because the vendor init extension gets executed as part of init
construction and it is considered a trusted system component.

Change-Id: I6198b453745cb92c65d3e3d49e3262354cddd2a2
Signed-off-by: Alex Naidis <alex.naidis@linux.com>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
2025-05-16 23:26:19 +00:00
Danny Lin
7f7b6aab72 init: Set properties to make SafetyNet pass
This is a squash of the following commits.

  Author: Danny Lin <danny@kdrag0n.dev>
  Date:   Wed Oct 7 00:24:54 2020 -0700

      init: Set properties to make SafetyNet pass

      Google's SafetyNet integrity checks will check the values of these
      properties when performing basic attestation. Setting fake values helps
      us pass basic SafetyNet with no Magisk Hide or kernel patches necessary.

      Note that these properties need to be set very early, before parsing the
      kernel command-line, as they are read-only properties that the bootloader
      sets using androidboot kernel arguments. The bootloader's real values
      cause SafetyNet to fail with an unlocked bootloader and/or custom
      software because the verified boot chain is broken in that case.

      Change-Id: I66d23fd91d82906b00d5eb020668f01ae83ec31f
      Signed-off-by: Omkar Chandorkar <gotenksIN@aospa.co>

  Author: Jarl-Penguin <jarlpenguin@outlook.com>
  Date:   Wed Jun 16 11:28:46 2021 +0000

      init: Don't spoof SafetyNet properties in recovery mode

      Change-Id: Ib6d3808c3b8f3e0cffab685a24d3cdd436b0fe9b

Change-Id: I0a219245b8e8f59ab1acc31068b4f8f98f708d81
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
2025-05-16 23:26:05 +00:00
Danny Lin
1aea24d503 init.rc: Disable native stats collection service
When opening and closing activities in Settings, a measurably
significant amount of CPU time is spent processing and logging stats
events in statsd:

0.02%     /apex/com.android.os.statsd/lib64/libstatspull.so                                                                                         @plt
0.01%     /apex/com.android.os.statsd/bin/statsd                                                                                                    @plt
0.01%     /apex/com.android.os.statsd/bin/statsd                                                                                                    SocketListener::runListener()
0.01%     /apex/com.android.os.statsd/bin/statsd                                                                                                    android::os::statsd::LogEvent::parseBuffer(unsigned char*, unsigned long)
0.01%     /apex/com.android.os.statsd/bin/statsd                                                                                                    android::os::statsd::LogEvent::parseAnnotations(unsigned char, int)

Over longer device uptimes with real-world usage, statsd uses a
substantial amount of total CPU time. We have no use for the stats
recorded by statsd, so disable the service entirely to save CPU in
potential hotpaths.

This is the system/core part of the change; changes to frameworks/base
are also required.

Test: simpleperf record -a; verify that statsd no longer appears in
      sample hits
Change-Id: Idf6fdb0eff987169bd5f370dd72315e831a669e6
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
Signed-off-by: Dmitrii <bankersenator@gmail.com>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
Signed-off-by: rmp22 <195054967+rmp22@users.noreply.github.com>
2025-05-16 23:25:48 +00:00
Juhyung Park
2e24debf3c init.rc: tune dirty data writebacks
To relieve memory pressure on Android, we should start writing
dirty data sooner than later.

The Linux kernel's default is way too conservative on Android.
Android doesn't have a good reason to delay writing dirty data
anyways.

This change will make the kernel start writing dirty data when
it reaches 50M and switch to synchronous on 200M, which is far
more sensible values than 1.2G and 2.4G respectively on a device
with 12G of RAM.

Change-Id: I22f9ec9010dd028710a1a5c2e3d26d8444a4c914
Signed-off-by: Juhyung Park <qkrwngud825@gmail.com>
2025-05-16 23:25:48 +00:00
hydrangea07
367e295c4b init.rc: Tune F2FS and dirty writeout policy for modern devices
In a previous commit bb0838b511, the gc_urgent_sleep_time for F2FS was aggressively set to 50ms to optimize GC.
This change, however, led to performance regressions on most devices, particularly of those running in 4.19+ kernels.
From our tests, the heightened CPU and I/O activity from this aggressive garbage collection setting is the likely cause.
To address this, we're revising the gc_urgent_sleep_time parameter to strike a balance between aggressive GC and device performance, taking
bb0838b511 goal into consideration.
Furthermore, the dirty writeout policy has been aligned with the latest configurations used in Pixel devices,
and cp_interval has been adjusted to surpass dirty_expire_centisecs for improved power efficiency during idle times.

Test: booted partner device, monitor performance
Change-Id: Ie4d0c870d734e915aaebcc53e64acdabac47b6dc
Signed-off-by: minaripenguin <minaripenguin@users.noreply.github.com>
2025-05-16 23:25:48 +00:00
4 changed files with 64 additions and 8 deletions

View file

@ -123,6 +123,7 @@ libinit_cc_defaults {
"-DREBOOT_BOOTLOADER_ON_PANIC=0",
"-DSHUTDOWN_ZERO_TIMEOUT=0",
"-DWORLD_WRITABLE_KMSG=0",
"-DSPOOF_SAFETYNET=1",
"-Wall",
"-Werror",
"-Wextra",
@ -150,6 +151,8 @@ libinit_cc_defaults {
cppflags: [
"-USHUTDOWN_ZERO_TIMEOUT",
"-DSHUTDOWN_ZERO_TIMEOUT=1",
"-USPOOF_SAFETYNET",
"-DSPOOF_SAFETYNET=0",
],
},
uml: {
@ -421,6 +424,7 @@ init_first_stage_cc_defaults {
"-DSHUTDOWN_ZERO_TIMEOUT=0",
"-DLOG_UEVENTS=0",
"-DSEPOLICY_VERSION=30", // TODO(jiyong): externalize the version number
"-DSPOOF_SAFETYNET=1",
],
product_variables: {
@ -450,6 +454,8 @@ init_first_stage_cc_defaults {
cflags: [
"-USHUTDOWN_ZERO_TIMEOUT",
"-DSHUTDOWN_ZERO_TIMEOUT=1",
"-USPOOF_SAFETYNET",
"-DSPOOF_SAFETYNET=0",
],
},
},

View file

@ -132,6 +132,8 @@ struct PropertyAuditData {
const char* name;
};
static bool weaken_prop_override_security = false;
static int PropertyAuditCallback(void* data, security_class_t /*cls*/, char* buf, size_t len) {
auto* d = reinterpret_cast<PropertyAuditData*>(data);
@ -406,8 +408,8 @@ static std::optional<uint32_t> PropertySet(const std::string& name, const std::s
} else {
prop_info* pi = (prop_info*)__system_property_find(name.c_str());
if (pi != nullptr) {
// ro.* properties are actually "write-once".
if (StartsWith(name, "ro.")) {
// ro.* properties are actually "write-once", unless the system decides to
if (StartsWith(name, "ro.") && !weaken_prop_override_security) {
*error = "Read-only property was already set";
return {PROP_ERROR_READ_ONLY_PROPERTY};
}
@ -1242,6 +1244,9 @@ void PropertyLoadBootDefaults() {
}
}
// Weaken property override security during execution of the vendor init extension
weaken_prop_override_security = true;
// Update with vendor-specific property runtime overrides
vendor_load_properties();
@ -1252,6 +1257,9 @@ void PropertyLoadBootDefaults() {
property_initialize_ro_cpu_abilist();
property_initialize_ro_vendor_api_level();
// Restore the normal property override security after init extension is executed
weaken_prop_override_security = false;
update_sys_usb_config();
}
@ -1410,6 +1418,36 @@ static void ProcessBootconfig() {
});
}
static void SetSafetyNetProps() {
InitPropertySet("ro.boot.flash.locked", "1");
InitPropertySet("ro.boot.vbmeta.device_state", "locked");
InitPropertySet("ro.boot.verifiedbootstate", "green");
InitPropertySet("ro.boot.veritymode", "enforcing");
InitPropertySet("ro.boot.warranty_bit", "0");
InitPropertySet("ro.warranty_bit", "0");
InitPropertySet("ro.debuggable", "0");
InitPropertySet("ro.force.debuggable", "0");
InitPropertySet("ro.adb.secure", "1");
InitPropertySet("ro.secure", "1");
InitPropertySet("ro.bootimage.build.type", "user");
InitPropertySet("ro.build.type", "user");
InitPropertySet("ro.build.keys", "release-keys");
InitPropertySet("ro.build.tags", "release-keys");
InitPropertySet("ro.system.build.tags", "release-keys");
InitPropertySet("ro.product.build.type", "user");
InitPropertySet("ro.odm.build.type", "user");
InitPropertySet("ro.system.build.type", "user");
InitPropertySet("ro.system_ext.build.type", "user");
InitPropertySet("ro.vendor.build.type", "user");
InitPropertySet("ro.vendor_dlkm.build.type", "user");
InitPropertySet("ro.vendor.boot.warranty_bit", "0");
InitPropertySet("ro.vendor.warranty_bit", "0");
InitPropertySet("vendor.boot.vbmeta.device_state", "locked");
InitPropertySet("vendor.boot.verifiedbootstate", "green");
InitPropertySet("oplusboot.verifiedbootstate", "green");
InitPropertySet("sys.oem_unlock_allowed", "0");
}
void PropertyInit() {
selinux_callback cb;
cb.func_audit = PropertyAuditCallback;
@ -1424,6 +1462,16 @@ void PropertyInit() {
LOG(FATAL) << "Failed to load serialized property info file";
}
// Report a valid verified boot chain to make Google SafetyNet integrity
// checks pass. This needs to be done before parsing the kernel cmdline as
// these properties are read-only and will be set to invalid values with
// androidboot cmdline arguments.
if (SPOOF_SAFETYNET) {
if (!IsRecoveryMode()) {
SetSafetyNetProps();
}
}
// If arguments are passed both on the command line and in DT,
// properties set in DT always have priority over the command-line ones.
ProcessKernelDt();

View file

@ -37,7 +37,7 @@
namespace android {
namespace init {
static std::string init_fatal_reboot_target = "bootloader";
static std::string init_fatal_reboot_target = "recovery";
static bool init_fatal_panic = false;
// this needs to read the /proc/* files directly because it is called before

View file

@ -1143,14 +1143,12 @@ on zygote-start
wait_for_prop odsign.verification.done 1
# A/B update verifier that marks a successful boot.
exec_start update_verifier
start statsd
start zygote
start zygote_secondary
on boot && property:ro.config.low_ram=true
# Tweak background writeout
on boot && property:ro.config.low_ram=true
write /proc/sys/vm/dirty_expire_centisecs 200
write /proc/sys/vm/dirty_background_ratio 5
on boot && property:suspend.disable_sync_on_suspend=true
write /sys/power/sync_on_suspend 0
@ -1169,6 +1167,8 @@ on boot
# parameters to match how it is managing things.
write /proc/sys/vm/overcommit_memory 1
write /proc/sys/vm/min_free_order_shift 4
write /proc/sys/vm/dirty_background_bytes 52428800
write /proc/sys/vm/dirty_bytes 209715200
# System server manages zram writeback
chown root system /sys/block/zram0/idle
@ -1190,10 +1190,12 @@ on boot
# to avoid power consumption when system becomes mostly idle. Be careful
# to make it too large, since it may bring userdata loss, if they
# are not aware of using fsync()/sync() to prepare sudden power-cut.
write /dev/sys/fs/by-name/userdata/cp_interval 200
write /dev/sys/fs/by-name/userdata/gc_urgent_sleep_time 50
write /dev/sys/fs/by-name/userdata/cp_interval 6000
write /dev/sys/fs/by-name/userdata/gc_urgent_sleep_time 200
write /dev/sys/fs/by-name/userdata/iostat_period_ms 1000
write /dev/sys/fs/by-name/userdata/iostat_enable 0
write /proc/sys/vm/dirty_expire_centisecs 3000
write /proc/sys/vm/dirty_background_ratio 10
# set readahead multiplier for POSIX_FADV_SEQUENTIAL files
write /dev/sys/fs/by-name/userdata/seq_file_ra_mul 128